aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-01-26 11:26:05 -0800
committerAdam Soltys <[email protected]>2023-01-26 11:26:09 -0800
commitf0543b6d94081f43a265bb9f754a654df9c4268a (patch)
treec2fee79d8e410a2b6914f2dd53d7abef19497e39 /routes
parent143490db49b6d67e9ddb2c59ea92ae923d08911c (diff)
downloadcoinos-server-f0543b6d94081f43a265bb9f754a654df9c4268a.tar.gz
coinos-server-f0543b6d94081f43a265bb9f754a654df9c4268a.zip
sample notify script
Diffstat (limited to 'routes')
-rw-r--r--routes/payments.js12
1 files changed, 8 insertions, 4 deletions
diff --git a/routes/payments.js b/routes/payments.js
index a060d90a..ca32e969 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -111,9 +111,12 @@ export default {
async take({ body: { name, amount }, user }, res) {
amount = parseInt(amount);
- await t(`pot:${name}`, async balance => {
+ await t(`pot:${name}`, async (balance, db) => {
if (balance < amount) fail("Insufficient funds");
- return balance - amount;
+ await db
+ .multi()
+ .decrBy(`pot:${name}`, amount)
+ .exec();
});
let hash = v4();
@@ -211,10 +214,11 @@ export default {
total = total - change + fee;
let amount = total - fee;
+ if (change && !amount) fail("Cannot send to unregistered coinos address");
+
await debit(txid, amount, fee, null, user, types.bitcoin, txid);
await bc.sendRawTransaction(hex);
res.send({ txid });
- },
-
+ }
};