From 25086ed1e0feae9fecf7cb553683cd98f810b681 Mon Sep 17 00:00:00 2001 From: Donald Hutchison Date: Tue, 10 Oct 2023 18:41:45 +0200 Subject: [PATCH 01/11] Cache trivial implementation. --- .../lib/explorer/celo/sanction_cache.ex | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 apps/explorer/lib/explorer/celo/sanction_cache.ex diff --git a/apps/explorer/lib/explorer/celo/sanction_cache.ex b/apps/explorer/lib/explorer/celo/sanction_cache.ex new file mode 100644 index 000000000000..fdf802bb184c --- /dev/null +++ b/apps/explorer/lib/explorer/celo/sanction_cache.ex @@ -0,0 +1,23 @@ +defmodule Explorer.Celo.SanctionCache do + @moduledoc "A cache to manage addresses blocked for interaction" + + use GenServer + + @spec start_link(term()) :: GenServer.on_start() + def start_link(params \\ %{}) do + GenServer.start_link(__MODULE__, params, name: __MODULE__) + end + + @impl true + def init(params) do + state = Map.get(params, :initial_state, %{}) + + {:ok, state, {:continue, :update_with_public_list}} + end + + @impl true + def handle_continue(:update_with_public_list, state) do + new_state = Map.put(state, :list, ["0xtestaddresspleaseblockme"]) + {:noreply, new_state} + end +end \ No newline at end of file From 25459141c4f4050aa0a4e9a9a093259ef50e423f Mon Sep 17 00:00:00 2001 From: Donald Hutchison Date: Tue, 10 Oct 2023 18:46:56 +0200 Subject: [PATCH 02/11] Add cache to web supervision tree. --- apps/block_scout_web/lib/block_scout_web/application.ex | 2 ++ apps/explorer/lib/explorer/celo/sanction_cache.ex | 9 +++++++++ 2 files changed, 11 insertions(+) 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 f156e32504ff..7bf53b53a325 100644 --- a/apps/block_scout_web/lib/block_scout_web/application.ex +++ b/apps/block_scout_web/lib/block_scout_web/application.ex @@ -13,6 +13,7 @@ defmodule BlockScoutWeb.Application do alias BlockScoutWeb.{Endpoint, RealtimeEventHandler} alias EthereumJSONRPC.Celo.Instrumentation, as: EthRPC + alias Explorer.Celo.SanctionCache alias Explorer.Celo.Telemetry.Instrumentation.{Api, Database, FlyPostgres} alias Explorer.Celo.Telemetry.MetricsCollector, as: CeloPrometheusCollector @@ -35,6 +36,7 @@ defmodule BlockScoutWeb.Application do {RealtimeEventHandler, name: RealtimeEventHandler}, {BlocksIndexedCounter, name: BlocksIndexedCounter}, {CampaignBannerCache, name: CampaignBannerCache}, + {SanctionCache, %{}}, {InternalTransactionsIndexedCounter, name: InternalTransactionsIndexedCounter} ] |> cluster_process(Application.get_env(:block_scout_web, :environment)) diff --git a/apps/explorer/lib/explorer/celo/sanction_cache.ex b/apps/explorer/lib/explorer/celo/sanction_cache.ex index fdf802bb184c..4a278febbee4 100644 --- a/apps/explorer/lib/explorer/celo/sanction_cache.ex +++ b/apps/explorer/lib/explorer/celo/sanction_cache.ex @@ -20,4 +20,13 @@ defmodule Explorer.Celo.SanctionCache do new_state = Map.put(state, :list, ["0xtestaddresspleaseblockme"]) {:noreply, new_state} end + + @impl true + def handle_call(:get_sanction_list, _from, %{list: list} = state) do + {:reply, list, state} + end + + def get_sanction_list() do + GenServer.call(__MODULE__, :get_sanction_list) + end end \ No newline at end of file From 5dd06de76a8f0312205d86f4aaffb8521b5dcce0 Mon Sep 17 00:00:00 2001 From: Donald Hutchison Date: Thu, 12 Oct 2023 15:15:31 +0200 Subject: [PATCH 03/11] Writing sanctions into html. --- .../controllers/smart_contract_controller.ex | 6 +++++- .../templates/address_write_contract/index.html.eex | 1 + .../templates/address_write_proxy/index.html.eex | 1 + .../templates/smart_contract/_functions.html.eex | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/smart_contract_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/smart_contract_controller.ex index a49e2ec0562f..d5eb3360ad37 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/smart_contract_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/smart_contract_controller.ex @@ -2,6 +2,7 @@ defmodule BlockScoutWeb.SmartContractController do use BlockScoutWeb, :controller alias BlockScoutWeb.AddressView + #alias Explorer.Celo.SanctionCache alias Explorer.Chain alias Explorer.Chain.SmartContract alias Explorer.SmartContract.{Reader, Writer} @@ -85,6 +86,7 @@ defmodule BlockScoutWeb.SmartContractController do implementation_address: implementation_address_hash_string, implementation_abi: implementation_abi, contract_type: contract_type, + sanctions: ["smart_contract_controller.ex","index"], action: action ) else @@ -138,7 +140,9 @@ defmodule BlockScoutWeb.SmartContractController do implementation_address: @burn_address, implementation_abi: [], contract_type: contract_type, - action: action + sanctions: ["smart_contract_controller.ex","index"], + + action: action ) else :error -> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_write_contract/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_write_contract/index.html.eex index 4cb36fc3a73f..aa167be06344 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_write_contract/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_write_contract/index.html.eex @@ -14,6 +14,7 @@ %>
+ <%= render BlockScoutWeb.AddressView, "_tabs.html", address: @address, is_proxy: is_proxy, conn: @conn %>
<%= render BlockScoutWeb.SmartContractView, "_connect_container.html" %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_write_proxy/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_write_proxy/index.html.eex index 6e84b630f323..2108b9bacb90 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_write_proxy/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_write_proxy/index.html.eex @@ -15,6 +15,7 @@
<%= render BlockScoutWeb.AddressView, "_tabs.html", address: @address, is_proxy: is_proxy, conn: @conn %> +