aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2025-02-25 04:11:50 -0800
committerAdam Soltys <[email protected]>2025-02-25 04:11:50 -0800
commitc8508982dc216615e3e342b734d6e16145808008 (patch)
treeb3416c7b48d4327d3aba57c8e69d78f15b00c288 /lib
parentfc394c6299ff200f4e4f5a95fe34f4e97988632e (diff)
downloadcoinos-server-c8508982dc216615e3e342b734d6e16145808008.tar.gz
coinos-server-c8508982dc216615e3e342b734d6e16145808008.zip
allow 0 fee payments to direct channels
Diffstat (limited to 'lib')
-rw-r--r--lib/payments.ts39
1 files changed, 29 insertions, 10 deletions
diff --git a/lib/payments.ts b/lib/payments.ts
index 9c819866..d9833c96 100644
--- a/lib/payments.ts
+++ b/lib/payments.ts
@@ -65,12 +65,25 @@ export const debit = async ({
user?.username?.toLowerCase().trim(),
);
- let serverLimit = await g(`${type}:limit`);
- let userLimit = await g("limit");
- let frozen = (await g("hardfreeze")) || ((await g("freeze")) && type !== types.internal) || blacklisted;
+ const serverLimit = await g(`${type}:limit`);
+ const userLimit = await g("limit");
+ const frozen =
+ (await g("hardfreeze")) ||
+ ((await g("freeze")) && type !== types.internal) ||
+ blacklisted;
if (frozen || (amount > userLimit && !whitelisted) || amount > serverLimit) {
- warn("Blocking", user.username, amount, hash, user.id, type, frozen, userLimit, serverLimit);
+ warn(
+ "Blocking",
+ user.username,
+ amount,
+ hash,
+ user.id,
+ type,
+ frozen,
+ userLimit,
+ serverLimit,
+ );
fail("Problem sending payment");
}
@@ -511,12 +524,18 @@ export const sendLightning = async ({
fail("Invalid amount");
}
- const decoded = await ln.decode(pr);
- const amount_msat = decoded.type.includes("bolt12")
- ? decoded.invoice_amount_msat
- : decoded.amount_msat;
+ let { type, invoice_amount_msat, amount_msat, invoice_node_id, payee } =
+ await ln.decode(pr);
+ if (type.includes("bolt12")) {
+ amount_msat = invoice_amount_msat;
+ payee = invoice_node_id;
+ }
+
+ let minfee = 2;
+ const { channels } = await ln.listpeerchannels();
+ if (channels.some((c) => c.peer_id === payee)) minfee = 0;
- fee = Math.max(parseInt(fee || 0), 2);
+ fee = Math.max(parseInt(fee || 0), minfee);
if (fee < 0) fail("Fee cannot be negative");
const { pays } = await ln.listpays(pr);
@@ -882,7 +901,7 @@ const freezeCheck = async () => {
funds.channels.reduce((a, b) => a + b.our_amount_msat, 0) / 1000,
);
- const bcbalance = Math.round(await bc.getBalance() * SATS);
+ const bcbalance = Math.round((await bc.getBalance()) * SATS);
const { bitcoin } = await lq.getBalance();
const lqbalance = Math.round(bitcoin * SATS);