Add socket for confirmed batches list on the main page

pull/7584/head
POA 1 year ago
parent adc277ec22
commit bd7a7837a3
  1. 6
      .dialyzer-ignore
  2. 1
      apps/block_scout_web/lib/block_scout_web/channels/user_socket_v2.ex
  3. 31
      apps/block_scout_web/lib/block_scout_web/channels/zkevm_confirmed_batch_channel.ex
  4. 2
      apps/block_scout_web/lib/block_scout_web/controllers/api/v2/transaction_controller.ex
  5. 10
      apps/block_scout_web/lib/block_scout_web/notifier.ex
  6. 1
      apps/block_scout_web/lib/block_scout_web/realtime_event_handler.ex
  7. 6
      apps/block_scout_web/lib/block_scout_web/views/api/v2/transaction_view.ex
  8. 2
      apps/explorer/lib/explorer/chain/events/publisher.ex
  9. 2
      apps/explorer/lib/explorer/chain/events/subscriber.ex
  10. 8
      apps/indexer/lib/indexer/fetcher/zkevm/transaction_batch.ex

@ -20,6 +20,6 @@ lib/indexer/fetcher/polygon_edge/deposit_execute.ex:140
lib/indexer/fetcher/polygon_edge/deposit_execute.ex:184
lib/indexer/fetcher/polygon_edge/withdrawal.ex:160
lib/indexer/fetcher/polygon_edge/withdrawal.ex:204
lib/indexer/fetcher/zkevm/transaction_batch.ex:115
lib/indexer/fetcher/zkevm/transaction_batch.ex:155
lib/indexer/fetcher/zkevm/transaction_batch.ex:251
lib/indexer/fetcher/zkevm/transaction_batch.ex:116
lib/indexer/fetcher/zkevm/transaction_batch.ex:156
lib/indexer/fetcher/zkevm/transaction_batch.ex:252

@ -10,6 +10,7 @@ defmodule BlockScoutWeb.UserSocketV2 do
channel("rewards:*", BlockScoutWeb.RewardChannel)
channel("transactions:*", BlockScoutWeb.TransactionChannel)
channel("tokens:*", BlockScoutWeb.TokenChannel)
channel("zkevm_batches:*", BlockScoutWeb.ZkevmConfirmedBatchChannel)
def connect(_params, socket) do
{:ok, socket}

@ -0,0 +1,31 @@
defmodule BlockScoutWeb.ZkevmConfirmedBatchChannel do
@moduledoc """
Establishes pub/sub channel for live updates of zkEVM confirmed batch events.
"""
use BlockScoutWeb, :channel
alias BlockScoutWeb.API.V2.ZkevmView
intercept(["new_zkevm_confirmed_batch"])
def join("zkevm_batches:new_zkevm_confirmed_batch", _params, socket) do
require Logger
Logger.warn("zkevm_batches:new_zkevm_confirmed_batch")
{:ok, %{}, socket}
end
def handle_out(
"new_zkevm_confirmed_batch",
%{batch: batch},
%Phoenix.Socket{handler: BlockScoutWeb.UserSocketV2} = socket
) do
rendered_batch = ZkevmView.render("zkevm_batch.json", %{batch: batch, socket: nil})
push(socket, "new_zkevm_confirmed_batch", %{
batch: rendered_batch
})
{:noreply, socket}
end
end

@ -134,7 +134,7 @@ defmodule BlockScoutWeb.API.V2.TransactionController do
conn
|> put_status(200)
|> render(:transactions, %{transactions: transactions})
|> render(:transactions, %{transactions: transactions, items: true})
end
@doc """

@ -114,6 +114,16 @@ defmodule BlockScoutWeb.Notifier do
end)
end
def handle_event({:chain_event, :zkevm_confirmed_batches, :realtime, batches}) do
batches
|> Enum.sort_by(& &1.number, :asc)
|> Enum.each(fn confirmed_batch ->
Endpoint.broadcast("zkevm_batches:new_zkevm_confirmed_batch", "new_zkevm_confirmed_batch", %{
batch: confirmed_batch
})
end)
end
def handle_event({:chain_event, :exchange_rate}) do
exchange_rate = Market.get_coin_exchange_rate()

@ -32,6 +32,7 @@ defmodule BlockScoutWeb.RealtimeEventHandler do
Subscriber.to(:token_total_supply, :on_demand)
Subscriber.to(:changed_bytecode, :on_demand)
Subscriber.to(:smart_contract_was_verified, :on_demand)
Subscriber.to(:zkevm_confirmed_batches, :realtime)
# Does not come from the indexer
Subscriber.to(:exchange_rate)
Subscriber.to(:transaction_stats)

@ -71,6 +71,12 @@ defmodule BlockScoutWeb.API.V2.TransactionView do
}
end
def render("transactions.json", %{transactions: transactions, items: true, conn: conn}) do
%{
"items" => render("transactions.json", %{transactions: transactions, conn: conn})
}
end
def render("transactions.json", %{transactions: transactions, conn: conn}) do
block_height = Chain.block_height(@api_true)
{decoded_transactions, _, _} = decode_transactions(transactions, true)

@ -3,7 +3,7 @@ defmodule Explorer.Chain.Events.Publisher do
Publishes events related to the Chain context.
"""
@allowed_events ~w(addresses address_coin_balances address_token_balances address_current_token_balances blocks block_rewards internal_transactions last_block_number polygon_edge_reorg_block token_transfers transactions contract_verification_result token_total_supply changed_bytecode smart_contract_was_verified)a
@allowed_events ~w(addresses address_coin_balances address_token_balances address_current_token_balances blocks block_rewards internal_transactions last_block_number polygon_edge_reorg_block token_transfers transactions contract_verification_result token_total_supply changed_bytecode smart_contract_was_verified zkevm_confirmed_batches)a
def broadcast(_data, false), do: :ok

@ -3,7 +3,7 @@ defmodule Explorer.Chain.Events.Subscriber do
Subscribes to events related to the Chain context.
"""
@allowed_broadcast_events ~w(addresses address_coin_balances address_token_balances address_current_token_balances blocks block_rewards internal_transactions last_block_number polygon_edge_reorg_block token_transfers transactions contract_verification_result token_total_supply changed_bytecode smart_contract_was_verified)a
@allowed_broadcast_events ~w(addresses address_coin_balances address_token_balances address_current_token_balances blocks block_rewards internal_transactions last_block_number polygon_edge_reorg_block token_transfers transactions contract_verification_result token_total_supply changed_bytecode smart_contract_was_verified zkevm_confirmed_batches)a
@allowed_broadcast_types ~w(catchup realtime on_demand contract_verification_result)a

@ -11,6 +11,7 @@ defmodule Indexer.Fetcher.Zkevm.TransactionBatch do
import EthereumJSONRPC, only: [integer_to_quantity: 1, json_rpc: 2, quantity_to_integer: 1]
alias Explorer.Chain
alias Explorer.Chain.Events.Publisher
alias Explorer.Chain.Zkevm.Reader
@zero_hash "0000000000000000000000000000000000000000000000000000000000000000"
@ -254,6 +255,13 @@ defmodule Indexer.Fetcher.Zkevm.TransactionBatch do
zkevm_batch_transactions: %{params: l2_txs_to_import},
timeout: :infinity
})
confirmed_batches =
Enum.filter(batches_to_import, fn batch -> not is_nil(batch.sequence_id) and batch.sequence_id > 0 end)
if not Enum.empty?(confirmed_batches) do
Publisher.broadcast([{:zkevm_confirmed_batches, confirmed_batches}], :realtime)
end
end
defp fetch_latest_batch_numbers(json_rpc_named_arguments) do

Loading…
Cancel
Save