W3WS.Handler.BlockRemovalHandler (w3ws v0.3.1)

Handler which filters removed events by buffering received events until future blocks are created.

Each time a new block is added the handler will check the queue and see if any events should be pushed to the given :handler. :blocks configures the number of blocks that must be created before an event is pushed to the :handler.

If a removed: true event is received the handler will filter out the original event and the removed event, preventing them from being sent to the :handler.

In order to prevent memory usage from growing out of control, removed events are forgotten after :removal_timeout which defaults to 10s.

This handler is meant to be composed with other handlers.

Example

{:ok, listener} = W3WS.Listener.start_link(
  uri: "http://localhost:8545",
  subscriptions: [
    [
      abi_files: ["path/to/abi.json"],
      handler: {W3WS.Handler.BlockRemovalHandler, 
        blocks: 12,
        handler: W3WS.Handler.DefaultHandler,
        removal_timeout: :timer.seconds(10),
        settled_threshold: :timer.seconds(5)},
      topics: ["Transfer"],
      address: "0x73d578371eb449726d727376393b02bb3b8e6a57"
    ]
  ]
)

Summary

Functions

Returns a specification to start this module under a supervisor.

GenServer handle cast callback.

Handle an event. Casts the event to the GenServer.

Initialize the handler. Requires a W3WS.Rpc.rpc/0 to be passed in the args

Returns true if the handler has settled.

Functions

Link to this function

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

handle_cast(msg, state)

GenServer handle cast callback.

Link to this function

handle_event(env, handler)

Handle an event. Casts the event to the GenServer.

Link to this function

initialize(args)

Initialize the handler. Requires a W3WS.Rpc.rpc/0 to be passed in the args

Link to this function

settled?(state)

Returns true if the handler has settled.