essential-contributions / essential-server

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

Subscribe to contracts and blocks. #172

Closed freesig closed 1 month ago

freesig commented 1 month ago

Add two new api endpoints using server sent events with axum sse. SSE are basically lightweight websockets using HTTP/2. This means it's trivial for the server to handle a lot of these connections.

Subscribe Contracts

Add the api /subscribe-contracts that takes:

Subscribe Blocks

Add the api /subscribe-blocks that takes:

Implementation

In the rqlite-storage and memory-storage we will need to add either a notify or watch. Care must be taken to ensure that when the subscribe_* methods are called that any changes after the initial list_* are not skipped. This might make Notify unsuitable as notify_waiters does not awaken Notifys that are not yet awaiting notified.

The subsribe_ will have to track which was the last sent data and which page they were up to to avoid sending duplicate data.