Skip to content

Commit

Permalink
add: sync nonce in case of errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sirpy committed Jun 5, 2019
1 parent 93f16a0 commit e0f4ec8
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/server/blockchain/AdminWallet.js
Expand Up @@ -146,6 +146,15 @@ export class Wallet {
network: this.networkId,
nonce: this.nonce
})
//resync nonce
setInterval(async () => {
let release = await this.mutex.lock()
this.nonce = await this.web3.eth
.getTransactionCount(this.address)
.then(parseInt)
.catch(e => this.nonce)
.finally(() => release())
}, 30000)
} catch (e) {
log.error('Error initializing wallet', { e }, e.message)
}
Expand Down Expand Up @@ -264,8 +273,12 @@ export class Wallet {
res(r)
})
.on('confirmation', c => onConfirmation && onConfirmation(c))
.on('error', e => {
release()
.on('error', async e => {
this.nonce = await this.web3.eth
.getTransactionCount(this.address)
.then(parseInt)
.catch(e => this.nonce)
.finally(() => release())
onError && onError(e)
rej(e)
})
Expand Down Expand Up @@ -310,8 +323,12 @@ export class Wallet {
res(r)
})
.on('confirmation', c => onConfirmation && onConfirmation(c))
.on('error', e => {
release()
.on('error', async e => {
this.nonce = await this.web3.eth
.getTransactionCount(this.address)
.then(parseInt)
.catch(e => this.nonce)
.finally(() => release())
onError && onError(e)
rej(e)
})
Expand Down

0 comments on commit e0f4ec8

Please sign in to comment.