Send raw messages to the provider

This commit is contained in:
Mark Spanbroek 2022-01-18 14:24:46 +01:00
parent 8dd84b0622
commit bd20199f87
2 changed files with 11 additions and 0 deletions

View File

@ -26,6 +26,12 @@ proc connect(_: type RpcClient, url: string): Future[RpcClient] {.async.} =
proc new*(_: type JsonRpcProvider, url=defaultUrl): JsonRpcProvider = proc new*(_: type JsonRpcProvider, url=defaultUrl): JsonRpcProvider =
JsonRpcProvider(client: RpcClient.connect(url)) JsonRpcProvider(client: RpcClient.connect(url))
proc send*(provider: JsonRpcProvider,
call: string,
arguments = %(@[])): Future[JsonNode] {.async.} =
let client = await provider.client
return await client.call(call, arguments)
proc listAccounts*(provider: JsonRpcProvider): Future[seq[Address]] {.async.} = proc listAccounts*(provider: JsonRpcProvider): Future[seq[Address]] {.async.} =
let client = await provider.client let client = await provider.client
return await client.eth_accounts() return await client.eth_accounts()

View File

@ -1,3 +1,4 @@
import std/json
import pkg/asynctest import pkg/asynctest
import pkg/chronos import pkg/chronos
import pkg/ethers/providers/jsonrpc import pkg/ethers/providers/jsonrpc
@ -21,3 +22,7 @@ suite "JsonRpcProvider":
test "lists all accounts": test "lists all accounts":
let accounts = await provider.listAccounts() let accounts = await provider.listAccounts()
check accounts.len > 0 check accounts.len > 0
test "sends raw messages to the provider":
let response = await provider.send("evm_mine")
check response == %"0x0"