diff options
| author | Adam Soltys <[email protected]> | 2023-01-19 16:00:38 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-01-19 16:00:38 -0800 |
| commit | 5264f702a2217fe8815cb5275aca14a672f6d4bb (patch) | |
| tree | 1c92a5258cfb92749c4250923f73797284c5d9c7 /lib/lightning.js | |
| parent | ef3679051214a9b3047b68f236eac656edcf8d38 (diff) | |
| download | coinos-server-5264f702a2217fe8815cb5275aca14a672f6d4bb.tar.gz coinos-server-5264f702a2217fe8815cb5275aca14a672f6d4bb.zip | |
refactor payment types
Diffstat (limited to 'lib/lightning.js')
| -rw-r--r-- | lib/lightning.js | 33 |
1 files changed, 2 insertions, 31 deletions
diff --git a/lib/lightning.js b/lib/lightning.js index 86dfdb2b..c8daf8c8 100644 --- a/lib/lightning.js +++ b/lib/lightning.js @@ -5,6 +5,7 @@ import { callWebhook } from "$lib/webhooks"; import ln from "$lib/ln"; import { l, err, warn } from "$lib/logging"; import { g, s, t, db } from "$lib/db"; +import { credit, types } from "$lib/payments"; export async function listenForLightning() { let { @@ -33,37 +34,7 @@ export async function listenForLightning() { let amount = parseInt(received) - tip; if (amount < 0) throw new Error("amount out of range"); - let user = await g(`user:${uid}`); - - let payment = { - amount, - created: Date.now(), - currency, - fee: 0, - hash, - memo, - preimage, - rate, - tip, - type: "lightning", - uid - }; - - invoice.status = "paid"; - invoice.received += received; - - await s(`invoice:${hash}`, invoice); - await db.incrBy(`balance:${uid}`, received); - payment.invoice = invoice; - await s(`payment:${hash}`, payment); - await db.lPush(`${uid}:payments`, hash); - - callWebhook(invoice, payment); - - emit(uid, "payment", payment); - notify(user, `Received ${received} SAT`); - - l("lightning payment received", user.username, payment.amount, payment.tip); + await credit(hash, amount, memo, preimage, types.lightning); } catch (e) { console.log(e); err("problem receiving lightning payment", e.message); |
