diff options
| author | Adam Soltys <[email protected]> | 2023-03-22 16:57:37 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-03-22 16:57:37 -0700 |
| commit | 711b75309ce8c4efce457a1938b50ac875550b2d (patch) | |
| tree | d23e6decc7ed87b774a6ee5145be2b33c06a73a3 | |
| parent | f4366d86b20a4a5a9bb3c85d9559d0b61beac6c9 (diff) | |
| download | coinos-server-711b75309ce8c4efce457a1938b50ac875550b2d.tar.gz coinos-server-711b75309ce8c4efce457a1938b50ac875550b2d.zip | |
prettier
| -rw-r--r-- | routes/payments.js | 43 | ||||
| -rw-r--r-- | routes/users.js | 26 |
2 files changed, 33 insertions, 36 deletions
diff --git a/routes/payments.js b/routes/payments.js index 3c318f2d..a1204700 100644 --- a/routes/payments.js +++ b/routes/payments.js @@ -15,12 +15,12 @@ import ln from "$lib/ln"; let seen = []; let catchUp = async () => { let txns = await bc.listTransactions("*", 50); - txns = txns.filter(tx => tx.category === "receive" && tx.confirmations > 0); + txns = txns.filter((tx) => tx.category === "receive" && tx.confirmations > 0); for (let { txid } of txns) { try { if (seen.includes(txid)) continue; await got.post(`http://localhost:${process.env.PORT || 3119}/bitcoin`, { - json: { txid, wallet: config.bitcoin.wallet } + json: { txid, wallet: config.bitcoin.wallet }, }); seen.push(txid); @@ -54,7 +54,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) { @@ -124,7 +124,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}`); @@ -132,7 +132,7 @@ export default { }) ) ) - .filter(p => p) + .filter((p) => p) .sort((a, b) => b.created - a.created); let total = payments.length; @@ -159,7 +159,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) }); @@ -169,13 +169,13 @@ export default { let amount = await g(`pot:${name}`); if (!amount) return bail(res, "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 }); }, @@ -183,16 +183,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); @@ -252,7 +249,7 @@ export default { let tx = await bc.fundRawTransaction(raw, { feeRate, subtractFeeFromOutputs, - replaceable + replaceable, }); let fee = sats(tx.fee); @@ -295,7 +292,7 @@ export default { for (let { scriptPubKey: { address }, - value + value, } of tx.vout) { total += sats(value); if ( @@ -330,13 +327,13 @@ export default { "card[number]": number, "card[exp_month]": month, "card[exp_year]": year, - "card[cvc]": cvc + "card[cvc]": cvc, }; let { id: source } = await got .post(`${stripe}/tokens`, { form, - username + username, }) .json(); @@ -345,13 +342,13 @@ export default { amount, currency, source, - description: "starter coupon" + description: "starter coupon", }; let r = await got .post(`${stripe}/charges`, { form, - username + username, }) .json(); @@ -361,7 +358,7 @@ export default { let memo = "stripe"; await s(`invoice:${hash}`, { uid: user.id, - received: 0 + received: 0, }); amount = sats(amount / store.rates[currency]); let uid = await g("user:coinos"); @@ -381,7 +378,7 @@ export default { "estimatesmartfee", "echo", "getblockchaininfo", - "getnetworkinfo" + "getnetworkinfo", ]; if (!whitelist.includes(method)) fail("unsupported method"); @@ -425,5 +422,5 @@ export default { } catch (e) { bail(res, e.message); } - } + }, }; diff --git a/routes/users.js b/routes/users.js index 3e5741a2..3c083d17 100644 --- a/routes/users.js +++ b/routes/users.js @@ -83,7 +83,7 @@ export default { username: key, display: key.substr(0, 6), pubkey: key, - anon: true + anon: true, }; } @@ -100,7 +100,7 @@ export default { "pubkey", "display", "prompt", - "id" + "id", ]; if (user.pubkey) @@ -124,7 +124,7 @@ export default { pubkey, password, username, - salt + salt, }; user = await register(user, ip, false); @@ -201,7 +201,7 @@ export default { "salt", "seed", "tokens", - "twofa" + "twofa", ]; for (let a of attributes) { @@ -245,7 +245,7 @@ export default { if (!token) fail(); user = await got(`${classic}/admin/migrate/${username}?zero=true`, { - headers: { authorization: `Bearer ${config.admin}` } + headers: { authorization: `Bearer ${config.admin}` }, }).json(); let { balance } = user; @@ -257,7 +257,7 @@ export default { ...pick(user, fields), id: uid, about: user.address, - migrated: true + migrated: true, }; await s(`user:${username}`, uid); @@ -265,7 +265,7 @@ export default { await s(`balance:${uid}`, balance); let payments = await got(`${classic}/payments`, { - headers: { authorization: `Bearer ${token}` } + headers: { authorization: `Bearer ${token}` }, }).json(); for (let p of payments) { @@ -275,7 +275,7 @@ export default { "confirmed", "rate", "currency", - "preimage" + "preimage", ]); n.id = v4(); n.created = parseISO(p.createdAt).getTime(); @@ -293,7 +293,7 @@ export default { u = await got( `${classic}/admin/migrate/${p.with.username.toLowerCase()}`, { - headers: { authorization: `Bearer ${config.admin}` } + headers: { authorization: `Bearer ${config.admin}` }, } ).json(); @@ -365,7 +365,7 @@ export default { if (!subscriptions) subscriptions = []; if ( !subscriptions.find( - s => JSON.stringify(s) === JSON.stringify(subscription) + (s) => JSON.stringify(s) === JSON.stringify(subscription) ) ) subscriptions.push(subscription); @@ -402,8 +402,8 @@ export default { let contacts = (await g(`${id}:contacts`)) || []; for (let { ref } of ( - await Promise.all(payments.map(async id => await g(`payment:${id}`))) - ).filter(p => p.type === types.internal && p.ref)) { + await Promise.all(payments.map(async (id) => await g(`payment:${id}`))) + ).filter((p) => p.type === types.internal && p.ref)) { !~contacts.findIndex(({ id }) => id === ref) && contacts.push(await g(`user:${ref}`)); } @@ -461,5 +461,5 @@ export default { } catch (e) { bail(res, e.message); } - } + }, }; |
