aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/api.js5
-rw-r--r--lib/payments.js19
2 files changed, 17 insertions, 7 deletions
diff --git a/lib/api.js b/lib/api.js
new file mode 100644
index 00000000..3fa8c35b
--- /dev/null
+++ b/lib/api.js
@@ -0,0 +1,5 @@
+export default {
+ bitcoin: "https://mempool.space/api/v1",
+ liquid: "https://liquid.network/api/v1",
+};
+
diff --git a/lib/payments.js b/lib/payments.js
index 6c98c15e..2b2ed2af 100644
--- a/lib/payments.js
+++ b/lib/payments.js
@@ -11,6 +11,7 @@ import { callWebhook } from "$lib/webhooks";
import got from "got";
import { mqtt1, mqtt2 } from "$lib/mqtt";
import { mail, templates } from "$lib/mail";
+import api from "$lib/api";
import lq from "$lib/liquid";
import bc from "$lib/bitcoin";
@@ -18,11 +19,6 @@ import ln from "$lib/ln";
let { URL } = process.env;
-let api = {
- bitcoin: "https://mempool.space/api/v1",
- liquid: "https://liquid.network/api/v1",
-};
-
export let types = {
internal: "internal",
bitcoin: "bitcoin",
@@ -91,7 +87,7 @@ export let debit = async ({
memo,
iid,
uid,
- confirmed: true,
+ confirmed: ![types.bitcoin, types.liquid].includes(type),
rate,
currency,
type,
@@ -100,6 +96,7 @@ export let debit = async ({
created: Date.now(),
};
+ await s(`payment:${hash}`, id);
await s(`payment:${id}`, p);
await db.lPush(`${uid}:payments`, id);
@@ -267,12 +264,13 @@ let pay = async ({ amount, to, user }) => {
pr = to;
}
+ console.log("PAYING");
return pr
? await sendLightning({ user, pr, amount, maxfee })
: await sendOnchain({ amount, address: to, user, subtract: true });
};
-let decode = async (hex) => {
+export let decode = async (hex) => {
let type, tx;
try {
tx = await bc.decodeRawTransaction(hex);
@@ -282,6 +280,7 @@ let decode = async (hex) => {
tx = await lq.decodeRawTransaction(hex);
type = types.liquid;
} catch (e) {
+ err("invalid hex", hex);
fail("unrecognized tx");
}
}
@@ -364,7 +363,11 @@ export let sendOnchain = async (params) => {
type,
});
+ p.hex = signed;
+ await s(`payment:${p.id}`, p);
+
await node.sendRawTransaction(signed);
+
return p;
};
@@ -517,6 +520,8 @@ export let build = async ({ amount, address, feeRate, user, subtract }) => {
feeRate = fees.halfHourFee;
}
+ if (feeRate < fees.economyFee) fail("fee rate too low");
+
let replaceable = true;
let outs = [{ [address]: btc(amount) }];