From e8196b3c8278d0e8752465e4da91352b4c5dd82f Mon Sep 17 00:00:00 2001 From: Ben Bierens <39762930+benbierens@users.noreply.github.com> Date: Tue, 20 Feb 2024 16:25:23 +0100 Subject: [PATCH] Adds isSyncing to provider (#62) --- ethers/provider.nim | 3 +++ ethers/providers/jsonrpc.nim | 4 ++++ testmodule/providers/jsonrpc/testJsonRpcProvider.nim | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/ethers/provider.nim b/ethers/provider.nim index 1bf2363..068439c 100644 --- a/ethers/provider.nim +++ b/ethers/provider.nim @@ -182,6 +182,9 @@ method unsubscribe*( doAssert false, "not implemented" +method isSyncing*(provider: Provider): Future[bool] {.base, async.} = + doAssert false, "not implemented" + proc replay*( provider: Provider, tx: Transaction, diff --git a/ethers/providers/jsonrpc.nim b/ethers/providers/jsonrpc.nim index 729bec5..95cca3f 100644 --- a/ethers/providers/jsonrpc.nim +++ b/ethers/providers/jsonrpc.nim @@ -268,6 +268,10 @@ method unsubscribe*( let id = subscription.id await subscriptions.unsubscribe(id) +method isSyncing*(provider: JsonRpcProvider): Future[bool] {.async.} = + let response = await provider.send("eth_syncing") + return response.getBool() + method close*( provider: JsonRpcProvider) {.async: (raises:[ProviderError]).} = diff --git a/testmodule/providers/jsonrpc/testJsonRpcProvider.nim b/testmodule/providers/jsonrpc/testJsonRpcProvider.nim index ccfc5e7..ec4fb8c 100644 --- a/testmodule/providers/jsonrpc/testJsonRpcProvider.nim +++ b/testmodule/providers/jsonrpc/testJsonRpcProvider.nim @@ -98,3 +98,8 @@ for url in ["ws://localhost:8545", "http://localhost:8545"]: discard await provider.subscribe(proc(_: Block) = discard) expect JsonRpcSignerError: discard await provider.getSigner().sendTransaction(Transaction.example) + + test "syncing": + let isSyncing = await provider.isSyncing() + check not isSyncing +