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()