aboutsummaryrefslogtreecommitdiffstats
path: root/lib/payments.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-12-28 22:50:56 -0800
committerAdam Soltys <[email protected]>2023-12-28 22:51:02 -0800
commitcb38551cc4ec392911d18dda9b5a9fe97087ad61 (patch)
tree939808cef6a568dbe86ed8b2ba6b95fcc2fe9178 /lib/payments.js
parent73a36051979e7257d9198bed976128e8cea5235d (diff)
downloadcoinos-server-cb38551cc4ec392911d18dda9b5a9fe97087ad61.tar.gz
coinos-server-cb38551cc4ec392911d18dda9b5a9fe97087ad61.zip
liquid
Diffstat (limited to 'lib/payments.js')
-rw-r--r--lib/payments.js13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/payments.js b/lib/payments.js
index e0aff192..03daf93e 100644
--- a/lib/payments.js
+++ b/lib/payments.js
@@ -5,7 +5,7 @@ import { v4 } from "uuid";
import { notify } from "$lib/notifications";
import { db, g, s, t } from "$lib/db";
import { l, err, warn } from "$lib/logging";
-import { fail, wait, SATS } from "$lib/utils";
+import { fail, sleep, wait, SATS } from "$lib/utils";
import { callWebhook } from "$lib/webhooks";
import got from "got";
import { spawn } from "child_process";
@@ -61,7 +61,7 @@ export let debit = async ({
if (!amount || amount < 0) fail("Amount must be greater than zero");
- let ourfee = [types.bitcoin, types.lightning].includes(type)
+ let ourfee = [types.bitcoin, types.liquid, types.lightning].includes(type)
? Math.round(amount * config.fee)
: 0;
@@ -128,6 +128,9 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => {
let rate = store.rates[currency];
+ if (!rate) await sleep(1000);
+ rate = store.rates[currency];
+
let equivalentRate =
invoice.rate * (store.rates[currency] / store.rates[invoice.currency]);
@@ -153,11 +156,11 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => {
created: Date.now(),
};
- if (type === types.bitcoin) invoice.pending += amount;
+ if ([types.bitcoin, types.liquid].includes(type)) invoice.pending += amount;
else invoice.received += amount;
let balance = "balance";
- if (type === types.bitcoin) {
+ if ([types.bitcoin, types.liquid].includes(type)) {
let [txid, vout] = ref.split(":").slice(-2);
p.confirmed = false;
balance = "pending";
@@ -168,7 +171,7 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => {
let m = await db.multi();
- if ([types.bitcoin, types.lightning].includes(type))
+ if ([types.bitcoin, types.liquid, types.lightning].includes(type))
m.incrBy(`credit:${type}:${uid}`, Math.round(amount * config.fee));
m.set(`invoice:${iid}`, JSON.stringify(invoice))