supply block parameter to eth_call, default being BlockTag.latest

This commit is contained in:
Michael Bradley, Jr 2022-04-10 15:21:59 -05:00 committed by markspanbroek
parent ac74b91f11
commit 073924d3f5
4 changed files with 15 additions and 8 deletions

View File

@ -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.} =

View File

@ -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.} =

View File

@ -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

View File

@ -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