From 44b5d463d8e32d9dd400ebb834ed2a877d93a639 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 20 Dec 2023 14:39:05 -0800 Subject: calculate fee from inputs and outputs --- lib/payments.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/payments.js b/lib/payments.js index 20429864..d257ed77 100644 --- a/lib/payments.js +++ b/lib/payments.js @@ -25,7 +25,7 @@ export const types = { classic: "classic", }; -export let debit = async ( +export let debit = async ({ hash, amount, fee = 0, @@ -33,12 +33,11 @@ export let debit = async ( user, type = types.internal, id = v4(), -) => { + rate = store.rates[currency] +}) => { let ref; let { id: uid, currency, username } = user; - let rate = store.rates[currency]; - let iid = await g(`invoice:${hash}`); if (iid && iid.hash) iid = iid.hash; let invoice = await g(`invoice:${iid}`); @@ -259,7 +258,14 @@ export let payLightning = async (user, payreq, amount, maxfee, memo) => { if (pays.find((p) => p.status === "pending")) fail("Payment is already underway"); - p = await debit(payreq, total, maxfee, memo, user, types.lightning); + p = await debit({ + hash: payreq, + amount: total, + fee: maxfee, + memo, + user, + type: types.lightning, + }); let check = async () => { try { -- cgit v1.2.3