From bed887ae567acd4f8480bd3e2726474f79021714 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sun, 11 May 2025 16:31:42 -0700 Subject: check frozen balance --- lib/db.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/db.ts') 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))) -- cgit v1.2.3