|
|
|
@@ -4,21 +4,23 @@ const BigNumber = ethers.BigNumber
|
|
|
|
const PromiEvent = require('web3-core-promievent')
|
|
|
|
const PromiEvent = require('web3-core-promievent')
|
|
|
|
const { sleep, min, max } = require('./utils')
|
|
|
|
const { sleep, min, max } = require('./utils')
|
|
|
|
|
|
|
|
|
|
|
|
// prettier-ignore
|
|
|
|
|
|
|
|
const nonceErrors = [
|
|
|
|
const nonceErrors = [
|
|
|
|
'Transaction nonce is too low. Try incrementing the nonce.',
|
|
|
|
'Transaction nonce is too low. Try incrementing the nonce.',
|
|
|
|
'nonce too low'
|
|
|
|
'nonce too low',
|
|
|
|
|
|
|
|
'nonce has already been used',
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
const gasPriceErrors = [
|
|
|
|
const gasPriceErrors = [
|
|
|
|
'Transaction gas price supplied is too low. There is another transaction with same nonce in the queue. Try increasing the gas price or incrementing the nonce.',
|
|
|
|
'Transaction gas price supplied is too low. There is another transaction with same nonce in the queue. Try increasing the gas price or incrementing the nonce.',
|
|
|
|
'replacement transaction underpriced',
|
|
|
|
'replacement transaction underpriced',
|
|
|
|
|
|
|
|
'transaction underpriced',
|
|
|
|
/Transaction gas price \d+wei is too low. There is another transaction with same nonce in the queue with gas price: \d+wei. Try increasing the gas price or incrementing the nonce./,
|
|
|
|
/Transaction gas price \d+wei is too low. There is another transaction with same nonce in the queue with gas price: \d+wei. Try increasing the gas price or incrementing the nonce./,
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
// prettier-ignore
|
|
|
|
// prettier-ignore
|
|
|
|
const sameTxErrors = [
|
|
|
|
const sameTxErrors = [
|
|
|
|
'Transaction with the same hash was already imported.',
|
|
|
|
'Transaction with the same hash was already imported.',
|
|
|
|
|
|
|
|
'already known',
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class Transaction {
|
|
|
|
class Transaction {
|
|
|
|
@@ -182,6 +184,9 @@ class Transaction {
|
|
|
|
this._emitter.emit('confirmations', confirmations)
|
|
|
|
this._emitter.emit('confirmations', confirmations)
|
|
|
|
if (confirmations >= this.config.CONFIRMATIONS) {
|
|
|
|
if (confirmations >= this.config.CONFIRMATIONS) {
|
|
|
|
// Tx is mined and has enough confirmations
|
|
|
|
// Tx is mined and has enough confirmations
|
|
|
|
|
|
|
|
if (this.config.THROW_ON_REVERT && Number(receipt.status) === 0) {
|
|
|
|
|
|
|
|
throw new Error('EVM execution failed, so the transaction was reverted.')
|
|
|
|
|
|
|
|
}
|
|
|
|
return receipt
|
|
|
|
return receipt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -234,7 +239,6 @@ class Transaction {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
console.log('Mined. Start waiting for confirmations...')
|
|
|
|
|
|
|
|
this._emitter.emit('mined', receipt)
|
|
|
|
this._emitter.emit('mined', receipt)
|
|
|
|
this.currentTxHash = receipt.transactionHash
|
|
|
|
this.currentTxHash = receipt.transactionHash
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -266,11 +270,13 @@ class Transaction {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_handleSendError(e) {
|
|
|
|
_handleSendError(e) {
|
|
|
|
console.log('Got error', e)
|
|
|
|
if (e.error.error) {
|
|
|
|
|
|
|
|
// Sometimes ethers wraps known errors, unwrap it in this case
|
|
|
|
|
|
|
|
e = e.error
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (e.code === 'SERVER_ERROR' && e.error) {
|
|
|
|
if (e.error && e.code === 'SERVER_ERROR') {
|
|
|
|
const message = e.error.message
|
|
|
|
const message = e.error.message
|
|
|
|
console.log('Error', e.error.code, e.error.message)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// nonce is too low, trying to increase and resubmit
|
|
|
|
// nonce is too low, trying to increase and resubmit
|
|
|
|
if (this._hasError(message, nonceErrors)) {
|
|
|
|
if (this._hasError(message, nonceErrors)) {
|
|
|
|
|