mirror of
https://github.com/logos-storage/nim-ethers.git
synced 2026-01-02 21:53:08 +00:00
Move logFilters to JsonRpcSubscriptions
This commit is contained in:
parent
7081e6922f
commit
c48ff9b84d
@ -19,6 +19,11 @@ type
|
||||
client: RpcClient
|
||||
callbacks: Table[JsonNode, SubscriptionCallback]
|
||||
methodHandlers: Table[string, MethodHandler]
|
||||
# We need to keep around the filters that are used to create log filters on the RPC node
|
||||
# as there might be a time when they need to be recreated as RPC node might prune/forget
|
||||
# about them
|
||||
# This is used of resubscribe all the subscriptions when using websocket with hardhat
|
||||
logFilters: Table[JsonNode, EventFilter]
|
||||
MethodHandler* = proc (j: JsonNode) {.gcsafe, raises: [].}
|
||||
SubscriptionCallback = proc(id: JsonNode, arguments: ?!JsonNode) {.gcsafe, raises:[].}
|
||||
|
||||
@ -140,6 +145,7 @@ method subscribeLogs(subscriptions: WebSocketSubscriptions,
|
||||
convertErrorsToSubscriptionError:
|
||||
let id = await subscriptions.client.eth_subscribe("logs", filter)
|
||||
subscriptions.callbacks[id] = callback
|
||||
subscriptions.logFilters[id] = filter
|
||||
return id
|
||||
|
||||
method unsubscribe*(subscriptions: WebSocketSubscriptions,
|
||||
@ -160,11 +166,6 @@ type
|
||||
PollingSubscriptions* = ref object of JsonRpcSubscriptions
|
||||
polling: Future[void]
|
||||
|
||||
# We need to keep around the filters that are used to create log filters on the RPC node
|
||||
# as there might be a time when they need to be recreated as RPC node might prune/forget
|
||||
# about them
|
||||
logFilters: Table[JsonNode, EventFilter]
|
||||
|
||||
# Used when filters are recreated to translate from the id that user
|
||||
# originally got returned to new filter id
|
||||
subscriptionMapping: Table[JsonNode, JsonNode]
|
||||
|
||||
@ -114,6 +114,7 @@ suite "HTTP polling subscriptions - mock tests":
|
||||
var mockServer: MockRpcHttpServer
|
||||
|
||||
privateAccess(PollingSubscriptions)
|
||||
privateAccess(JsonRpcSubscriptions)
|
||||
|
||||
proc startServer() {.async.} =
|
||||
mockServer = MockRpcHttpServer.new()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user