aboutsummaryrefslogtreecommitdiffstats
path: root/lib/payments.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-12-02 12:53:19 -0800
committerAdam Soltys <[email protected]>2024-12-02 12:53:19 -0800
commit501e2ba1942911a98278a95121a7553da19795d2 (patch)
tree5d55f8e88a95fbf708d47c0afc86ad559ccfaf18 /lib/payments.ts
parentd16675345757dc7bf180f4aa51ccb0d124ea7e12 (diff)
downloadcoinos-server-501e2ba1942911a98278a95121a7553da19795d2.tar.gz
coinos-server-501e2ba1942911a98278a95121a7553da19795d2.zip
keysend
Diffstat (limited to 'lib/payments.ts')
-rw-r--r--lib/payments.ts41
1 files changed, 37 insertions, 4 deletions
diff --git a/lib/payments.ts b/lib/payments.ts
index fb394550..2b344817 100644
--- a/lib/payments.ts
+++ b/lib/payments.ts
@@ -281,18 +281,18 @@ const pay = async ({ aid = undefined, amount, to, user }) => {
).toString();
}
- const maxfee = Math.max(5, Math.round(amount * 0.005));
+ const fee = Math.max(5, Math.round(amount * 0.005));
if (lnurl) {
- amount -= maxfee;
+ amount -= fee;
const { callback } = (await got(lnurl).json()) as any;
({ pr } = (await got(`${callback}?amount=${amount * 1000}`).json()) as any);
} else if (to.startsWith("ln")) {
- amount -= maxfee;
+ amount -= fee;
pr = to;
}
return pr
- ? await sendLightning({ user, pr, amount, maxfee })
+ ? await sendLightning({ user, pr, amount, fee })
: await sendOnchain({ aid, amount, address: to, user, subtract: true });
};
@@ -415,6 +415,39 @@ export const sendOnchain = async (params) => {
}
};
+export const sendKeysend = async ({
+ amount,
+ pubkey,
+ fee,
+ memo = undefined,
+ user,
+}) => {
+ let p = await debit({
+ hash: pubkey,
+ amount,
+ fee,
+ memo,
+ user,
+ type: types.lightning,
+ });
+
+ fee = Math.max(parseInt(fee || 0), 5);
+ if (fee < 0) fail("Fee cannot be negative");
+
+ const r = await ln.keysend({
+ pubkey,
+ amount_msat: amount * 1000,
+ maxfee: fee * 1000,
+ retry_for: 10,
+ });
+
+ try {
+ if (r.status === "complete") p = await finalize(r, p);
+ } catch (e) {
+ warn("failed to process payment", p.id);
+ }
+};
+
export const sendLightning = async ({
user,
pr,