aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-12-20 14:39:05 -0800
committerAdam Soltys <[email protected]>2023-12-20 14:39:08 -0800
commit44b5d463d8e32d9dd400ebb834ed2a877d93a639 (patch)
tree3e52a95fba04dc96dd1d1ab0e79e2d8f03564781 /lib
parentb67ca07bac3a0cb78f9b3c19a783c3253f06c29f (diff)
downloadcoinos-server-44b5d463d8e32d9dd400ebb834ed2a877d93a639.tar.gz
coinos-server-44b5d463d8e32d9dd400ebb834ed2a877d93a639.zip
calculate fee from inputs and outputs
Diffstat (limited to 'lib')
-rw-r--r--lib/payments.js16
1 files changed, 11 insertions, 5 deletions
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 {