diff --git a/ethers/provider.nim b/ethers/provider.nim index c285cdb..6050943 100644 --- a/ethers/provider.nim +++ b/ethers/provider.nim @@ -19,10 +19,17 @@ type topics*: seq[Topic] LogHandler* = proc(log: Log) {.gcsafe, upraises:[].} Topic* = array[32, byte] + Block* = object + number*: UInt256 + timestamp*: UInt256 + hash*: array[32, byte] method getBlockNumber*(provider: Provider): Future[UInt256] {.base.} = doAssert false, "not implemented" +method getBlock*(provider: Provider, tag: BlockTag): Future[Block] {.base.} = + doAssert false, "not implemented" + method call*(provider: Provider, tx: Transaction): Future[seq[byte]] {.base.} = doAssert false, "not implemented" diff --git a/ethers/providers/jsonrpc.nim b/ethers/providers/jsonrpc.nim index 8326b31..097216a 100644 --- a/ethers/providers/jsonrpc.nim +++ b/ethers/providers/jsonrpc.nim @@ -70,6 +70,11 @@ method getBlockNumber*(provider: JsonRpcProvider): Future[UInt256] {.async.} = let client = await provider.client return await client.eth_blockNumber() +method getBlock*(provider: JsonRpcProvider, + tag: BlockTag): Future[?Block] {.async.} = + let client = await provider.client + return await client.eth_getBlockByNumber(tag, false) + method call*(provider: JsonRpcProvider, tx: Transaction): Future[seq[byte]] {.async.} = let client = await provider.client diff --git a/ethers/providers/jsonrpc/signatures.nim b/ethers/providers/jsonrpc/signatures.nim index e882b40..7f50b80 100644 --- a/ethers/providers/jsonrpc/signatures.nim +++ b/ethers/providers/jsonrpc/signatures.nim @@ -3,6 +3,7 @@ proc eth_accounts: seq[Address] proc eth_blockNumber: UInt256 proc eth_call(transaction: Transaction): seq[byte] proc eth_gasPrice(): UInt256 +proc eth_getBlockByNumber(blockTag: BlockTag, includeTransactions: bool): ?Block proc eth_getTransactionCount(address: Address, blockTag: BlockTag): UInt256 proc eth_estimateGas(transaction: Transaction): UInt256 proc eth_chainId(): UInt256 diff --git a/testmodule/testJsonRpcProvider.nim b/testmodule/testJsonRpcProvider.nim index 10c41c4..756d1d7 100644 --- a/testmodule/testJsonRpcProvider.nim +++ b/testmodule/testJsonRpcProvider.nim @@ -32,3 +32,10 @@ suite "JsonRpcProvider": discard await provider.send("evm_mine") let blocknumber2 = await provider.getBlockNumber() check blocknumber2 > blocknumber1 + + test "returns block": + let block1 = !await provider.getBlock(BlockTag.earliest) + let block2 = !await provider.getBlock(BlockTag.latest) + check block1.hash != block2.hash + check block1.number < block2.number + check block1.timestamp < block2.timestamp