Add polling interval to constructor of provider
This commit is contained in:
parent
88d60b14b0
commit
1b151d589d
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue