essential-contributions / essential-server

Centralized implementation of the Essential declarative protocol
Apache License 2.0
0 stars 0 forks source link

feat: add contract and block subscriptions #177

Closed freesig closed 3 months ago

freesig commented 3 months ago

This adds server sent event apis for /subscribe-contracts and /subscribe-blocks. Internally it uses a stream unfold that does the initial lists and then awaits a watch channel for updates. I chose a watch instead of a notify because a watch Receiver will return from changed() if there has been any updates since the start of the channel. This means that the api will never miss an update. Compared to a notify which would work if we used notify_one() except that we can have multiple streams, so you would need to use notify_waiters() which only notifies streams actively awaiting the notify future. This makes it easy to miss an update.

The stream logic is abstracted across databases and contracts / blocks which makes it easier to maintain and test. It has to live in the essential-storage crate because of this though.

TODO: