Add Provider.getBlock()
Only returns hash, number and timestamp for now.
This commit is contained in:
parent
5cc1f4b71d
commit
ce435f8791
|
@ -19,10 +19,17 @@ type
|
||||||
topics*: seq[Topic]
|
topics*: seq[Topic]
|
||||||
LogHandler* = proc(log: Log) {.gcsafe, upraises:[].}
|
LogHandler* = proc(log: Log) {.gcsafe, upraises:[].}
|
||||||
Topic* = array[32, byte]
|
Topic* = array[32, byte]
|
||||||
|
Block* = object
|
||||||
|
number*: UInt256
|
||||||
|
timestamp*: UInt256
|
||||||
|
hash*: array[32, byte]
|
||||||
|
|
||||||
method getBlockNumber*(provider: Provider): Future[UInt256] {.base.} =
|
method getBlockNumber*(provider: Provider): Future[UInt256] {.base.} =
|
||||||
doAssert false, "not implemented"
|
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.} =
|
method call*(provider: Provider, tx: Transaction): Future[seq[byte]] {.base.} =
|
||||||
doAssert false, "not implemented"
|
doAssert false, "not implemented"
|
||||||
|
|
||||||
|
|
|
@ -70,6 +70,11 @@ method getBlockNumber*(provider: JsonRpcProvider): Future[UInt256] {.async.} =
|
||||||
let client = await provider.client
|
let client = await provider.client
|
||||||
return await client.eth_blockNumber()
|
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,
|
method call*(provider: JsonRpcProvider,
|
||||||
tx: Transaction): Future[seq[byte]] {.async.} =
|
tx: Transaction): Future[seq[byte]] {.async.} =
|
||||||
let client = await provider.client
|
let client = await provider.client
|
||||||
|
|
|
@ -3,6 +3,7 @@ proc eth_accounts: seq[Address]
|
||||||
proc eth_blockNumber: UInt256
|
proc eth_blockNumber: UInt256
|
||||||
proc eth_call(transaction: Transaction): seq[byte]
|
proc eth_call(transaction: Transaction): seq[byte]
|
||||||
proc eth_gasPrice(): UInt256
|
proc eth_gasPrice(): UInt256
|
||||||
|
proc eth_getBlockByNumber(blockTag: BlockTag, includeTransactions: bool): ?Block
|
||||||
proc eth_getTransactionCount(address: Address, blockTag: BlockTag): UInt256
|
proc eth_getTransactionCount(address: Address, blockTag: BlockTag): UInt256
|
||||||
proc eth_estimateGas(transaction: Transaction): UInt256
|
proc eth_estimateGas(transaction: Transaction): UInt256
|
||||||
proc eth_chainId(): UInt256
|
proc eth_chainId(): UInt256
|
||||||
|
|
|
@ -32,3 +32,10 @@ suite "JsonRpcProvider":
|
||||||
discard await provider.send("evm_mine")
|
discard await provider.send("evm_mine")
|
||||||
let blocknumber2 = await provider.getBlockNumber()
|
let blocknumber2 = await provider.getBlockNumber()
|
||||||
check blocknumber2 > blocknumber1
|
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
|
||||||
|
|
Loading…
Reference in New Issue