feat: broadcast updates about new Arbitrum batches and L1-L2 messages through WebSocket (#10272)
* publish new batches through websockets * publish new L1-L2 messages amount through websockets * credo issues * Consitent handling of transaction hash * new types re-usedpull/10381/head
parent
d6080e04a1
commit
b2345b159f
@ -0,0 +1,14 @@ |
||||
defmodule BlockScoutWeb.ArbitrumChannel do |
||||
@moduledoc """ |
||||
Establishes pub/sub channel for live updates of Arbitrum related events. |
||||
""" |
||||
use BlockScoutWeb, :channel |
||||
|
||||
def join("arbitrum:new_batch", _params, socket) do |
||||
{:ok, %{}, socket} |
||||
end |
||||
|
||||
def join("arbitrum:new_messages_to_rollup_amount", _params, socket) do |
||||
{:ok, %{}, socket} |
||||
end |
||||
end |
@ -0,0 +1,31 @@ |
||||
defmodule BlockScoutWeb.Notifiers.Arbitrum do |
||||
@moduledoc """ |
||||
Module to handle and broadcast Arbitrum related events. |
||||
""" |
||||
|
||||
alias BlockScoutWeb.API.V2.ArbitrumView |
||||
alias BlockScoutWeb.Endpoint |
||||
|
||||
require Logger |
||||
|
||||
def handle_event({:chain_event, :new_arbitrum_batches, :realtime, batches}) do |
||||
batches |
||||
|> Enum.sort_by(& &1.number, :asc) |
||||
|> Enum.each(fn batch -> |
||||
Endpoint.broadcast("arbitrum:new_batch", "new_arbitrum_batch", %{ |
||||
batch: ArbitrumView.render_base_info_for_batch(batch) |
||||
}) |
||||
end) |
||||
end |
||||
|
||||
def handle_event({:chain_event, :new_messages_to_arbitrum_amount, :realtime, new_messages_amount}) do |
||||
Endpoint.broadcast("arbitrum:new_messages_to_rollup_amount", "new_messages_to_rollup_amount", %{ |
||||
new_messages_to_rollup_amount: new_messages_amount |
||||
}) |
||||
end |
||||
|
||||
def handle_event(event) do |
||||
Logger.warning("Unknown broadcasted event #{inspect(event)}.") |
||||
nil |
||||
end |
||||
end |
Loading…
Reference in new issue