aboutsummaryrefslogtreecommitdiffstats
path: root/routes/payments.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-12-24 00:47:08 -0800
committerAdam Soltys <[email protected]>2024-12-24 00:47:12 -0800
commit4a9d5e1f40be289970f3dec2006852b160ae8e41 (patch)
treef6feb393c91e79048a7ad6ca4c69381d1a1e29f6 /routes/payments.ts
parent47236bc1ac522aa14e280e1a9664b3bd90e761db (diff)
downloadcoinos-server-4a9d5e1f40be289970f3dec2006852b160ae8e41.tar.gz
coinos-server-4a9d5e1f40be289970f3dec2006852b160ae8e41.zip
lnurlw
Diffstat (limited to 'routes/payments.ts')
-rw-r--r--routes/payments.ts28
1 files changed, 16 insertions, 12 deletions
diff --git a/routes/payments.ts b/routes/payments.ts
index 1f919cf4..665e0014 100644
--- a/routes/payments.ts
+++ b/routes/payments.ts
@@ -30,6 +30,7 @@ import got from "got";
import { v4 } from "uuid";
import ln from "$lib/ln";
+const { URL } = process.env;
export default {
async info(_, res) {
@@ -232,14 +233,14 @@ export default {
const {
params: { name },
} = req;
- const maxWithdrawable = await g(`fund:${name}`);
+ const balance = await g(`fund:${name}`);
res.send({
tag: "withdrawRequest",
- callback: `${URL}/lnurlw/${name}`,
+ callback: `${URL}/api/lnurlw`,
k1: name,
defaultDescription: `Withdraw from coinos fund ${name}`,
- minWithdrawable: 0,
- maxWithdrawable,
+ minWithdrawable: balance * 1000,
+ maxWithdrawable: balance * 1000,
});
},
@@ -249,39 +250,42 @@ export default {
user,
} = req;
try {
+ const { id: uid } = user;
amount = parseInt(amount);
if (amount < 0) fail("Invalid amount");
- await t(`fund:${id}`, async (balance, db) => {
- if (balance < amount) fail("Insufficient funds");
- await db.multi().decrBy(`fund:${id}`, amount).exec();
- });
+ await db.debit(`fund:${id}`, "", amount, 0, 0, 0);
+
+ const rates = await g("rates");
+ const { currency } = user;
+ const rate = rates[currency];
if (!iid) {
iid = v4();
- const rates = await g("rates");
- const { currency } = user;
await s(`invoice:${iid}`, {
currency,
id: iid,
hash: iid,
- rate: rates[currency],
- uid: user.id,
+ rate,
+ uid,
received: 0,
});
}
const payment = await credit({
+ aid: user.id,
hash: iid,
amount,
memo: id,
ref: id,
type: types.fund,
});
+
await db.lPush(`fund:${id}:payments`, payment.id);
res.send({ payment });
} catch (e) {
+ console.log(e);
warn("problem withdrawing from fund", e.message);
bail(res, e.message);
}