aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2025-05-12 15:30:35 +0000
committerAdam Soltys <[email protected]>2025-05-12 15:30:37 +0000
commit67f9ec53b7348860ab55e49574a81df4706dfb06 (patch)
tree80f19216cfd82f6da40126d5430bff5fcdcd12eb /lib
parent1e9d9989c11048002ff55a84c83e39fd5bf32378 (diff)
downloadcoinos-server-67f9ec53b7348860ab55e49574a81df4706dfb06.tar.gz
coinos-server-67f9ec53b7348860ab55e49574a81df4706dfb06.zip
debit signature
Diffstat (limited to 'lib')
-rw-r--r--lib/db.ts6
-rw-r--r--lib/payments.ts6
2 files changed, 6 insertions, 6 deletions
diff --git a/lib/db.ts b/lib/db.ts
index 7a779485..762afa41 100644
--- a/lib/db.ts
+++ b/lib/db.ts
@@ -6,12 +6,12 @@ import { warn, err } from "$lib/logging";
const DEBIT = `
local balanceKey = KEYS[1]
local creditKey = KEYS[2]
+local insufficientString = KEYS[3];
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')
@@ -20,7 +20,7 @@ local covered = math.min(credit, ourfee)
ourfee = ourfee - covered
if balance - frozen < amount + tip + fee + ourfee then
- return {err = insufficientString .. '⚡️' .. balance - frozen .. ' / ' .. amount + tip + fee + ourfee}
+ return {err = insufficientString .. ' ⚡️' .. balance - frozen .. ' / ' .. amount + tip + fee + ourfee}
end
redis.call('decrby', creditKey, tostring(math.floor(covered)))
@@ -55,7 +55,7 @@ end
`;
const debit = defineScript({
- NUMBER_OF_KEYS: 2,
+ NUMBER_OF_KEYS: 3,
SCRIPT: DEBIT,
transformArguments: (...args) => args.map((a) => a.toString()),
});
diff --git a/lib/payments.ts b/lib/payments.ts
index 38e8eab6..bc19dae9 100644
--- a/lib/payments.ts
+++ b/lib/payments.ts
@@ -120,17 +120,17 @@ export const debit = async ({
: 0;
if (aid && aid !== uid) ourfee = 0;
- const frozenBalance = await ga(`balance:${uid}`);
+ const frozenBalance = whitelisted ? 0 : await ga(`balance:${uid}`);
ourfee = await db.debit(
`balance:${aid || uid}`,
`credit:${creditType}:${aid !== uid ? 0 : uid}`,
+ t(user).insufficientFunds,
amount || 0,
tip || 0,
fee || 0,
ourfee || 0,
- frozenBalance,
- t(user).insufficientFunds,
+ frozenBalance || 0,
);
if (ourfee.err) fail(ourfee.err);