diff --git a/.env.example b/.env.example index af282507..08836e65 100644 --- a/.env.example +++ b/.env.example @@ -1,8 +1,10 @@ export DB_TYPE= # set to postgresql if you want to use postgresql, empty otherwise (sqlite). export DISABLE_MAINNET_SYNC=true # Set to true if you want to disable mainnet sync export DISABLE_TESTNET_SYNC=true # Set to true if you want to disable testnet sync +export DISABLE_SEPOLIA_SYNC=true # Set to true if you want to disable sepolia sync export RPC_API_HOST= # Set to your mainnet rpc api host, is will be used in the explorer as "Mainnet" export TESTNET_RPC_API_HOST= # Set to your testnet rpc api host, is will be used in the explorer as "Testnet" +export SEPOLIA_RPC_API_HOST= # Set to your sepolia rpc api host, is will be used in the explorer as "Sepolia" export DB_NAME= # set DB creds export DB_USER= export DB_PASS= diff --git a/config/config.exs b/config/config.exs index 3599a8b4..3f651376 100644 --- a/config/config.exs +++ b/config/config.exs @@ -62,7 +62,7 @@ config :esbuild, ] config :starknet_explorer, - allowed_networks: [:mainnet, :testnet] + allowed_networks: [:mainnet, :testnet, :sepolia] # Import environment specific config. This must remain at the bottom # of this file so it overrides the configuration defined above. diff --git a/config/runtime.exs b/config/runtime.exs index 9eba51b0..75cf6556 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -32,9 +32,16 @@ testnet_rpc_host = environment variable for testnet is missing. """ +sepolia_rpc_host = + System.get_env("SEPOLIA_RPC_API_HOST") || + raise """ + environment variable for sepolia is missing. + """ + config :starknet_explorer, rpc_host: rpc_host, - testnet_host: testnet_rpc_host + testnet_host: testnet_rpc_host, + sepolia_host: sepolia_rpc_host config :starknet_explorer, rpc_host: rpc_host diff --git a/lib/cache_request_warmer.ex b/lib/cache_request_warmer.ex index 20991496..2c2a7c63 100644 --- a/lib/cache_request_warmer.ex +++ b/lib/cache_request_warmer.ex @@ -6,7 +6,7 @@ defmodule StarknetExplorer.Cache.BlockWarmer do def interval, do: @interval def execute(%{network: network}) - when network in [:mainnet, :testnet] do + when network in [:mainnet, :testnet, :sepolia] do Logger.debug("Warming cache for #{network}") # Try/Rescue is not really an elixir/erlang thing to do, but # I think this is the most simple way to do this, since diff --git a/lib/starknet_explorer/application.ex b/lib/starknet_explorer/application.ex index 899be335..61527730 100644 --- a/lib/starknet_explorer/application.ex +++ b/lib/starknet_explorer/application.ex @@ -35,6 +35,20 @@ defmodule StarknetExplorer.Application do ] end + sepolia_state_sync = + if System.get_env("DISABLE_SEPOLIA_SYNC") == "true" do + [] + else + # Start the State Sync System server for sepolia. + [ + Supervisor.child_spec( + {StarknetExplorer.Blockchain.StateSyncSystem, + [network: :sepolia, name: :sepolia_state_sync]}, + id: :sepolia_state_sync + ) + ] + end + children = [ # Start the Telemetry supervisor @@ -50,7 +64,7 @@ defmodule StarknetExplorer.Application do # Start a worker by calling: StarknetExplorer.Worker.start_link(arg) # {StarknetExplorer.Worker, arg} StarknetExplorer.IndexCache - ] ++ testnet_state_sync ++ mainnet_state_sync + ] ++ sepolia_state_sync ++ testnet_state_sync ++ mainnet_state_sync # See https://hexdocs.pm/elixir/Supervisor.html # for other strategies and supported options diff --git a/lib/starknet_explorer/block/block.ex b/lib/starknet_explorer/block/block.ex index c501bd8e..5d29d1cd 100644 --- a/lib/starknet_explorer/block/block.ex +++ b/lib/starknet_explorer/block/block.ex @@ -8,7 +8,7 @@ defmodule StarknetExplorer.Block do alias StarknetExplorerWeb.Utils alias StarknetExplorer.TransactionReceipt, as: Receipt require Logger - @networks [:mainnet, :testnet] + @networks [:mainnet, :testnet, :sepolia] @cast_fields [ :number, :status, diff --git a/lib/starknet_explorer/cache.ex b/lib/starknet_explorer/cache.ex index 8a75bd29..d9818c49 100644 --- a/lib/starknet_explorer/cache.ex +++ b/lib/starknet_explorer/cache.ex @@ -5,12 +5,14 @@ defmodule StarknetExplorer.IndexCache do def start_link(_) do blocks_mainnet = StarknetExplorer.Data.many_blocks_with_txs("mainnet") blocks_testnet = StarknetExplorer.Data.many_blocks_with_txs("testnet") + blocks_sepolia = StarknetExplorer.Data.many_blocks_with_txs("sepolia") Agent.start_link( fn -> %{ "mainnet" => blocks_mainnet, - "testnet" => blocks_testnet + "testnet" => blocks_testnet, + "sepolia" => blocks_sepolia } end, name: __MODULE__ diff --git a/lib/starknet_explorer/class.ex b/lib/starknet_explorer/class.ex index 95c5b891..4843e22c 100644 --- a/lib/starknet_explorer/class.ex +++ b/lib/starknet_explorer/class.ex @@ -54,7 +54,7 @@ defmodule StarknetExplorer.Class do ] } - @networks [:mainnet, :testnet] + @networks [:mainnet, :testnet, :sepolia] @fields [ :declared_by_address, diff --git a/lib/starknet_explorer/contract.ex b/lib/starknet_explorer/contract.ex index bebb8403..2a3f01bd 100644 --- a/lib/starknet_explorer/contract.ex +++ b/lib/starknet_explorer/contract.ex @@ -4,7 +4,7 @@ defmodule StarknetExplorer.Contract do import Ecto.Query alias StarknetExplorer.Repo - @networks [:mainnet, :testnet] + @networks [:mainnet, :testnet, :sepolia] @fields [ :address, :deployed_by_address, diff --git a/lib/starknet_explorer/events.ex b/lib/starknet_explorer/events.ex index 278787bf..92398a25 100644 --- a/lib/starknet_explorer/events.ex +++ b/lib/starknet_explorer/events.ex @@ -77,7 +77,7 @@ defmodule StarknetExplorer.Events do field :data, {:array, :string} field :index_in_block, :integer field :transaction_hash, :string - field :network, Ecto.Enum, values: [:mainnet, :testnet] + field :network, Ecto.Enum, values: [:mainnet, :testnet, :sepolia] timestamps() end diff --git a/lib/starknet_explorer/message.ex b/lib/starknet_explorer/message.ex index f26c6edb..37081246 100644 --- a/lib/starknet_explorer/message.ex +++ b/lib/starknet_explorer/message.ex @@ -36,7 +36,7 @@ defmodule StarknetExplorer.Message do :l1_to_l2_cancelled_on_l1 ] - field :network, Ecto.Enum, values: [:mainnet, :testnet] + field :network, Ecto.Enum, values: [:mainnet, :testnet, :sepolia] # belongs_to :transaction, Transaction, foreign_key: :transaction_hash, references: :hash timestamps() end diff --git a/lib/starknet_explorer/transaction.ex b/lib/starknet_explorer/transaction.ex index 02e6ef2b..4059a8f3 100644 --- a/lib/starknet_explorer/transaction.ex +++ b/lib/starknet_explorer/transaction.ex @@ -71,7 +71,7 @@ defmodule StarknetExplorer.Transaction do @deploy_account_tx_fields ++ [:network, :nonce] - @networks [:mainnet, :testnet] + @networks [:mainnet, :testnet, :sepolia] @primary_key {:hash, :string, []} schema "transactions" do diff --git a/lib/starknet_explorer/transaction_receipt.ex b/lib/starknet_explorer/transaction_receipt.ex index 4d8501d1..8292e574 100644 --- a/lib/starknet_explorer/transaction_receipt.ex +++ b/lib/starknet_explorer/transaction_receipt.ex @@ -84,7 +84,7 @@ defmodule StarknetExplorer.TransactionReceipt do # :contract_address # ] - @networks [:mainnet, :testnet] + @networks [:mainnet, :testnet, :sepolia] @fields @invoke_tx_receipt_fields ++ @l1_receipt_handler ++ diff --git a/lib/starknet_explorer_web/components/layouts/root.html.heex b/lib/starknet_explorer_web/components/layouts/root.html.heex index 29f74c35..f3df4393 100644 --- a/lib/starknet_explorer_web/components/layouts/root.html.heex +++ b/lib/starknet_explorer_web/components/layouts/root.html.heex @@ -152,6 +152,14 @@ Testnet + diff --git a/lib/starknet_explorer_web/live/common_assigns.ex b/lib/starknet_explorer_web/live/common_assigns.ex index 5ee6e420..eb154f9c 100644 --- a/lib/starknet_explorer_web/live/common_assigns.ex +++ b/lib/starknet_explorer_web/live/common_assigns.ex @@ -4,7 +4,7 @@ defmodule StarknetExplorerWeb.Live.CommonAssigns do def on_mount(:network, params, _session, socket) do socket = case Map.get(params, "network") do - network when network in ["testnet"] -> + network when network in ["testnet", "sepolia"] -> network = network |> String.to_existing_atom() diff --git a/lib/starknet_explorer_web/live/utils.ex b/lib/starknet_explorer_web/live/utils.ex index 8c23dd8b..1402ac5a 100644 --- a/lib/starknet_explorer_web/live/utils.ex +++ b/lib/starknet_explorer_web/live/utils.ex @@ -164,6 +164,7 @@ defmodule StarknetExplorerWeb.Utils do # This case is for mainnet def network_path(:mainnet), do: "/" def network_path(:testnet), do: "/testnet/" + def network_path(:sepolia), do: "/sepolia/" def network_path(:mainnet, remaining_path) do "/#{remaining_path}" @@ -173,6 +174,10 @@ defmodule StarknetExplorerWeb.Utils do "/testnet/#{remaining_path}" end + def network_path(:sepolia, remaining_path) do + "/sepolia/#{remaining_path}" + end + def format_version(<<"0x", hex_val::binary>>), do: "Cairo " <> hex_val def format_version(nil), do: "-" def format_version(version), do: version diff --git a/lib/starknet_rpc.ex b/lib/starknet_rpc.ex index 6e60a0aa..2570b2b3 100644 --- a/lib/starknet_rpc.ex +++ b/lib/starknet_rpc.ex @@ -81,7 +81,7 @@ defmodule StarknetExplorer.Rpc do network ) - defp send_request(method, args, network) when network in [:mainnet, :testnet] do + defp send_request(method, args, network) when network in [:mainnet, :testnet, :sepolia] do payload = build_payload(method, args) case cache_lookup(method, args, network) do @@ -107,7 +107,7 @@ defmodule StarknetExplorer.Rpc do end defp send_request_no_cache(method, args, network) - when network in [:mainnet, :testnet] do + when network in [:mainnet, :testnet, :sepolia] do payload = build_payload(method, args) host = fetch_rpc_host(network) {:ok, rsp} = post(host, payload) @@ -116,6 +116,7 @@ defmodule StarknetExplorer.Rpc do defp fetch_rpc_host(:mainnet), do: Application.fetch_env!(:starknet_explorer, :rpc_host) defp fetch_rpc_host(:testnet), do: Application.fetch_env!(:starknet_explorer, :testnet_host) + defp fetch_rpc_host(:sepolia), do: Application.fetch_env!(:starknet_explorer, :sepolia_host) defp build_payload(method, params) do %{ @@ -151,7 +152,7 @@ defmodule StarknetExplorer.Rpc do defp do_cache_lookup(cache_type, key, network) when cache_type in [:block_cache, :tx_cache, :request_cache] and - network in [:mainnet, :testnet] do + network in [:mainnet, :testnet, :sepolia] do cache_name = :"#{network}_#{cache_type}" case Cachex.get(cache_name, key) do