diff options
| author | Adam Soltys <[email protected]> | 2021-01-15 15:31:46 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2021-01-15 15:31:46 -0800 |
| commit | d01159ce9eee956dca32fd69525c0edd5aae9477 (patch) | |
| tree | e6a4d4a928daffb5bcedbc3411a0dfded6ff422f /routes/liquid/send.js | |
| parent | d03dad4d85ccd107068719c4b68cbd6a255864f6 (diff) | |
| download | coinos-server-d01159ce9eee956dca32fd69525c0edd5aae9477.tar.gz coinos-server-d01159ce9eee956dca32fd69525c0edd5aae9477.zip | |
add more transactions and locks
Diffstat (limited to 'routes/liquid/send.js')
| -rw-r--r-- | routes/liquid/send.js | 22 |
1 files changed, 10 insertions, 12 deletions
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); |
