Skip to content

Commit

Permalink
fix: incomplete race condition solution for topwallet
Browse files Browse the repository at this point in the history
  • Loading branch information
sirpy committed Jul 21, 2019
1 parent 193fdd7 commit 12c82f1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/server/verification/verificationAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,17 @@ const setup = (app: Router, verifier: VerificationAPI, storage: StorageAPI) => {
const log = req.log.child({ from: 'verificationAPI - verify/topwallet' })
const user: LoggedUser = req.user
//allow topping once a day

storage.updateUser({ identifier: user.loggedInAs, lastTopWallet: new Date().toISOString() })
let txRes = await AdminWallet.topWallet(user.gdAddress, user.lastTopWallet)
.then(tx => {
log.debug('topping wallet tx', { walletaddress: user.gdAddress, tx })
storage.updateUser({ identifier: user.loggedInAs, lastTopWallet: new Date().toISOString() })
return { ok: 1 }
})
.catch(e => {
log.error('Failed top wallet tx', e.message, e.stack)
//restore last top wallet in case of error
storage.updateUser({ identifier: user.loggedInAs, lastTopWallet: user.lastTopWallet })

return { ok: -1, error: e.message }
})
log.info('topping wallet', { txRes, loggedInAs: user.loggedInAs, adminBalance: await AdminWallet.getBalance() })
Expand Down

0 comments on commit 12c82f1

Please sign in to comment.