diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d87321c54..a63c6d520a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Features +- [#9018](https://github.com/blockscout/blockscout/pull/9018) - Add SmartContractRealtimeEventHandler - [#8997](https://github.com/blockscout/blockscout/pull/8997) - Isolate throttable error count by request method - [#8975](https://github.com/blockscout/blockscout/pull/8975) - Add EIP-4844 compatibility (not full support yet) - [#8972](https://github.com/blockscout/blockscout/pull/8972) - BENS integration diff --git a/apps/block_scout_web/lib/block_scout_web/application.ex b/apps/block_scout_web/lib/block_scout_web/application.ex index cb46a88576..f323ef8e95 100644 --- a/apps/block_scout_web/lib/block_scout_web/application.ex +++ b/apps/block_scout_web/lib/block_scout_web/application.ex @@ -8,7 +8,7 @@ defmodule BlockScoutWeb.Application do alias BlockScoutWeb.API.APILogger alias BlockScoutWeb.Counters.{BlocksIndexedCounter, InternalTransactionsIndexedCounter} alias BlockScoutWeb.{Endpoint, Prometheus} - alias BlockScoutWeb.{MainPageRealtimeEventHandler, RealtimeEventHandler} + alias BlockScoutWeb.{MainPageRealtimeEventHandler, RealtimeEventHandler, SmartContractRealtimeEventHandler} def start(_type, _args) do import Supervisor @@ -36,6 +36,7 @@ defmodule BlockScoutWeb.Application do {Absinthe.Subscription, Endpoint}, {MainPageRealtimeEventHandler, name: MainPageRealtimeEventHandler}, {RealtimeEventHandler, name: RealtimeEventHandler}, + {SmartContractRealtimeEventHandler, name: SmartContractRealtimeEventHandler}, {BlocksIndexedCounter, name: BlocksIndexedCounter}, {InternalTransactionsIndexedCounter, name: InternalTransactionsIndexedCounter} ] diff --git a/apps/block_scout_web/lib/block_scout_web/realtime_event_handler.ex b/apps/block_scout_web/lib/block_scout_web/realtime_event_handler.ex index 7d029f17f8..1fedc2dc3d 100644 --- a/apps/block_scout_web/lib/block_scout_web/realtime_event_handler.ex +++ b/apps/block_scout_web/lib/block_scout_web/realtime_event_handler.ex @@ -24,11 +24,8 @@ defmodule BlockScoutWeb.RealtimeEventHandler do Subscriber.to(:address_coin_balances, :on_demand) Subscriber.to(:address_current_token_balances, :on_demand) Subscriber.to(:address_token_balances, :on_demand) - Subscriber.to(:contract_verification_result, :on_demand) Subscriber.to(:token_total_supply, :on_demand) Subscriber.to(:changed_bytecode, :on_demand) - Subscriber.to(:smart_contract_was_verified, :on_demand) - Subscriber.to(:smart_contract_was_not_verified, :on_demand) Subscriber.to(:eth_bytecode_db_lookup_started, :on_demand) Subscriber.to(:zkevm_confirmed_batches, :realtime) # Does not come from the indexer diff --git a/apps/block_scout_web/lib/block_scout_web/smart_contract_realtime_event_handler.ex b/apps/block_scout_web/lib/block_scout_web/smart_contract_realtime_event_handler.ex new file mode 100644 index 0000000000..e94e8a3bb9 --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/smart_contract_realtime_event_handler.ex @@ -0,0 +1,28 @@ +defmodule BlockScoutWeb.SmartContractRealtimeEventHandler do + @moduledoc """ + Subscribing process for smart contract verification related broadcast events from realtime. + """ + + use GenServer + + alias BlockScoutWeb.Notifier + alias Explorer.Chain.Events.Subscriber + + def start_link(_) do + GenServer.start_link(__MODULE__, [], name: __MODULE__) + end + + @impl true + def init([]) do + Subscriber.to(:contract_verification_result, :on_demand) + Subscriber.to(:smart_contract_was_verified, :on_demand) + Subscriber.to(:smart_contract_was_not_verified, :on_demand) + {:ok, []} + end + + @impl true + def handle_info(event, state) do + Notifier.handle_event(event) + {:noreply, state} + end +end