diff options
| author | Adam Soltys <[email protected]> | 2022-05-31 10:22:17 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-05-31 10:23:39 -0700 |
| commit | 2200e185f7099defdad3e510e7f74c84017d833b (patch) | |
| tree | 216153cab69650ad8e3fcb2929ab4ad5bb839ac2 | |
| parent | bfe6091feeabdb9562250cf0544863bc4f035c09 (diff) | |
| download | coinos-server-2200e185f7099defdad3e510e7f74c84017d833b.tar.gz coinos-server-2200e185f7099defdad3e510e7f74c84017d833b.zip | |
create payment record for withdrawal fee
| -rw-r--r-- | routes/bitcoin/send.js | 30 | ||||
| -rw-r--r-- | routes/users.js | 2 |
2 files changed, 22 insertions, 10 deletions
diff --git a/routes/bitcoin/send.js b/routes/bitcoin/send.js index 326518a0..51962367 100644 --- a/routes/bitcoin/send.js +++ b/routes/bitcoin/send.js @@ -19,9 +19,6 @@ module.exports = ah(async (req, res) => { let total = 0; let change = 0; - console.log("tx.vout is "); - console.log(tx.vout); - for (let i = 0; i < tx.vout.length; i++) { let o = tx.vout[i]; total += toSats(o.value); @@ -63,9 +60,6 @@ module.exports = ah(async (req, res) => { }); } - console.log("Account balance is " + account.balance); - console.log("Total is " + total); - if (total > account.balance) { l.error("amount exceeds balance", amount, fee, account.balance); throw new Error("low balance"); @@ -82,14 +76,32 @@ module.exports = ah(async (req, res) => { await db.transaction(async transaction => { let receiverAccount = await db.Account.findOne({ where: { - username: withdrawalFeeReceiver + "$user.username$": withdrawalFeeReceiver }, + include: [ + { + model: db.User, + as: "user" + }, + ], lock: transaction.LOCK.UPDATE, transaction }); - await account.increment({ balance: withdrawalFee }, { transaction }); - await account.reload({ transaction }); + await receiverAccount.increment({ balance: withdrawalFee }, { transaction }); + await receiverAccount.reload({ transaction }); + await db.Payment.create({ + amount: withdrawalFee, + fee: 0, + memo: "Bitcoin withdrawal fee", + account_id: receiverAccount.id, + user_id: receiverAccount.user_id, + rate: app.get("rates")[receiverAccount.user.currency], + currency: receiverAccount.user.currency, + confirmed: true, + received: true, + network: "COINOS" + }); }); // record the external bitcoin transaction diff --git a/routes/users.js b/routes/users.js index 549de828..6bf9a063 100644 --- a/routes/users.js +++ b/routes/users.js @@ -365,7 +365,7 @@ app.post( ); app.post( - "/taboggan", + "/doggin", ah(async (req, res) => { try { const { params, sig, key } = req.body; |
