From 073924d3f5a11142d50508cc4e72eb7a659e52b8 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Sun, 10 Apr 2022 15:21:59 -0500 Subject: [PATCH] supply block parameter to eth_call, default being BlockTag.latest --- ethers/contract.nim | 12 ++++++++---- ethers/provider.nim | 4 +++- ethers/providers/jsonrpc.nim | 5 +++-- ethers/providers/jsonrpc/signatures.nim | 2 +- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ethers/contract.nim b/ethers/contract.nim index 6bf0ce6..799a994 100644 --- a/ethers/contract.nim +++ b/ethers/contract.nim @@ -56,16 +56,20 @@ proc decodeResponse(T: type, bytes: seq[byte]): T = raiseContractError "unable to decode return value as " & $T return decoded -proc call(contract: Contract, function: string, parameters: tuple) {.async.} = +proc call(contract: Contract, + function: string, + parameters: tuple, + blockTag = BlockTag.latest) {.async.} = let transaction = createTransaction(contract, function, parameters) - discard await contract.provider.call(transaction) + discard await contract.provider.call(transaction, blockTag) proc call(contract: Contract, function: string, parameters: tuple, - ReturnType: type): Future[ReturnType] {.async.} = + ReturnType: type, + blockTag = BlockTag.latest): Future[ReturnType] {.async.} = let transaction = createTransaction(contract, function, parameters) - let response = await contract.provider.call(transaction) + let response = await contract.provider.call(transaction, blockTag) return decodeResponse(ReturnType, response) proc send(contract: Contract, function: string, parameters: tuple) {.async.} = diff --git a/ethers/provider.nim b/ethers/provider.nim index 2a8badf..1aa21ce 100644 --- a/ethers/provider.nim +++ b/ethers/provider.nim @@ -30,7 +30,9 @@ method getBlockNumber*(provider: Provider): Future[UInt256] {.base.} = method getBlock*(provider: Provider, tag: BlockTag): Future[?Block] {.base.} = doAssert false, "not implemented" -method call*(provider: Provider, tx: Transaction): Future[seq[byte]] {.base.} = +method call*(provider: Provider, + tx: Transaction, + blockTag = BlockTag.latest): Future[seq[byte]] {.base.} = doAssert false, "not implemented" method getGasPrice*(provider: Provider): Future[UInt256] {.base.} = diff --git a/ethers/providers/jsonrpc.nim b/ethers/providers/jsonrpc.nim index b9e26ab..f33df34 100644 --- a/ethers/providers/jsonrpc.nim +++ b/ethers/providers/jsonrpc.nim @@ -77,9 +77,10 @@ method getBlock*(provider: JsonRpcProvider, return await client.eth_getBlockByNumber(tag, false) method call*(provider: JsonRpcProvider, - tx: Transaction): Future[seq[byte]] {.async.} = + tx: Transaction, + blockTag = BlockTag.latest): Future[seq[byte]] {.async.} = let client = await provider.client - return await client.eth_call(tx) + return await client.eth_call(tx, blockTag) method getGasPrice*(provider: JsonRpcProvider): Future[UInt256] {.async.} = let client = await provider.client diff --git a/ethers/providers/jsonrpc/signatures.nim b/ethers/providers/jsonrpc/signatures.nim index 7f50b80..7ce1af7 100644 --- a/ethers/providers/jsonrpc/signatures.nim +++ b/ethers/providers/jsonrpc/signatures.nim @@ -1,7 +1,7 @@ proc net_version(): string proc eth_accounts: seq[Address] proc eth_blockNumber: UInt256 -proc eth_call(transaction: Transaction): seq[byte] +proc eth_call(transaction: Transaction, blockTag: BlockTag): seq[byte] proc eth_gasPrice(): UInt256 proc eth_getBlockByNumber(blockTag: BlockTag, includeTransactions: bool): ?Block proc eth_getTransactionCount(address: Address, blockTag: BlockTag): UInt256