aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-02-10 23:36:34 -0800
committerAdam Soltys <[email protected]>2023-02-11 00:37:46 -0800
commit60cf57d56f617998e093e81b229e18c9a221e312 (patch)
treea7d0dbc1096b00cdc940ce1138e527fdbf92c2c2
parenta059697ad1dab4308f9bc9c2957dc574f6e5518a (diff)
downloadcoinos-server-60cf57d56f617998e093e81b229e18c9a221e312.tar.gz
coinos-server-60cf57d56f617998e093e81b229e18c9a221e312.zip
prettier
-rw-r--r--lib/auth.js12
-rw-r--r--lib/db.js6
-rw-r--r--lib/payments.js6
-rw-r--r--routes/payments.js8
-rw-r--r--routes/users.js15
5 files changed, 26 insertions, 21 deletions
diff --git a/lib/auth.js b/lib/auth.js
index f3cfd1e9..2e26f138 100644
--- a/lib/auth.js
+++ b/lib/auth.js
@@ -7,17 +7,17 @@ export const optional = {
preValidation: fastifyPassport.authenticate(
"jwt",
{ session: false },
- function (req, res, err, user, info) {
+ function(req, res, err, user, info) {
req.user = user;
}
- ),
+ )
};
export const auth = {
preValidation: fastifyPassport.authenticate("jwt", {
authInfo: false,
- session: false,
- }),
+ session: false
+ })
};
export const requirePin = async ({ body, user }) => {
@@ -29,9 +29,9 @@ export const jwtStrategy = new jwt.Strategy(
{
jwtFromRequest: jwt.ExtractJwt.fromExtractors([
jwt.ExtractJwt.fromAuthHeaderAsBearerToken(),
- (req) => (req.cookies ? req.cookies.token : null),
+ req => (req.cookies ? req.cookies.token : null)
]),
- secretOrKey: config.jwt,
+ secretOrKey: config.jwt
},
async (payload, next) => {
let user = await g(`user:${payload.id}`);
diff --git a/lib/db.js b/lib/db.js
index 94538abb..edf48910 100644
--- a/lib/db.js
+++ b/lib/db.js
@@ -10,10 +10,10 @@ export let g = async k => {
let v = await db.get(k);
try {
return JSON.parse(v);
- } catch(e) {
+ } catch (e) {
return v;
- }
-}
+ }
+};
export let s = (k, v) => db.set(k, JSON.stringify(v));
let retries = {};
diff --git a/lib/payments.js b/lib/payments.js
index 2c0eb0c0..e946e41e 100644
--- a/lib/payments.js
+++ b/lib/payments.js
@@ -13,7 +13,7 @@ export const types = {
bitcoin: "bitcoin",
lightning: "lightning",
pot: "pot",
- classic: "classic",
+ classic: "classic"
};
export let debit = async (
@@ -66,7 +66,7 @@ export let debit = async (
currency,
type,
ref,
- created: Date.now(),
+ created: Date.now()
};
await s(`payment:${id}`, p);
@@ -98,7 +98,7 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => {
ref,
type,
confirmed: true,
- created: Date.now(),
+ created: Date.now()
};
let { tip } = invoice;
diff --git a/routes/payments.js b/routes/payments.js
index 0ee2bce0..eee0990b 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -43,9 +43,7 @@ export default {
if (invoice) {
if (invoice.uid === user.id) fail("Cannot send to self");
hash = payment_hash;
- }
-
- else {
+ } else {
p = await debit(
hash,
amount + maxfee,
@@ -109,7 +107,9 @@ export default {
},
async get({ params: { hash } }, res) {
- res.send(await g(`payment:${hash}`));
+ let p = await g(`payment:${hash}`);
+ if (p.type === types.internal) p.with = await g(`user:${p.ref}`);
+ res.send(p);
},
async parse({ body: { payreq } }, res) {
diff --git a/routes/users.js b/routes/users.js
index 2cdd3247..c6fb848d 100644
--- a/routes/users.js
+++ b/routes/users.js
@@ -244,9 +244,12 @@ export default {
let u = id && (await g(`user:${id}`));
if (!u) {
- u = await got(`${classic}/admin/migrate/${p.with.username.toLowerCase()}`, {
- headers: { authorization: `Bearer ${config.admin}` }
- }).json();
+ u = await got(
+ `${classic}/admin/migrate/${p.with.username.toLowerCase()}`,
+ {
+ headers: { authorization: `Bearer ${config.admin}` }
+ }
+ ).json();
u = { id: u.uuid, about: u.address, ...pick(u, fields) };
delete u.address;
@@ -369,7 +372,9 @@ export default {
if (!(authorization && authorization.includes(config.admin)))
return res.code(401).send("unauthorized");
- let { id, pubkey } = await g(`user:${await g(`user:${username.toLowerCase()}`)}`);
+ let { id, pubkey } = await g(
+ `user:${await g(`user:${username.toLowerCase()}`)}`
+ );
let invoices = await db.lRange(`${id}:invoices`, 0, -1);
let payments = await db.lRange(`${id}:payments`, 0, -1);
@@ -385,7 +390,7 @@ export default {
async lower(req, res) {
for await (let k of db.scanIterator({ MATCH: "balance:*" })) {
let b = await g(k);
- if (b < 0) console.log(k, b)
+ if (b < 0) console.log(k, b);
}
res.send("ok");