Fix duplicate deposit push messages sent (#940)
This commit is contained in:
parent
39991575d6
commit
f4513b6710
@ -0,0 +1,21 @@
|
|||||||
|
-- return integer based on update
|
||||||
|
CREATE OR REPLACE FUNCTION confirm_invoice(lnd_id TEXT, lnd_received BIGINT)
|
||||||
|
RETURNS INTEGER
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS $$
|
||||||
|
DECLARE
|
||||||
|
user_id INTEGER;
|
||||||
|
confirmed_at TIMESTAMP;
|
||||||
|
BEGIN
|
||||||
|
PERFORM ASSERT_SERIALIZED();
|
||||||
|
|
||||||
|
SELECT "userId", "confirmedAt" INTO user_id, confirmed_at FROM "Invoice" WHERE hash = lnd_id;
|
||||||
|
IF confirmed_at IS NULL THEN
|
||||||
|
UPDATE "Invoice" SET "msatsReceived" = lnd_received, "confirmedAt" = now_utc(), updated_at = now_utc()
|
||||||
|
WHERE hash = lnd_id;
|
||||||
|
UPDATE users SET msats = msats + lnd_received WHERE id = user_id;
|
||||||
|
RETURN 0;
|
||||||
|
END IF;
|
||||||
|
RETURN 1;
|
||||||
|
END;
|
||||||
|
$$;
|
@ -122,20 +122,23 @@ async function checkInvoice ({ data: { hash }, boss, models, lnd }) {
|
|||||||
// ALSO: is_confirmed and is_held are mutually exclusive
|
// ALSO: is_confirmed and is_held are mutually exclusive
|
||||||
// that is, a hold invoice will first be is_held but not is_confirmed
|
// that is, a hold invoice will first be is_held but not is_confirmed
|
||||||
// and once it's settled it will be is_confirmed but not is_held
|
// and once it's settled it will be is_confirmed but not is_held
|
||||||
await serialize(models,
|
const [[{ confirm_invoice: code }]] = await serialize(models,
|
||||||
models.$executeRaw`SELECT confirm_invoice(${inv.id}, ${Number(inv.received_mtokens)})`,
|
models.$queryRaw`SELECT confirm_invoice(${inv.id}, ${Number(inv.received_mtokens)})`,
|
||||||
models.invoice.update({ where: { hash }, data: { confirmedIndex: inv.confirmed_index } })
|
models.invoice.update({ where: { hash }, data: { confirmedIndex: inv.confirmed_index } })
|
||||||
)
|
)
|
||||||
|
|
||||||
// don't send notifications for JIT invoices
|
// don't send notifications for JIT invoices
|
||||||
if (dbInv.preimage) return
|
if (dbInv.preimage) return
|
||||||
|
|
||||||
sendUserNotification(dbInv.userId, {
|
if (code === 0) {
|
||||||
title: `${numWithUnits(msatsToSats(inv.received_mtokens), { abbreviate: false })} were deposited in your account`,
|
sendUserNotification(dbInv.userId, {
|
||||||
body: dbInv.comment || undefined,
|
title: `${numWithUnits(msatsToSats(inv.received_mtokens), { abbreviate: false })} were deposited in your account`,
|
||||||
tag: 'DEPOSIT',
|
body: dbInv.comment || undefined,
|
||||||
data: { sats: msatsToSats(inv.received_mtokens) }
|
tag: 'DEPOSIT',
|
||||||
}).catch(console.error)
|
data: { sats: msatsToSats(inv.received_mtokens) }
|
||||||
|
}).catch(console.error)
|
||||||
|
}
|
||||||
|
|
||||||
return await boss.send('nip57', { hash })
|
return await boss.send('nip57', { hash })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user