From 1b151d589d788b0bf1c6f00b6ae82b6e55582308 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Tue, 27 Jun 2023 15:08:37 +0200 Subject: [PATCH] Add polling interval to constructor of provider --- ethers/providers/jsonrpc.nim | 8 ++++++-- testmodule/providers/jsonrpc/testJsonRpcProvider.nim | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ethers/providers/jsonrpc.nim b/ethers/providers/jsonrpc.nim index c33956a..559a4cb 100644 --- a/ethers/providers/jsonrpc.nim +++ b/ethers/providers/jsonrpc.nim @@ -47,11 +47,14 @@ template convertError(body) = # Provider const defaultUrl = "http://localhost:8545" +const defaultPollingInterval = 4.seconds proc jsonHeaders: seq[(string, string)] = @[("Content-Type", "application/json")] -proc new*(_: type JsonRpcProvider, url=defaultUrl): JsonRpcProvider = +proc new*(_: type JsonRpcProvider, + url=defaultUrl, + pollingInterval=defaultPollingInterval): JsonRpcProvider = var initialized: Future[void] var client: RpcClient var subscriptions: JsonRpcSubscriptions @@ -67,7 +70,8 @@ proc new*(_: type JsonRpcProvider, url=defaultUrl): JsonRpcProvider = let http = newRpcHttpClient(getHeaders = jsonHeaders) await http.connect(url) client = http - subscriptions = JsonRpcSubscriptions.new(http) + subscriptions = JsonRpcSubscriptions.new(http, + pollingInterval = pollingInterval) proc awaitClient: Future[RpcClient] {.async.} = await initialized diff --git a/testmodule/providers/jsonrpc/testJsonRpcProvider.nim b/testmodule/providers/jsonrpc/testJsonRpcProvider.nim index a70e528..3895dbe 100644 --- a/testmodule/providers/jsonrpc/testJsonRpcProvider.nim +++ b/testmodule/providers/jsonrpc/testJsonRpcProvider.nim @@ -14,7 +14,7 @@ for url in ["ws://localhost:8545", "http://localhost:8545"]: var provider: JsonRpcProvider setup: - provider = JsonRpcProvider.new(url) + provider = JsonRpcProvider.new(url, pollingInterval = 100.millis) test "can be instantiated with a default URL": discard JsonRpcProvider.new()