diff options
| author | Adam Soltys <[email protected]> | 2023-10-08 00:16:50 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-10-08 00:16:50 -0700 |
| commit | db38e8f3316a121ba64d7e1c4cfd93b4826d6f4e (patch) | |
| tree | 172eaaed2c04d0c0e6491a68f7b8631a6298bf4b /routes | |
| parent | f599e57af5564c23908632c42d4827e51d120204 (diff) | |
| download | coinos-server-db38e8f3316a121ba64d7e1c4cfd93b4826d6f4e.tar.gz coinos-server-db38e8f3316a121ba64d7e1c4cfd93b4826d6f4e.zip | |
use invoice id instead of hash
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/invoices.js | 5 | ||||
| -rw-r--r-- | routes/payments.js | 25 |
2 files changed, 18 insertions, 12 deletions
diff --git a/routes/invoices.js b/routes/invoices.js index 9f2e4c99..d1ef1a68 100644 --- a/routes/invoices.js +++ b/routes/invoices.js @@ -7,14 +7,13 @@ import config from "$config"; import ln from "$lib/ln"; export default { - async get({ params: { hash } }, res) { + async get({ params: { id } }, res) { let pr; - let invoice = await g(`invoice:${hash}`); + let invoice = await g(`invoice:${id}`); if (invoice) { delete invoice.secret; invoice.user = pick(await g(`user:${invoice.uid}`), ['id', 'profile', 'banner', 'currency', 'username']); - invoice.id = hash; } else if (config.classic) { invoice = await got(`${config.classic}/invoice/${pr}`).json(); if (invoice) { diff --git a/routes/payments.js b/routes/payments.js index f83a9175..87096bdd 100644 --- a/routes/payments.js +++ b/routes/payments.js @@ -61,7 +61,8 @@ export default { let total = amount; let { amount_msat, payment_hash } = await ln.decode(payreq); if (amount_msat) total = Math.round(amount_msat / 1000); - let invoice = await g(`invoice:${payreq}`); + let iid = await g(`invoice:${payreq}`); + let invoice = await g(`invoice:${iid}`); if (invoice) { if (invoice.uid === user.id) fail("Cannot send to self"); @@ -270,7 +271,7 @@ export default { }); }, - async take({ body: { name, amount, hash }, user }, res) { + async take({ body: { name, amount, id }, user }, res) { try { amount = parseInt(amount); if (amount < 0) fail("Invalid amount"); @@ -283,11 +284,13 @@ export default { .exec(); }); - if (!hash) { - hash = v4(); + if (!id) { + id = v4(); let { currency } = user; - await s(`invoice:${hash}`, { + await s(`invoice:${id}`, { currency, + id, + hash: id, rate: store.rates[currency], uid: user.id, received: 0 @@ -310,7 +313,7 @@ export default { for (let { address, amount, category, vout } of details) { if (category !== "receive") continue; let p = await g(`payment:${txid}:${vout}`); - if (!p || confirmations < 1) { + if (!p) { await credit( address, sats(amount), @@ -318,7 +321,7 @@ export default { `${txid}:${vout}`, types.bitcoin ); - } else { + } else if(confirmations >= 1) { await confirm(address, txid, vout); } } @@ -400,9 +403,10 @@ export default { value } of tx.vout) { total += sats(value); + let iid = await g(`invoice:${address}`); if ( (await bc.getAddressInfo(address)).ismine && - !(await g(`invoice:${address}`)) + !iid ) change += sats(value); } @@ -459,9 +463,12 @@ export default { let { status } = r; if (status === "succeeded") { + let id = v4(); let hash = r.id; let memo = "stripe"; - await s(`invoice:${hash}`, { + await s(`invoice:${id}`, { + id, + hash: id, uid: user.id, received: 0 }); |
