From e40e68f49b10d6ef70546f7128bad891256525c0 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 7 Sep 2020 20:04:33 -0700 Subject: multiple same-asset accounts --- routes/bitcoin/send.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'routes/bitcoin') diff --git a/routes/bitcoin/send.js b/routes/bitcoin/send.js index 5e52b7ed..8745c3dd 100644 --- a/routes/bitcoin/send.js +++ b/routes/bitcoin/send.js @@ -9,7 +9,7 @@ module.exports = ah(async (req, res) => { const isChange = async address => (await bc.getAddressInfo(address)).ismine && - (!Object.keys(addresses).includes(address)); + !Object.keys(addresses).includes(address); tx = await bc.decodeRawTransaction(hex); @@ -30,17 +30,20 @@ module.exports = ah(async (req, res) => { total = total - change + fee; let amount = total - fee; - let account, params; + let { account } = user; + let params; try { await db.transaction(async transaction => { - account = await db.Account.findOne({ - where: { - user_id: user.id, - asset: config.liquid.btcasset - }, - lock: transaction.LOCK.UPDATE, - transaction - }); + if (account.asset !== btcasset) { + account = await db.Account.findOne({ + where: { + user_id: user.id, + asset: config.liquid.btcasset + }, + lock: transaction.LOCK.UPDATE, + transaction + }); + } if (total > account.balance) { l.error("amount exceeds balance", amount, fee, account.balance); -- cgit v1.2.3