aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-05-08 16:59:05 -0700
committerAdam Soltys <[email protected]>2023-05-08 16:59:05 -0700
commit841e5434fe3b53bc35b0c5e22e7589b47aac5dc7 (patch)
tree7199325a009b3eda7b534d5a567e473af094b0bf
parent88990faa498ab269d1745dc6524cddf2fe9e5245 (diff)
downloadcoinos-server-841e5434fe3b53bc35b0c5e22e7589b47aac5dc7.tar.gz
coinos-server-841e5434fe3b53bc35b0c5e22e7589b47aac5dc7.zip
withdraw endpoint
-rw-r--r--index.js1
-rw-r--r--routes/lnurl.js3
-rw-r--r--routes/payments.js35
3 files changed, 29 insertions, 10 deletions
diff --git a/index.js b/index.js
index 6e001025..a799ab30 100644
--- a/index.js
+++ b/index.js
@@ -53,6 +53,7 @@ app.get("/payments", auth, payments.list);
app.get("/payments/:hash", auth, payments.get);
app.post("/parse", payments.parse);
app.get("/pot/:name", payments.pot);
+app.get("/pot/:name/withdraw", payments.withdraw);
app.post("/take", auth, payments.take);
app.post("/buy", auth, payments.buy);
app.post("/print", auth, payments.print);
diff --git a/routes/lnurl.js b/routes/lnurl.js
index 14f848a4..146ac199 100644
--- a/routes/lnurl.js
+++ b/routes/lnurl.js
@@ -89,6 +89,9 @@ export default {
}
},
+ async lnurlw({ params: { k1, pr } }, res) {
+ },
+
async lnurl({ params: { id }, query: { amount } }, res) {
let pr = await g(`lnurlp:${id}`);
diff --git a/routes/payments.js b/routes/payments.js
index 282a8682..874ed6e1 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -192,8 +192,21 @@ export default {
res.send({ amount, payments });
},
- async take({ body: { name, amount }, user }, res) {
+ async withdraw({ params: { name } }, res) {
+ let maxWithdrawable = await g(`pot:${name}`);
+ res.send({
+ tag: "withdrawRequest",
+ callback: `${URL}/lnurlw/${name}`,
+ k1: name,
+ defaultDescription: `Withdraw from coinos pot ${name}`,
+ minWithdrawable: 0,
+ maxWithdrawable
+ });
+ },
+
+ async take({ body: { name, amount, hash }, user }, res) {
amount = parseInt(amount);
+
await t(`pot:${name}`, async (balance, db) => {
if (balance < amount) fail("Insufficient funds");
await db
@@ -202,16 +215,18 @@ export default {
.exec();
});
- let hash = v4();
- let { currency } = user;
- await s(`invoice:${hash}`, {
- currency,
- rate: store.rates[currency],
- uid: user.id,
- received: 0
- });
+ if (!hash) {
+ hash = v4();
+ let { currency } = user;
+ await s(`invoice:${hash}`, {
+ currency,
+ rate: store.rates[currency],
+ uid: user.id,
+ received: 0
+ });
+ }
- let payment = await credit(hash, amount, "", name, types.pot);
+ let payment = await credit(hash, amount, name, name, types.pot);
await db.lPush(`pot:${name}:payments`, hash);
res.send({ payment });