Skip to content

Commit

Permalink
fix(wait-for-tx-confirm): validate transaction height after awaitHeight
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed May 21, 2021
1 parent e57b2ba commit 95e0d93
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/chain/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,16 @@ async function sendTransaction (tx, options = {}) {
async function waitForTxConfirm (txHash, options = { confirm: 3 }) {
options.confirm = options.confirm === true ? 3 : options.confirm
const { blockHeight } = await this.tx(txHash)
return this.awaitHeight(blockHeight + options.confirm, options)
const height = await this.awaitHeight(blockHeight + options.confirm, options)
const { blockHeight: newBlockHeight } = await this.tx(txHash)
switch (newBlockHeight) {
case -1:
throw new Error(`Transaction ${txHash} is removed from chain`)
case blockHeight:
return height
default:
return waitForTxConfirm(txHash, options)
}
}

async function getAccount (address, { height, hash } = {}) {
Expand Down

0 comments on commit 95e0d93

Please sign in to comment.