diff options
| author | Adam Soltys <[email protected]> | 2019-10-14 23:41:20 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2019-10-14 23:41:20 -0700 |
| commit | a3ae613d7e2cde43096dcd80f8a1e04a7fb2512f (patch) | |
| tree | b6a78851f106c9cf4849f140e5954da511588086 /sendCoins.js | |
| parent | 7c77d82d6bb52662b98461c67b7240182ded8002 (diff) | |
| download | coinos-server-a3ae613d7e2cde43096dcd80f8a1e04a7fb2512f.tar.gz coinos-server-a3ae613d7e2cde43096dcd80f8a1e04a7fb2512f.zip | |
use database transaction when updating balance on block receipt
Diffstat (limited to 'sendCoins.js')
| -rw-r--r-- | sendCoins.js | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/sendCoins.js b/sendCoins.js index 7eebdc8a..997af0dd 100644 --- a/sendCoins.js +++ b/sendCoins.js @@ -24,14 +24,13 @@ module.exports = (app, bc, db, emit) => async (req, res) => { try { await db.transaction(async transaction => { - let { balance } = await db.User.findOne( - { - where: { - username: req.user.username - } + let { balance } = await db.User.findOne({ + where: { + username: req.user.username }, - { transaction } - ); + lock: transaction.LOCK.UPDATE, + transaction + }); if (amount !== balance && amount + fee > balance) { l("amount exceeds balance", amount, fee, balance); |
