aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-01-29 15:06:09 -0800
committerAdam Soltys <[email protected]>2024-01-29 15:06:09 -0800
commit86404448e9a06b6fd5b6ea341bda8ba372f88a66 (patch)
tree2d22cfb80d9797236f8f7ec74acc6d98652666a1 /routes
parent96f865cd9c9e70205d062e0cda86e0114afb5fbc (diff)
downloadcoinos-server-86404448e9a06b6fd5b6ea341bda8ba372f88a66.tar.gz
coinos-server-86404448e9a06b6fd5b6ea341bda8ba372f88a66.zip
autowithdrawals
Diffstat (limited to 'routes')
-rw-r--r--routes/payments.js13
-rw-r--r--routes/users.js3
2 files changed, 10 insertions, 6 deletions
diff --git a/routes/payments.js b/routes/payments.js
index 13ef20c2..86362a01 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -7,6 +7,7 @@ import { l, err, warn } from "$lib/logging";
import { bail, fail, getInvoice, btc, sats, SATS } from "$lib/utils";
import { requirePin } from "$lib/auth";
import {
+ autowithdraw,
debit,
credit,
types,
@@ -63,7 +64,7 @@ export default {
})
.json();
} else if (payreq) {
- p = await sendLightning(user, payreq, amount, maxfee, memo);
+ p = await sendLightning({ user, pr: payreq, amount, maxfee, memo });
}
if (!p) {
@@ -270,6 +271,8 @@ export default {
.exec();
emit(p.uid, "payment", p);
+ let user = await g(`user:${p.uid}`);
+ autowithdraw(user);
}
}
}
@@ -285,7 +288,7 @@ export default {
try {
res.send(await build({ ...body, user }));
} catch (e) {
- console.log(e)
+ console.log(e);
warn(
"problem estimating fee",
e.message,
@@ -302,11 +305,11 @@ export default {
async send({ body, user }, res) {
try {
await requirePin({ body, user });
- let txid = await sendOnchain({ ...body, user });
+ let txid = await sendOnchain({ ...body, user });
res.send({ txid });
} catch (e) {
- console.log(e)
+ console.log(e);
warn("payment failed", e.message);
res.code(500).send(e.message);
}
@@ -365,7 +368,7 @@ export default {
let r = await got(`${callback}?amount=${amount * 1000}`).json();
if (r.reason) fail(r.rason);
let { pr } = r;
- let p = await sendLightning(user, pr, amount, maxfee, memo);
+ let p = await sendLightning({ user, pr, amount, maxfee, memo });
if (!p) {
p = await debit({ hash: pr, amount, memo, user });
diff --git a/routes/users.js b/routes/users.js
index dff3f7bc..8e2a0d14 100644
--- a/routes/users.js
+++ b/routes/users.js
@@ -41,6 +41,7 @@ export default {
user.prompt = !!user.prompt;
if (user.pubkey)
user.npub = encode("npub", toWords(Buffer.from(user.pubkey, "hex")));
+
res.send(pick(user, whitelist));
} catch (e) {
console.log("problem fetching user", e);
@@ -237,6 +238,7 @@ export default {
"prompt",
"profile",
"pubkey",
+ "reserve",
"salt",
"seed",
"threshold",
@@ -244,7 +246,6 @@ export default {
"twofa",
"shopifyToken",
"shopifyStore",
- "withdrawal",
];
for (let a of attributes) {