Merge pull request #8848 from blockscout/ap-main-page-event-handler

Add MainPageRealtimeEventHandler
pull/8843/head
Victor Baranov 1 year ago committed by GitHub
commit 228ea9d491
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 3
      apps/block_scout_web/lib/block_scout_web/application.ex
  3. 29
      apps/block_scout_web/lib/block_scout_web/main_page_realtime_event_handler.ex
  4. 4
      apps/block_scout_web/lib/block_scout_web/realtime_event_handler.ex

@ -4,6 +4,7 @@
### Features ### Features
- [#8848](https://github.com/blockscout/blockscout/pull/8848) - Add MainPageRealtimeEventHandler
- [#8795](https://github.com/blockscout/blockscout/pull/8795) - Disable catchup indexer by env - [#8795](https://github.com/blockscout/blockscout/pull/8795) - Disable catchup indexer by env
- [#8768](https://github.com/blockscout/blockscout/pull/8768) - Add possibility to search tokens by address hash - [#8768](https://github.com/blockscout/blockscout/pull/8768) - Add possibility to search tokens by address hash
- [#8750](https://github.com/blockscout/blockscout/pull/8750) - Support new eth-bytecode-db request metadata fields - [#8750](https://github.com/blockscout/blockscout/pull/8750) - Support new eth-bytecode-db request metadata fields

@ -8,7 +8,7 @@ defmodule BlockScoutWeb.Application do
alias BlockScoutWeb.API.APILogger alias BlockScoutWeb.API.APILogger
alias BlockScoutWeb.Counters.{BlocksIndexedCounter, InternalTransactionsIndexedCounter} alias BlockScoutWeb.Counters.{BlocksIndexedCounter, InternalTransactionsIndexedCounter}
alias BlockScoutWeb.{Endpoint, Prometheus} alias BlockScoutWeb.{Endpoint, Prometheus}
alias BlockScoutWeb.RealtimeEventHandler alias BlockScoutWeb.{MainPageRealtimeEventHandler, RealtimeEventHandler}
def start(_type, _args) do def start(_type, _args) do
import Supervisor import Supervisor
@ -34,6 +34,7 @@ defmodule BlockScoutWeb.Application do
{Phoenix.PubSub, name: BlockScoutWeb.PubSub}, {Phoenix.PubSub, name: BlockScoutWeb.PubSub},
child_spec(Endpoint, []), child_spec(Endpoint, []),
{Absinthe.Subscription, Endpoint}, {Absinthe.Subscription, Endpoint},
{MainPageRealtimeEventHandler, name: MainPageRealtimeEventHandler},
{RealtimeEventHandler, name: RealtimeEventHandler}, {RealtimeEventHandler, name: RealtimeEventHandler},
{BlocksIndexedCounter, name: BlocksIndexedCounter}, {BlocksIndexedCounter, name: BlocksIndexedCounter},
{InternalTransactionsIndexedCounter, name: InternalTransactionsIndexedCounter} {InternalTransactionsIndexedCounter, name: InternalTransactionsIndexedCounter}

@ -0,0 +1,29 @@
defmodule BlockScoutWeb.MainPageRealtimeEventHandler do
@moduledoc """
Subscribing process for main page broadcast events from realtime.
"""
use GenServer
alias BlockScoutWeb.Notifier
alias Explorer.Chain.Events.Subscriber
alias Explorer.Counters.Helper
def start_link(_) do
GenServer.start_link(__MODULE__, [], name: __MODULE__)
end
@impl true
def init([]) do
Helper.create_cache_table(:last_broadcasted_block)
Subscriber.to(:blocks, :realtime)
Subscriber.to(:transactions, :realtime)
{:ok, []}
end
@impl true
def handle_info(event, state) do
Notifier.handle_event(event)
{:noreply, state}
end
end

@ -7,7 +7,6 @@ defmodule BlockScoutWeb.RealtimeEventHandler do
alias BlockScoutWeb.Notifier alias BlockScoutWeb.Notifier
alias Explorer.Chain.Events.Subscriber alias Explorer.Chain.Events.Subscriber
alias Explorer.Counters.Helper
def start_link(_) do def start_link(_) do
GenServer.start_link(__MODULE__, [], name: __MODULE__) GenServer.start_link(__MODULE__, [], name: __MODULE__)
@ -15,15 +14,12 @@ defmodule BlockScoutWeb.RealtimeEventHandler do
@impl true @impl true
def init([]) do def init([]) do
Helper.create_cache_table(:last_broadcasted_block)
Subscriber.to(:address_coin_balances, :realtime) Subscriber.to(:address_coin_balances, :realtime)
Subscriber.to(:addresses, :realtime) Subscriber.to(:addresses, :realtime)
Subscriber.to(:block_rewards, :realtime) Subscriber.to(:block_rewards, :realtime)
Subscriber.to(:blocks, :realtime)
Subscriber.to(:internal_transactions, :realtime) Subscriber.to(:internal_transactions, :realtime)
Subscriber.to(:internal_transactions, :on_demand) Subscriber.to(:internal_transactions, :on_demand)
Subscriber.to(:token_transfers, :realtime) Subscriber.to(:token_transfers, :realtime)
Subscriber.to(:transactions, :realtime)
Subscriber.to(:addresses, :on_demand) Subscriber.to(:addresses, :on_demand)
Subscriber.to(:address_coin_balances, :on_demand) Subscriber.to(:address_coin_balances, :on_demand)
Subscriber.to(:address_current_token_balances, :on_demand) Subscriber.to(:address_current_token_balances, :on_demand)

Loading…
Cancel
Save