Open patternmachine opened 1 month ago
Thanks for taking the time to figure this out, and sorry you had to run into this!
We should definitely index the subscriptions by the corresponding parsed and normalized Query
instead of its string representation.
Would you be open to create a PR for this? Otherwise I am happy to do it myself but it'll have to wait until next week or the one after that.
@patternmachine I just put a WIP branch with a tentative fix, let me know if that works for you until I have time to get back to it, or feel free to improve on it and open a PR.
Note that I haven't had a chance to test this so it may very well be broken in more than one way.
What went wrong?
When subscribing to
NewBlock
events (possibly also others, which I have not tested) I expect my code to receive events via theSubscription
returned by thesubscribe()
call which is not the case.After spending way too much time going through the code I discovered that the
SubscriptionRouter
stores the subscriptions internally in aHashMap<SubscriptionQuery, HashMap<SubscriptionId, SubscriptionTx>>
, whereSubscriptionQuery
is just a type alias for aString
. For theNewBlock
event that then means the key ends up being"tm.event = 'NewBlock'"
. Now when the client receives a message, it takes the query field inside that message to look into the hashmap. Unfortunately, I keep getting back"tm.event='NewBlock'"
which is obviously not the same as"tm.event = 'NewBlock'"
(missing spaces around the=
).Steps to reproduce
Take the example code from the
WebSocketClient
Definition of "done"
The above should print out the events.