Use Address type in RPC call signature

This commit is contained in:
Mark Spanbroek 2022-01-18 12:42:58 +01:00
parent 97d509571e
commit 8dd84b0622
4 changed files with 14 additions and 6 deletions

View File

@ -28,8 +28,4 @@ proc new*(_: type JsonRpcProvider, url=defaultUrl): JsonRpcProvider =
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
var addresses: seq[Address] return await client.eth_accounts()
for address in await client.eth_accounts():
if address =? Address.init(address):
addresses.add(address)
return addresses

View File

@ -1,6 +1,7 @@
import std/os import std/os
import pkg/json_rpc/rpcclient import pkg/json_rpc/rpcclient
import ../basics import ../basics
import ./rpccalls/conversions
const file = currentSourcePath.parentDir / "rpccalls" / "signatures.nim" const file = currentSourcePath.parentDir / "rpccalls" / "signatures.nim"

View File

@ -0,0 +1,11 @@
import std/json
import ../../basics
func `%`*(address: Address): JsonNode =
%($address)
func fromJson*(json: JsonNode, argname: string, result: var Address) =
if address =? Address.init(json.getStr()):
result = address
else:
raise newException(ValueError, "\"" & argname & "\"is not an Address")

View File

@ -1 +1 @@
proc eth_accounts: seq[string] proc eth_accounts: seq[Address]