mirror of
https://github.com/logos-storage/nim-ethers.git
synced 2026-01-04 22:53:08 +00:00
refactor: rename filter to logFilter
This commit is contained in:
parent
bcf6d1951a
commit
569664e629
@ -140,7 +140,7 @@ type
|
||||
# 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
|
||||
filters: Table[JsonNode, EventFilter]
|
||||
logFilters: Table[JsonNode, EventFilter]
|
||||
|
||||
# Used when filters are recreated to translate from the id that user
|
||||
# originally got returned to new filter id
|
||||
@ -168,10 +168,11 @@ proc new*(_: type JsonRpcSubscriptions,
|
||||
except CatchableError as e:
|
||||
if "filter not found" in e.msg:
|
||||
var newId: JsonNode
|
||||
# If there exists filter for given ID, then the filter was a log filter
|
||||
# otherwise it was a block filter
|
||||
if subscriptions.filters.hasKey(originalId):
|
||||
let filter = subscriptions.filters[originalId]
|
||||
# Log filters are stored in logFilters, block filters are not persisted
|
||||
# there is they do not need any specific data for their recreation.
|
||||
# We use this to determine if the filter was log or block filter here.
|
||||
if subscriptions.logFilters.hasKey(originalId):
|
||||
let filter = subscriptions.logFilters[originalId]
|
||||
newId = await subscriptions.client.eth_newFilter(filter)
|
||||
else:
|
||||
newId = await subscriptions.client.eth_newBlockFilter()
|
||||
@ -231,14 +232,14 @@ method subscribeLogs(subscriptions: PollingSubscriptions,
|
||||
|
||||
let id = await subscriptions.client.eth_newFilter(filter)
|
||||
subscriptions.callbacks[id] = callback
|
||||
subscriptions.filters[id] = filter
|
||||
subscriptions.logFilters[id] = filter
|
||||
subscriptions.subscriptionMapping[id] = id
|
||||
return id
|
||||
|
||||
method unsubscribe*(subscriptions: PollingSubscriptions,
|
||||
id: JsonNode)
|
||||
{.async.} =
|
||||
subscriptions.filters.del(id)
|
||||
subscriptions.logFilters.del(id)
|
||||
subscriptions.callbacks.del(id)
|
||||
let sub = subscriptions.subscriptionMapping[id]
|
||||
subscriptions.subscriptionMapping.del(id)
|
||||
|
||||
@ -128,14 +128,14 @@ suite "HTTP polling subscriptions - filter not found":
|
||||
let filter = EventFilter(address: Address.example, topics: @[array[32, byte].example])
|
||||
let emptyHandler = proc(log: Log) = discard
|
||||
|
||||
check subscriptions.filters.len == 0
|
||||
check subscriptions.logFilters.len == 0
|
||||
check subscriptions.subscriptionMapping.len == 0
|
||||
|
||||
let id = await subscriptions.subscribeLogs(filter, emptyHandler)
|
||||
|
||||
check subscriptions.filters[id] == filter
|
||||
check subscriptions.logFilters[id] == filter
|
||||
check subscriptions.subscriptionMapping[id] == id
|
||||
check subscriptions.filters.len == 1
|
||||
check subscriptions.logFilters.len == 1
|
||||
check subscriptions.subscriptionMapping.len == 1
|
||||
|
||||
mockServer.invalidateFilter(id)
|
||||
@ -151,7 +151,7 @@ suite "HTTP polling subscriptions - filter not found":
|
||||
|
||||
await subscriptions.unsubscribe(id)
|
||||
|
||||
check not subscriptions.filters.hasKey id
|
||||
check not subscriptions.logFilters.hasKey id
|
||||
check not subscriptions.subscriptionMapping.hasKey id
|
||||
|
||||
test "filter not found error recreates block filter":
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user