diff options
| author | Adam Soltys <[email protected]> | 2025-02-12 04:11:26 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2025-02-12 04:11:26 -0800 |
| commit | 3783b6fc63d67853ba9bb11bd40f1d967b846240 (patch) | |
| tree | 3cb9df05c3bafbef8eb6cb62973861e16f1b6f1f | |
| parent | eb3c2aad4cef9b86294bc9a13a36da4918529209 (diff) | |
| download | coinos-server-3783b6fc63d67853ba9bb11bd40f1d967b846240.tar.gz coinos-server-3783b6fc63d67853ba9bb11bd40f1d967b846240.zip | |
server limits
| -rw-r--r-- | lib/payments.ts | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/lib/payments.ts b/lib/payments.ts index a150e50c..2f21d765 100644 --- a/lib/payments.ts +++ b/lib/payments.ts @@ -54,10 +54,17 @@ export const debit = async ({ rate = undefined, }) => { amount = parseInt(amount); - // let whitelisted = await db.sIsMember("whitelist", user?.username?.toLowerCase()); + const whitelisted = await db.sIsMember( + "whitelist", + user?.username?.toLowerCase().trim(), + ); - if (type !== types.internal && (await g("freeze"))) { - warn("Blocking payment", amount, hash, user.username, user.id); + if ( + (amount > (await g("withdrawallimit")) && !whitelisted) || + amount > (await g(`${type}:limit`)) || + (await g("hardfreeze")) + ) { + warn("Blocking", user.username, amount, hash, user.id); fail("Problem sending payment"); } @@ -866,16 +873,22 @@ const reverse = async (p) => { const freezeCheck = async () => { const funds = await ln.listfunds(); - const balance = Math.round( + const lnbalance = Math.round( funds.channels.reduce((a, b) => a + b.our_amount_msat, 0) / 1000, ); - const threshold = await g("freezethreshold"); - if (balance < threshold) { - await s("hardfreeze", true); - } else { - await s("hardfreeze", false); - } - setTimeout(freezeCheck, 5000); + const bcbalance = Math.round(await bc.getBalance()) * SATS; + const { bitcoin } = await lq.getBalance(); + const lqbalance = Math.round(bitcoin * SATS); + + const lnthreshold = await g("lightning:threshold"); + const bcthreshold = await g("bitcoin:threshold"); + const lqthreshold = await g("liquid:threshold"); + + await s("lightning:limit", Math.max(lnbalance - lnthreshold, 0)); + await s("bitcoin:limit", Math.max(lqbalance - lqthreshold, 0)); + await s("liquid:limit", Math.max(bcbalance - bcthreshold, 0)); + + setTimeout(freezeCheck, 10000); }; freezeCheck(); |
