aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2025-05-11 16:31:42 -0700
committerAdam Soltys <[email protected]>2025-05-11 16:31:42 -0700
commitbed887ae567acd4f8480bd3e2726474f79021714 (patch)
tree72545f4a532792cc0ced2370a1f7512886bfcf10 /lib
parentc7b93725a08333516c89bdb64f4b4149f6b0da2b (diff)
downloadcoinos-server-bed887ae567acd4f8480bd3e2726474f79021714.tar.gz
coinos-server-bed887ae567acd4f8480bd3e2726474f79021714.zip
check frozen balance
Diffstat (limited to 'lib')
-rw-r--r--lib/db.ts6
-rw-r--r--lib/locales/en.json3
-rw-r--r--lib/payments.ts7
3 files changed, 11 insertions, 5 deletions
diff --git a/lib/db.ts b/lib/db.ts
index 57b53037..7a779485 100644
--- a/lib/db.ts
+++ b/lib/db.ts
@@ -10,6 +10,8 @@ local amount = tonumber(ARGV[1])
local tip = tonumber(ARGV[2])
local fee = tonumber(ARGV[3])
local ourfee = tonumber(ARGV[4])
+local frozen = tonumber(ARGV[5])
+local insufficientString = ARGV[6];
local balance = tonumber(redis.call('get', balanceKey) or '0')
local credit = tonumber(redis.call('get', creditKey) or '0')
@@ -17,8 +19,8 @@ local credit = tonumber(redis.call('get', creditKey) or '0')
local covered = math.min(credit, ourfee)
ourfee = ourfee - covered
-if balance < amount + tip + fee + ourfee then
- return {err = 'Insufficient funds ⚡️' .. balance .. ' of ⚡️' .. amount + tip + fee + ourfee}
+if balance - frozen < amount + tip + fee + ourfee then
+ return {err = insufficientString .. '⚡️' .. balance - frozen .. ' / ' .. amount + tip + fee + ourfee}
end
redis.call('decrby', creditKey, tostring(math.floor(covered)))
diff --git a/lib/locales/en.json b/lib/locales/en.json
index 7d143c53..fbe8e851 100644
--- a/lib/locales/en.json
+++ b/lib/locales/en.json
@@ -4,5 +4,6 @@
"hello": "Hello",
"youReceived": "You received a payment of",
"withdrawalTriggered": "This triggered a withdrawal of",
- "problemWithdrawing": "There was a problem sending to your autowithdrawal address"
+ "problemWithdrawing": "There was a problem sending to your autowithdrawal address",
+ "insufficientFunds": "Insufficient funds"
}
diff --git a/lib/payments.ts b/lib/payments.ts
index a0611c51..38e8eab6 100644
--- a/lib/payments.ts
+++ b/lib/payments.ts
@@ -1,6 +1,6 @@
import config from "$config";
import api from "$lib/api";
-import { db, g, s } from "$lib/db";
+import { db, g, ga, s } from "$lib/db";
import { generate } from "$lib/invoices";
import ln from "$lib/ln";
import { err, l, warn } from "$lib/logging";
@@ -120,6 +120,7 @@ export const debit = async ({
: 0;
if (aid && aid !== uid) ourfee = 0;
+ const frozenBalance = await ga(`balance:${uid}`);
ourfee = await db.debit(
`balance:${aid || uid}`,
@@ -128,8 +129,10 @@ export const debit = async ({
tip || 0,
fee || 0,
ourfee || 0,
+ frozenBalance,
+ t(user).insufficientFunds,
);
-
+
if (ourfee.err) fail(ourfee.err);
const id = v4();