cancel transaction after estimateGas failure

This commit is contained in:
Eric 2023-09-27 17:44:16 +10:00
parent 7eac8410af
commit 9ffc1763e4
No known key found for this signature in database
3 changed files with 9 additions and 2 deletions

View File

@ -123,7 +123,7 @@ proc send(contract: Contract,
Future[?TransactionResponse] {.async.} = Future[?TransactionResponse] {.async.} =
if signer =? contract.signer: if signer =? contract.signer:
let transaction = createTransaction(contract, function, parameters, overrides) let transaction = createTransaction(contract, function, parameters, overrides)
let populated = await signer.populateTransaction(transaction) let populated = await signer.populateTransaction(transaction, cancelOnEstimateGasError = true)
let txResp = await signer.sendTransaction(populated) let txResp = await signer.sendTransaction(populated)
return txResp.some return txResp.some
else: else:

View File

@ -1,7 +1,12 @@
import ./basics import ./basics
import ./provider import ./provider
import pkg/chronicles
export basics export basics
export chronicles
logScope:
topics = "ethers signer"
type type
Signer* = ref object of RootObj Signer* = ref object of RootObj
@ -87,7 +92,8 @@ method decreaseNonce*(signer: Signer) {.base, gcsafe.} =
signer.lastSeenNonce = some lastSeen - 1 signer.lastSeenNonce = some lastSeen - 1
method populateTransaction*(signer: Signer, method populateTransaction*(signer: Signer,
transaction: Transaction): transaction: Transaction,
cancelOnEstimateGasError = false):
Future[Transaction] {.base, async.} = Future[Transaction] {.base, async.} =
if sender =? transaction.sender and sender != await signer.getAddress(): if sender =? transaction.sender and sender != await signer.getAddress():

View File

@ -9,6 +9,7 @@ import ./hardhat
import ./helpers import ./helpers
import ./miner import ./miner
import ./mocks import ./mocks
import ./examples
type type
TestToken = ref object of Erc20Token TestToken = ref object of Erc20Token