From d01159ce9eee956dca32fd69525c0edd5aae9477 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 15 Jan 2021 15:31:46 -0800 Subject: add more transactions and locks --- routes/liquid/send.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'routes/liquid/send.js') diff --git a/routes/liquid/send.js b/routes/liquid/send.js index a04bc007..04b90814 100644 --- a/routes/liquid/send.js +++ b/routes/liquid/send.js @@ -54,13 +54,16 @@ module.exports = ah(async (req, res) => { where: { asset: nonbtc[0], user_id: null - } + }, + lock: transaction.LOCK.UPDATE, + transaction }); if (faucet) { covered = faucet.balance; if (covered > fee) covered = fee; - faucet.balance -= covered; + await faucet.decrement({ balance: covered }, { transaction }); + await faucet.reload({ transaction }); await faucet.save({ transaction }); } @@ -88,12 +91,14 @@ module.exports = ah(async (req, res) => { balance: account.balance }); throw new Error( - `Insufficient funds, need ${total} ${account.ticker === 'BTC' ? 'SAT' : account.ticker}, have ${account.balance}` + `Insufficient funds, need ${total} ${ + account.ticker === "BTC" ? "SAT" : account.ticker + }, have ${account.balance}` ); } - account.balance -= total; - await account.save({ transaction }); + await account.decrement({ balance: total }, { transaction }); + await account.reload({ transaction }); let payment = { amount: -amount, @@ -113,14 +118,7 @@ module.exports = ah(async (req, res) => { payments.push(payment); } } - }); - } catch (e) { - l.error("problem creating liquid payment", user.username, e.message); - return res.status(500).send(e.message); - } - try { - await db.transaction(async transaction => { if (config.liquid.walletpass) await lq.walletPassphrase(config.liquid.walletpass, 300); -- cgit v1.2.3