diff options
| author | Adam Soltys <[email protected]> | 2022-09-09 14:27:02 -0400 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-09-09 14:27:02 -0400 |
| commit | 86c59fc85cba222abc6dbe82d862ca45892a27c8 (patch) | |
| tree | 6d10f654ca27d056bad6e598e431454453feb225 | |
| parent | b075ae593d619a860c0b38350cada35f29f65c23 (diff) | |
| download | coinos-server-86c59fc85cba222abc6dbe82d862ca45892a27c8.tar.gz coinos-server-86c59fc85cba222abc6dbe82d862ca45892a27c8.zip | |
remove cancelled ln payments
| -rw-r--r-- | lib/sync.js | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/lib/sync.js b/lib/sync.js index 536bd582..57f0c507 100644 --- a/lib/sync.js +++ b/lib/sync.js @@ -75,12 +75,14 @@ const sync = async () => { ] }); - let { invoices } = await getInvoices({ lnd, limit: 200 }); + let { invoices } = await getInvoices({ lnd, limit: 1000 }); + let x = invoices.find(i => i.request.includes('lnbc10100u1p333l3lpp5znwsrpr9g')); + let cancelled = invoices.filter(i => i.is_canceled); let recent = invoices .filter( i => - i.secret && + i.is_confirmed && differenceInDays(new Date(), new Date(i.created_at)) < 2 ) .map(i => ({ @@ -98,6 +100,28 @@ const sync = async () => { }) ).map(p => p.preimage); + for (let i = 0; i < cancelled.length; i++) { + let c = cancelled[i]; + if (settled.includes(c.secret)) { + await db.transaction(async transaction => { + let p = await db.Payment.findOne({ + where: { + preimage: c.secret + }, + include: { + model: db.Account, + as: "account" + }, + transaction + }); + + console.log("destroying", p.id); + await p.account.decrement({ balance: p.amount }, { transaction }); + await p.destroy({ transaction }); + }); + } + } + let missed = recent.filter(i => !settled.includes(i.preimage)); for (let i = 0; i < missed.length; i++) { let { amount, preimage, pr: text, createdAt } = missed[i]; |
