From 5264f702a2217fe8815cb5275aca14a672f6d4bb Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 19 Jan 2023 16:00:38 -0800 Subject: refactor payment types --- lib/lightning.js | 33 ++------------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) (limited to 'lib/lightning.js') 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); -- cgit v1.2.3