aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-02-18 07:49:25 -0800
committerAdam Soltys <[email protected]>2026-02-18 07:49:25 -0800
commitb1e3435613ef092d43353d511b632a8de64efc5d (patch)
treea300812eec33177505dbba5882d25669fea4243e /routes
parent6e5c851fe1c4e7402014c5a42c8a5f919365a2c7 (diff)
downloadcoinos-server-b1e3435613ef092d43353d511b632a8de64efc5d.tar.gz
coinos-server-b1e3435613ef092d43353d511b632a8de64efc5d.zip
migrate funds to tb
Diffstat (limited to 'routes')
-rw-r--r--routes/payments.ts16
1 files changed, 8 insertions, 8 deletions
diff --git a/routes/payments.ts b/routes/payments.ts
index c77da697..6bc13b1c 100644
--- a/routes/payments.ts
+++ b/routes/payments.ts
@@ -24,7 +24,7 @@ import {
sendOnchain,
} from "$lib/payments";
import { emit } from "$lib/sockets";
-import { fundDebit, getBalance, getCredit, tbConfirm, tbCredit } from "$lib/tb";
+import { getBalance, getCredit, getFundBalance, tbConfirm, tbCredit, tbFundCredit, tbFundDebit } from "$lib/tb";
import { PaymentType } from "$lib/types";
import {
SATS,
@@ -109,13 +109,13 @@ export default {
}
} else if (fund) {
p = await debit({
- hash,
+ hash: v4(),
amount,
memo: fund,
user,
type: PaymentType.fund,
});
- await db.incrBy(`fund:${fund}`, amount);
+ await tbFundCredit(fund, amount);
await db.lPush(`fund:${fund}:payments`, p.id);
l("funded fund", fund);
}
@@ -277,8 +277,8 @@ export default {
const {
params: { id },
} = req;
- const amount = await g(`fund:${id}`);
- if (typeof amount === "undefined" || amount === null)
+ const amount = await getFundBalance(id);
+ if (amount === null)
return bail(res, "fund not found");
let payments = (await db.lRange(`fund:${id}:payments`, 0, -1)) || [];
payments = await Promise.all(payments.map((hash) => gf(`payment:${hash}`)));
@@ -336,7 +336,7 @@ export default {
} = req;
try {
amount = Number.parseInt(amount);
- if (amount < 0) fail("Invalid amount");
+ if (amount <= 0) fail("Invalid amount");
const rates = await g("rates");
@@ -370,7 +370,7 @@ export default {
type: PaymentType.fund,
});
- await db.incrBy(`fund:${id}`, amount);
+ await tbFundCredit(id, amount);
await db.lPush(`fund:${id}:payments`, pid);
l("funded fund", id);
}
@@ -378,7 +378,7 @@ export default {
const managers = await db.sMembers(`fund:${id}:managers`);
if (managers.length && !managers.includes(user.id)) fail("Unauthorized");
- const result: any = await fundDebit(`fund:${id}`, amount, "Insufficient funds");
+ const result: any = await tbFundDebit(id, amount, "Insufficient funds");
if (result.err) fail(result.err);
const payment = await credit({