diff options
| -rw-r--r-- | lib/auth.js | 3 | ||||
| -rw-r--r-- | lib/invoices.js | 4 | ||||
| -rw-r--r-- | lib/payments.js | 15 | ||||
| -rw-r--r-- | routes/nostr.js | 72 | ||||
| -rw-r--r-- | routes/users.js | 5 |
5 files changed, 50 insertions, 49 deletions
diff --git a/lib/auth.js b/lib/auth.js index 1eca2fa5..944cc3b2 100644 --- a/lib/auth.js +++ b/lib/auth.js @@ -22,8 +22,7 @@ export const auth = { }; export const requirePin = async ({ body, user }) => { - if (!user || (user.pin && user.pin !== body.pin)) - fail("Invalid pin"); + if (!user || (user.pin && user.pin !== body.pin)) fail("Invalid pin"); }; export const jwtStrategy = new jwt.Strategy( diff --git a/lib/invoices.js b/lib/invoices.js index 8023bdbb..8ac8a868 100644 --- a/lib/invoices.js +++ b/lib/invoices.js @@ -47,7 +47,7 @@ export let generate = async ({ invoice, user, sender, memo }) => { description: memo || "", expiry: expiry || 60 * 60 * 24 * 30, deschashonly: true, - cltv: 19 + cltv: 19, }); hash = r.bolt11; @@ -84,8 +84,6 @@ export let generate = async ({ invoice, user, sender, memo }) => { webhook, }; - if (!user.username === 'lightningins') l(type, "invoice", user.username, amount); - if (type === "liquid") { let { unconfidential } = await lq.getAddressInfo(hash); await s(`invoice:${unconfidential}`, id); diff --git a/lib/payments.js b/lib/payments.js index 8da04b38..550e3791 100644 --- a/lib/payments.js +++ b/lib/payments.js @@ -72,7 +72,7 @@ export let debit = async ({ ? Math.round(amount * config.fee) : 0; - let r = await db.debit( + let r = await db.debit( `balance:${uid}`, `credit:${type}:${uid}`, amount || 0, @@ -89,7 +89,7 @@ export let debit = async ({ amount: -amount, fee, hash, - ourfee: r.ourfee, + ourfee: r.ourfee, memo, iid, uid, @@ -188,9 +188,6 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => { .incrBy(`${balance}:${uid}`, amount) .exec(); - if (!username.startsWith("lightning")) - l(username, "received", type, amount, tip); - emit(uid, "payment", p); notify(user, `Received ${amount} sats`); callWebhook(invoice, p); @@ -383,7 +380,10 @@ export let build = async ({ amount, address, feeRate }, user) => { let balance = await g(`balance:${user.id}`); if (amount + fee + ourfee > balance) { - if (amount <= fee + ourfee + dust) fail(`insufficient funds ⚡️${balance} of ⚡️${amount + fee + ourfee + dust}`); + if (amount <= fee + ourfee + dust) + fail( + `insufficient funds ⚡️${balance} of ⚡️${amount + fee + ourfee + dust}`, + ); outs = [{ [address]: btc(amount - ourfee) }]; raw = await node.createRawTransaction([], outs, 0, replaceable); @@ -403,7 +403,7 @@ export let build = async ({ amount, address, feeRate }, user) => { let seen; export let catchUp = async () => { try { - if (!seen) seen = await db.sMembers("missing"); + if (!seen) seen = await db.sMembers("missing"); let txns = []; for (let [type, n] of Object.entries({ bitcoin: bc, liquid: lq })) { txns.push( @@ -432,4 +432,3 @@ export let catchUp = async () => { setTimeout(catchUp, 2000); }; - diff --git a/routes/nostr.js b/routes/nostr.js index 60b287e8..95186078 100644 --- a/routes/nostr.js +++ b/routes/nostr.js @@ -95,49 +95,51 @@ export default { async follows({ params: { pubkey }, query: { tagsonly } }, res) { try { - let sub = `${pubkey}:follows`, - params = { - limit: 1, - kinds: [3], - authors: [pubkey], - }, - opts = { timeout: 60000, eager: 60000 }; + let sub = `${pubkey}:follows`, + params = { + limit: 1, + kinds: [3], + authors: [pubkey], + }, + opts = { timeout: 60000, eager: 60000 }; - q(sub, params, opts).catch(nada); + q(sub, params, opts).catch(nada); - let tags = (await g(`${pubkey}:follows`)) || []; - if (tagsonly) return res.send(tags); + let tags = (await g(`${pubkey}:follows`)) || []; + if (tagsonly) return res.send(tags); - let follows = []; - for (let f of tags) { - let [_, pubkey] = f; + let follows = []; + for (let f of tags) { + let [_, pubkey] = f; - q(`${pubkey}:profile:f1`, { - limit: 1, - kinds: [0], - authors: [pubkey], - }).catch(nada); + q(`${pubkey}:profile:f1`, { + limit: 1, + kinds: [0], + authors: [pubkey], + }).catch(nada); - let uid = await g(`user:${pubkey}`); - let user = await g(`user:${uid}`); + let uid = await g(`user:${pubkey}`); + let user = await g(`user:${uid}`); - if (!user) - user = { - username: pubkey.substr(0, 6), - pubkey, - anon: true, - }; + if (!user) + user = { + username: pubkey.substr(0, 6), + pubkey, + anon: true, + }; - follows.push(user); - } + follows.push(user); + } - follows = uniq(follows, (e) => e.pubkey); - follows.sort((a, b) => a.username && a.username.localeCompare(b.username)); + follows = uniq(follows, (e) => e.pubkey); + follows.sort( + (a, b) => a.username && a.username.localeCompare(b.username), + ); - res.send(follows); - } catch(e) { + res.send(follows); + } catch (e) { bail(res, e.message); - } + } }, async followers({ params: { pubkey } }, res) { @@ -179,7 +181,9 @@ export default { } followers = uniq(followers, (e) => e.pubkey); - followers.sort((a, b) => a.username && a.username.localeCompare(b.username)); + followers.sort( + (a, b) => a.username && a.username.localeCompare(b.username), + ); res.send(followers); } catch (e) { diff --git a/routes/users.js b/routes/users.js index 69319ba2..230d46a1 100644 --- a/routes/users.js +++ b/routes/users.js @@ -71,8 +71,9 @@ export default { let p = await g(`payment:${pid}`); if (!p) continue; total += p.amount; - if (p.amount < 0) total -= (p.fee || 0) + (p.ourfee || 0) + (p.tip || 0); - else total += (p.tip || 0) + if (p.amount < 0) + total -= (p.fee || 0) + (p.ourfee || 0) + (p.tip || 0); + else total += p.tip || 0; } user.expected = total; |
