diff options
| author | Adam Soltys <[email protected]> | 2023-02-13 21:04:02 +0000 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-02-13 21:04:10 +0000 |
| commit | 19480e0c07632b645fbee881dcbc3bf41c481eed (patch) | |
| tree | 213f865c1747659779f496f296371766e893aef5 | |
| parent | f7307a8e2d627006dd6e72fe9c1e2e4d5c6e312a (diff) | |
| download | coinos-server-19480e0c07632b645fbee881dcbc3bf41c481eed.tar.gz coinos-server-19480e0c07632b645fbee881dcbc3bf41c481eed.zip | |
check payload id
| -rw-r--r-- | lib/auth.js | 8 | ||||
| -rw-r--r-- | routes/payments.js | 34 |
2 files changed, 22 insertions, 20 deletions
diff --git a/lib/auth.js b/lib/auth.js index 2e26f138..0533de31 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -34,8 +34,12 @@ export const jwtStrategy = new jwt.Strategy( secretOrKey: config.jwt }, async (payload, next) => { - let user = await g(`user:${payload.id}`); - if (typeof user === "string") await g(`user:${user}`); + let user; + if (payload.id) { + user = await g(`user:${payload.id}`); + if (typeof user === "string") await g(`user:${user}`); + } + next(null, user); } ); diff --git a/routes/payments.js b/routes/payments.js index eee0990b..60e3bdd2 100644 --- a/routes/payments.js +++ b/routes/payments.js @@ -32,7 +32,7 @@ export default { await got .post(`${config.classic}/admin/credit`, { json: { username, amount, source }, - headers: { authorization: `Bearer ${config.admin}` } + headers: { authorization: `Bearer ${config.admin}` }, }) .json(); } else if (payreq) { @@ -88,7 +88,7 @@ export default { let payments = (await db.lRange(`${id}:payments`, 0, -1)) || []; payments = ( await Promise.all( - payments.map(async id => { + payments.map(async (id) => { let p = await g(`payment:${id}`); if (p.created < start || p.created > end) return; if (p.type === types.internal) p.with = await g(`user:${p.ref}`); @@ -96,7 +96,7 @@ export default { }) ) ) - .filter(p => p) + .filter((p) => p) .sort((a, b) => b.created - a.created); let total = payments.length; @@ -123,7 +123,7 @@ export default { let twoWeeksAgo = new Date(new Date().setDate(new Date().getDate() - 14)); let decoded = await ln.decodepay(payreq); let { msatoshi, payee } = decoded; - let node = nodes.find(n => n.nodeid === payee); + let node = nodes.find((n) => n.nodeid === payee); let alias = node ? node.alias : payee.substr(0, 12); res.send({ alias, amount: Math.round(msatoshi / 1000) }); @@ -133,13 +133,13 @@ export default { let amount = await g(`pot:${name}`); if (!amount) fail("pot not found"); let payments = (await db.lRange(`pot:${name}:payments`, 0, -1)) || []; - payments = await Promise.all(payments.map(hash => g(`payment:${hash}`))); + payments = await Promise.all(payments.map((hash) => g(`payment:${hash}`))); await Promise.all( - payments.map(async p => (p.user = await g(`user:${p.uid}`))) + payments.map(async (p) => (p.user = await g(`user:${p.uid}`))) ); - payments = payments.filter(p => p); + payments = payments.filter((p) => p); res.send({ amount, payments }); }, @@ -147,16 +147,13 @@ export default { amount = parseInt(amount); await t(`pot:${name}`, async (balance, db) => { if (balance < amount) fail("Insufficient funds"); - await db - .multi() - .decrBy(`pot:${name}`, amount) - .exec(); + await db.multi().decrBy(`pot:${name}`, amount).exec(); }); let hash = v4(); await s(`invoice:${hash}`, { uid: user.id, - received: 0 + received: 0, }); let payment = await credit(hash, amount, "", name, types.pot); @@ -169,9 +166,8 @@ export default { if (wallet === config.bitcoin.wallet) { let { confirmations, details } = await bc.getTransaction(txid); for (let { address, amount, vout } of details) { - if (confirmations > 0) { - await confirm(address, txid, vout); - } else { + let p = await g(`payment:${txid}:${vout}`); + if (!p || confirmations < 1) { await credit( address, sats(amount), @@ -179,6 +175,8 @@ export default { `${txid}:${vout}`, types.bitcoin ); + } else { + await confirm(address, txid, vout); } } } @@ -196,7 +194,7 @@ export default { let tx = await bc.fundRawTransaction(raw, { feeRate, subtractFeeFromOutputs, - replaceable + replaceable, }); if (config.bitcoin.walletpass) @@ -235,7 +233,7 @@ export default { for (let { scriptPubKey: { address }, - value + value, } of tx.vout) { total += sats(value); if ( @@ -254,5 +252,5 @@ export default { await bc.sendRawTransaction(hex); res.send({ txid }); - } + }, }; |
