Adds isSyncing to provider (#62)

This commit is contained in:
Ben Bierens 2024-02-20 16:25:23 +01:00 committed by Mark Spanbroek
parent fd16d71ea5
commit 67ab667284
3 changed files with 12 additions and 0 deletions

View File

@ -157,6 +157,9 @@ method subscribe*(provider: Provider,
method unsubscribe*(subscription: Subscription) {.base, async.} = method unsubscribe*(subscription: Subscription) {.base, async.} =
doAssert false, "not implemented" 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.} = proc replay*(provider: Provider, tx: Transaction, blockNumber: UInt256) {.async.} =
# Replay transaction at block. Useful for fetching revert reasons, which will # Replay transaction at block. Useful for fetching revert reasons, which will
# be present in the raised error message. The replayed block number should # be present in the raised error message. The replayed block number should

View File

@ -222,6 +222,10 @@ method unsubscribe(subscription: JsonRpcSubscription) {.async.} =
let id = subscription.id let id = subscription.id
await subscriptions.unsubscribe(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.} = method close*(provider: JsonRpcProvider) {.async.} =
convertError: convertError:
let client = await provider.client let client = await provider.client

View File

@ -99,3 +99,8 @@ for url in ["ws://localhost:8545", "http://localhost:8545"]:
discard await provider.subscribe(proc(_: Block) = discard) discard await provider.subscribe(proc(_: Block) = discard)
expect JsonRpcProviderError: expect JsonRpcProviderError:
discard await provider.getSigner().sendTransaction(Transaction.example) discard await provider.getSigner().sendTransaction(Transaction.example)
test "syncing":
let isSyncing = await provider.isSyncing()
check not isSyncing