Subscribe to logs with polling
This commit is contained in:
parent
0aea16047c
commit
2481bda6e4
|
@ -16,5 +16,6 @@ proc eth_subscribe(name: string, filter: Filter): JsonNode
|
||||||
proc eth_subscribe(name: string): JsonNode
|
proc eth_subscribe(name: string): JsonNode
|
||||||
proc eth_unsubscribe(id: JsonNode): bool
|
proc eth_unsubscribe(id: JsonNode): bool
|
||||||
proc eth_newBlockFilter(): JsonNode
|
proc eth_newBlockFilter(): JsonNode
|
||||||
|
proc eth_newFilter(filter: Filter): JsonNode
|
||||||
proc eth_getFilterChanges(id: JsonNode): JsonNode
|
proc eth_getFilterChanges(id: JsonNode): JsonNode
|
||||||
proc eth_uninstallFilter(id: JsonNode): bool
|
proc eth_uninstallFilter(id: JsonNode): bool
|
||||||
|
|
|
@ -146,6 +146,20 @@ method subscribeBlocks(subscriptions: PollingSubscriptions,
|
||||||
subscriptions.callbacks[id] = callback
|
subscriptions.callbacks[id] = callback
|
||||||
return JsonRpcSubscription(subscriptions: subscriptions, id: id)
|
return JsonRpcSubscription(subscriptions: subscriptions, id: id)
|
||||||
|
|
||||||
|
method subscribeLogs(subscriptions: PollingSubscriptions,
|
||||||
|
filter: Filter,
|
||||||
|
onLog: LogHandler):
|
||||||
|
Future[JsonRpcSubscription]
|
||||||
|
{.async.} =
|
||||||
|
|
||||||
|
proc callback(id, change: JsonNode) =
|
||||||
|
if log =? Log.fromJson(change).catch:
|
||||||
|
onLog(log)
|
||||||
|
|
||||||
|
let id = await subscriptions.client.eth_newFilter(filter)
|
||||||
|
subscriptions.callbacks[id] = callback
|
||||||
|
return JsonRpcSubscription(subscriptions: subscriptions, id: id)
|
||||||
|
|
||||||
method unsubscribe(subscriptions: PollingSubscriptions,
|
method unsubscribe(subscriptions: PollingSubscriptions,
|
||||||
id: JsonNode)
|
id: JsonNode)
|
||||||
{.async.} =
|
{.async.} =
|
||||||
|
|
Loading…
Reference in New Issue