Merge pull request #47 from status-im/request-header-callback

request header callback
This commit is contained in:
tersec 2022-03-14 08:35:29 +00:00 committed by GitHub
commit 58b2e07830
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -68,16 +68,18 @@ proc newWeb3*(provider: RpcClient): Web3 =
provider.setMethodHandler("eth_subscription") do(j: JsonNode): provider.setMethodHandler("eth_subscription") do(j: JsonNode):
r.handleSubscriptionNotification(j) r.handleSubscriptionNotification(j)
proc newWeb3*(uri: string): Future[Web3] {.async.} = proc newWeb3*(
uri: string, getHeaders: GetJsonRpcRequestHeaders = nil):
Future[Web3] {.async.} =
let u = parseUri(uri) let u = parseUri(uri)
var provider: RpcClient var provider: RpcClient
case u.scheme case u.scheme
of "http", "https": of "http", "https":
let p = newRpcHttpClient() let p = newRpcHttpClient(getHeaders = getHeaders)
await p.connect(uri) await p.connect(uri)
provider = p provider = p
of "ws", "wss": of "ws", "wss":
let p = newRpcWebSocketClient() let p = newRpcWebSocketClient(getHeaders = getHeaders)
await p.connect(uri) await p.connect(uri)
provider = p provider = p
else: else: