2 Commits

Author SHA1 Message Date
Alexey
6bb265d3b9 fix: throw error if transaction execution was failed 2020-11-19 14:37:18 +03:00
Alexey
b940fad5e0 remove an anoying console.log 2020-10-30 11:56:24 +03:00
3 changed files with 9 additions and 3 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
node_modules node_modules
.env

View File

@@ -1,6 +1,6 @@
{ {
"name": "tx-manager", "name": "tx-manager",
"version": "0.2.3", "version": "0.2.5",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

View File

@@ -154,7 +154,6 @@ class Transaction {
this._emitter.emit('transactionHash', txHash) this._emitter.emit('transactionHash', txHash)
console.log(`Broadcasted transaction ${txHash}`) console.log(`Broadcasted transaction ${txHash}`)
console.log(this.tx)
} }
/** /**
@@ -176,6 +175,9 @@ class Transaction {
this.currentTxHash = null this.currentTxHash = null
continue continue
} }
if (Number(receipt.status) === 0) {
throw new Error('Transaction failed')
}
const currentBlock = await this._provider.getBlockNumber() const currentBlock = await this._provider.getBlockNumber()
const confirmations = Math.max(0, currentBlock - receipt.blockNumber) const confirmations = Math.max(0, currentBlock - receipt.blockNumber)
@@ -235,7 +237,10 @@ class Transaction {
} }
} }
console.log('Mined. Start waiting for confirmations...') if (Number(receipt.status) === 0) {
throw new Error('Transaction failed')
}
this._emitter.emit('mined', receipt) this._emitter.emit('mined', receipt)
this.currentTxHash = receipt.transactionHash this.currentTxHash = receipt.transactionHash
} }