diff --git a/ethers/provider.nim b/ethers/provider.nim index 6cc3058..dafa9ad 100644 --- a/ethers/provider.nim +++ b/ethers/provider.nim @@ -157,6 +157,9 @@ method subscribe*(provider: Provider, method unsubscribe*(subscription: Subscription) {.base, async.} = doAssert false, "not implemented" +method isSyncing*(provider: Provider): Future[bool] {.base, async.} = + doAssert false, "not implemented" + proc replay*(provider: Provider, tx: Transaction, blockNumber: UInt256) {.async.} = # Replay transaction at block. Useful for fetching revert reasons, which will # be present in the raised error message. The replayed block number should diff --git a/ethers/providers/jsonrpc.nim b/ethers/providers/jsonrpc.nim index 1784da0..d5f7e8c 100644 --- a/ethers/providers/jsonrpc.nim +++ b/ethers/providers/jsonrpc.nim @@ -222,6 +222,10 @@ method unsubscribe(subscription: JsonRpcSubscription) {.async.} = 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.} = convertError: let client = await provider.client diff --git a/testmodule/providers/jsonrpc/testJsonRpcProvider.nim b/testmodule/providers/jsonrpc/testJsonRpcProvider.nim index ee00acc..4fc9317 100644 --- a/testmodule/providers/jsonrpc/testJsonRpcProvider.nim +++ b/testmodule/providers/jsonrpc/testJsonRpcProvider.nim @@ -99,3 +99,8 @@ for url in ["ws://localhost:8545", "http://localhost:8545"]: discard await provider.subscribe(proc(_: Block) = discard) expect JsonRpcProviderError: discard await provider.getSigner().sendTransaction(Transaction.example) + + test "syncing": + let isSyncing = await provider.isSyncing() + check not isSyncing +