aboutsummaryrefslogtreecommitdiffstats
path: root/lib/invoices.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-10-08 00:16:50 -0700
committerAdam Soltys <[email protected]>2023-10-08 00:16:50 -0700
commitdb38e8f3316a121ba64d7e1c4cfd93b4826d6f4e (patch)
tree172eaaed2c04d0c0e6491a68f7b8631a6298bf4b /lib/invoices.js
parentf599e57af5564c23908632c42d4827e51d120204 (diff)
downloadcoinos-server-db38e8f3316a121ba64d7e1c4cfd93b4826d6f4e.tar.gz
coinos-server-db38e8f3316a121ba64d7e1c4cfd93b4826d6f4e.zip
use invoice id instead of hash
Diffstat (limited to 'lib/invoices.js')
-rw-r--r--lib/invoices.js14
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/invoices.js b/lib/invoices.js
index 0bb57714..8ac49a79 100644
--- a/lib/invoices.js
+++ b/lib/invoices.js
@@ -36,6 +36,8 @@ export let generate = async ({ invoice, user, sender, memo }) => {
if (fiat) amount = Math.round((SATS * fiat) / rate);
if (amount < 0) fail("invalid amount");
+ let id = v4();
+
let hash, text;
if (type === types.lightning) {
let r = await ln.invoice({
@@ -52,7 +54,7 @@ export let generate = async ({ invoice, user, sender, memo }) => {
hash = await bc.getNewAddress();
text = bip21(hash, invoice);
} else if (type === types.internal) {
- hash = v4();
+ hash = id;
} else {
fail("unrecognized type");
}
@@ -62,6 +64,7 @@ export let generate = async ({ invoice, user, sender, memo }) => {
created: Date.now(),
currency,
hash,
+ id,
rate,
pending: 0,
received: 0,
@@ -75,16 +78,17 @@ export let generate = async ({ invoice, user, sender, memo }) => {
webhook
};
- l("creating invoice", user.username, amount, tip, currency, invoice.hash);
+ l("creating invoice", id, user.username, amount, tip, currency, invoice.hash);
- await s(`invoice:${hash}`, invoice);
- await db.lPush(`${user.id}:invoices`, hash);
+ await s(`invoice:${hash}`, id);
+ await s(`invoice:${id}`, invoice);
+ await db.lPush(`${user.id}:invoices`, id);
if (request_id) {
let request = await g(`request:${request_id}`);
if (request) {
let { invoice_id: prev } = request;
- request.invoice_id = hash;
+ request.invoice_id = id;
await s(`request:${request_id}`, request);
if (!prev) emit(request.requester_id, "invoice", invoice);