mirror of
https://github.com/status-im/nim-ethers.git
synced 2025-01-12 00:24:54 +00:00
Provider.getBlockNumber()
This commit is contained in:
parent
bd20199f87
commit
7bc102a421
@ -7,6 +7,7 @@ requires "chronos >= 3.0.0 & < 4.0.0"
|
||||
requires "contractabi >= 0.4.0 & < 0.5.0"
|
||||
requires "questionable >= 0.10.2 & < 0.11.0"
|
||||
requires "json_rpc"
|
||||
requires "stint"
|
||||
requires "stew"
|
||||
|
||||
task test, "Run the test suite":
|
||||
|
@ -1,7 +1,9 @@
|
||||
import pkg/chronos
|
||||
import pkg/questionable
|
||||
import pkg/stint
|
||||
import ./address
|
||||
|
||||
export chronos
|
||||
export address
|
||||
export questionable
|
||||
export stint
|
||||
|
@ -1,2 +1,9 @@
|
||||
import ./basics
|
||||
|
||||
export basics
|
||||
|
||||
type
|
||||
Provider* = ref object of RootObj
|
||||
|
||||
method getBlockNumber*(provider: Provider): Future[UInt256] {.base.} =
|
||||
doAssert false, "not implemented"
|
||||
|
@ -35,3 +35,7 @@ proc send*(provider: JsonRpcProvider,
|
||||
proc listAccounts*(provider: JsonRpcProvider): Future[seq[Address]] {.async.} =
|
||||
let client = await provider.client
|
||||
return await client.eth_accounts()
|
||||
|
||||
method getBlockNumber*(provider: JsonRpcProvider): Future[UInt256] {.async.} =
|
||||
let client = await provider.client
|
||||
return await client.eth_blockNumber()
|
||||
|
@ -1,11 +1,21 @@
|
||||
import std/json
|
||||
import ../../basics
|
||||
|
||||
# Address
|
||||
|
||||
func `%`*(address: Address): JsonNode =
|
||||
%($address)
|
||||
|
||||
func fromJson*(json: JsonNode, argname: string, result: var Address) =
|
||||
func fromJson*(json: JsonNode, name: string, result: var Address) =
|
||||
if address =? Address.init(json.getStr()):
|
||||
result = address
|
||||
else:
|
||||
raise newException(ValueError, "\"" & argname & "\"is not an Address")
|
||||
raise newException(ValueError, "\"" & name & "\"is not an Address")
|
||||
|
||||
# UInt256
|
||||
|
||||
func `%`*(integer: UInt256): JsonNode =
|
||||
%toHex(integer)
|
||||
|
||||
func fromJson*(json: JsonNode, name: string, result: var UInt256) =
|
||||
result = UInt256.fromHex(json.getStr())
|
||||
|
@ -1 +1,2 @@
|
||||
proc eth_accounts: seq[Address]
|
||||
proc eth_blockNumber: UInt256
|
||||
|
@ -26,3 +26,9 @@ suite "JsonRpcProvider":
|
||||
test "sends raw messages to the provider":
|
||||
let response = await provider.send("evm_mine")
|
||||
check response == %"0x0"
|
||||
|
||||
test "returns block number":
|
||||
let blocknumber1 = await provider.getBlockNumber()
|
||||
discard await provider.send("evm_mine")
|
||||
let blocknumber2 = await provider.getBlockNumber()
|
||||
check blocknumber2 > blocknumber1
|
||||
|
Loading…
x
Reference in New Issue
Block a user