aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/db.ts6
-rw-r--r--lib/payments.ts6
-rw-r--r--routes/ecash.ts2
-rw-r--r--routes/payments.ts3
4 files changed, 10 insertions, 7 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);
diff --git a/routes/ecash.ts b/routes/ecash.ts
index 25b7a255..96783cc4 100644
--- a/routes/ecash.ts
+++ b/routes/ecash.ts
@@ -105,10 +105,12 @@ export default {
const ourfee = await db.debit(
`balance:${uid}`,
`credit:${type}:${uid}`,
+ "Insufficient funds",
amount || 0,
0,
0,
0,
+ 0
);
const rates = await g("rates");
diff --git a/routes/payments.ts b/routes/payments.ts
index 56e0b9d3..9e00653a 100644
--- a/routes/payments.ts
+++ b/routes/payments.ts
@@ -90,6 +90,7 @@ export default {
res.send(p);
} catch (e) {
+ console.log(e);
warn(user.username, "payment failed", amount, balance, hash, payreq);
err(e.message);
bail(res, e.message);
@@ -271,7 +272,7 @@ export default {
const managers = await db.sMembers(`fund:${id}:managers`);
if (managers.length && !managers.includes(user.id)) fail("Unauthorized");
- const result: any = await db.debit(`fund:${id}`, "", amount, 0, 0, 0);
+ const result: any = await db.debit(`fund:${id}`, "", "Insufficient funds", amount, 0, 0, 0, 0);
if (result.err) fail(result.err);
const rates = await g("rates");