From 083af80dcc3379a2e464519dc77f4f6da508d988 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Tue, 12 Jul 2022 12:43:56 +0200 Subject: [PATCH] Introduce separate type for transaction overrides --- ethers/contract.nim | 22 +++++++++++++++------- testmodule/testContracts.nim | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/ethers/contract.nim b/ethers/contract.nim index f7bbc55..15673f8 100644 --- a/ethers/contract.nim +++ b/ethers/contract.nim @@ -16,6 +16,11 @@ type provider: Provider signer: ?Signer address: Address + TransactionOverrides* = object + nonce*: ?UInt256 + gasPrice*: ?UInt256 + gasLimit*: ?UInt256 + ContractError* = object of EthersError Confirmable* = ?TransactionResponse EventHandler*[E: Event] = proc(event: E) {.gcsafe, upraises:[].} @@ -48,13 +53,16 @@ template raiseContractError(message: string) = proc createTransaction(contract: Contract, function: string, parameters: tuple, - overrides = Transaction.default): Transaction = + overrides = TransactionOverrides.default): Transaction = let selector = selector(function, typeof parameters).toArray let data = @selector & AbiEncoder.encode(parameters) - var transaction = overrides - transaction.to = contract.address - transaction.data = data - return transaction + Transaction( + to: contract.address, + data: data, + gasPrice: overrides.gasPrice, + gasLimit: overrides.gasLimit, + nonce: overrides.nonce + ) proc decodeResponse(T: type, multiple: static bool, bytes: seq[byte]): T = when multiple: @@ -84,7 +92,7 @@ proc call(contract: Contract, proc send(contract: Contract, function: string, parameters: tuple, - overrides = Transaction.default): + overrides = TransactionOverrides.default): Future[?TransactionResponse] {.async.} = if signer =? contract.signer: let transaction = createTransaction(contract, function, parameters, overrides) @@ -122,7 +130,7 @@ func addOverrides(procedure: var NimNode) = newIdentDefs( ident("overrides"), newEmptyNode(), - quote do: Transaction.default + quote do: TransactionOverrides.default ) ) diff --git a/testmodule/testContracts.nim b/testmodule/testContracts.nim index 05e0c2d..20c1ec5 100644 --- a/testmodule/testContracts.nim +++ b/testmodule/testContracts.nim @@ -114,7 +114,7 @@ suite "Contracts": check (await token.connect(provider).balanceOf(accounts[2])) == 25.u256 test "takes custom values for nonce, gasprice and gaslimit": - let overrides = Transaction( + let overrides = TransactionOverrides( nonce: some 100.u256, gasPrice: some 200.u256, gasLimit: some 300.u256