aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2021-01-13 14:21:47 -0800
committerAdam Soltys <[email protected]>2021-01-13 14:21:47 -0800
commiteb860d78b836d810f7c29d5587e17321adf20bef (patch)
tree437304e1ba62261af52146663a1ffe17339230c2 /lib
parent8afa3af7f790bd1d78b2105e7541eed462fbb825 (diff)
downloadcoinos-server-eb860d78b836d810f7c29d5587e17321adf20bef.tar.gz
coinos-server-eb860d78b836d810f7c29d5587e17321adf20bef.zip
add some more transaction locks
Diffstat (limited to 'lib')
-rw-r--r--lib/account.js32
1 files changed, 17 insertions, 15 deletions
diff --git a/lib/account.js b/lib/account.js
index 931638e0..5a8c3924 100644
--- a/lib/account.js
+++ b/lib/account.js
@@ -1,16 +1,15 @@
const axios = require("axios");
module.exports = async (asset, user, transaction) => {
- const account = await db.Account.findOne(
- {
- where: {
- user_id: user.id,
- asset,
- pubkey: null
- }
+ const account = await db.Account.findOne({
+ where: {
+ user_id: user.id,
+ asset,
+ pubkey: null
},
- { transaction }
- );
+ lock: transaction.LOCK.UPDATE,
+ transaction
+ });
if (account) return account;
@@ -28,13 +27,16 @@ module.exports = async (asset, user, transaction) => {
if (assets[asset]) {
({ domain, ticker, precision, name } = assets[asset]);
} else {
- const existing = await db.Account.findOne({
- where: {
- asset
+ const existing = await db.Account.findOne(
+ {
+ where: {
+ asset
+ },
+ order: [["id", "ASC"]],
+ limit: 1
},
- order: [["id", "ASC"]],
- limit: 1,
- }, { transaction });
+ { transaction }
+ );
if (existing) {
({ domain, ticker, precision, name } = existing);