commit
021811e74d
@ -0,0 +1,73 @@ |
||||
defmodule RPCTranslatorForwarder do |
||||
@moduledoc """ |
||||
Phoenix router limits forwarding, |
||||
so this module is to forward old paths for backward compatibility |
||||
""" |
||||
alias BlockScoutWeb.API.RPC.RPCTranslator |
||||
defdelegate init(opts), to: RPCTranslator |
||||
defdelegate call(conn, opts), to: RPCTranslator |
||||
end |
||||
|
||||
defmodule BlockScoutWeb.ApiRouter do |
||||
@moduledoc """ |
||||
Router for API |
||||
""" |
||||
use BlockScoutWeb, :router |
||||
|
||||
pipeline :api do |
||||
plug(:accepts, ["json"]) |
||||
end |
||||
|
||||
scope "/v1", BlockScoutWeb.API.V1, as: :api_v1 do |
||||
pipe_through(:api) |
||||
get("/health", HealthController, :health) |
||||
|
||||
if Application.get_env(:block_scout_web, __MODULE__)[:writing_enabled] do |
||||
post("/decompiled_smart_contract", DecompiledSmartContractController, :create) |
||||
post("/verified_smart_contracts", VerifiedSmartContractController, :create) |
||||
end |
||||
end |
||||
|
||||
if Application.get_env(:block_scout_web, __MODULE__)[:reading_enabled] do |
||||
scope "/" do |
||||
alias BlockScoutWeb.API.{RPC, V1} |
||||
pipe_through(:api) |
||||
|
||||
scope "/v1", as: :api_v1 do |
||||
get("/supply", V1.SupplyController, :supply) |
||||
post("/eth_rpc", RPC.EthController, :eth_request) |
||||
end |
||||
|
||||
# For backward compatibility. Should be removed |
||||
post("/eth_rpc", RPC.EthController, :eth_request) |
||||
end |
||||
end |
||||
|
||||
scope "/" do |
||||
pipe_through(:api) |
||||
alias BlockScoutWeb.API.RPC |
||||
|
||||
scope "/v1", as: :api_v1 do |
||||
forward("/", RPC.RPCTranslator, %{ |
||||
"block" => {RPC.BlockController, []}, |
||||
"account" => {RPC.AddressController, []}, |
||||
"logs" => {RPC.LogsController, []}, |
||||
"token" => {RPC.TokenController, []}, |
||||
"stats" => {RPC.StatsController, []}, |
||||
"contract" => {RPC.ContractController, [:verify]}, |
||||
"transaction" => {RPC.TransactionController, []} |
||||
}) |
||||
end |
||||
|
||||
# For backward compatibility. Should be removed |
||||
forward("/", RPCTranslatorForwarder, %{ |
||||
"block" => {RPC.BlockController, []}, |
||||
"account" => {RPC.AddressController, []}, |
||||
"logs" => {RPC.LogsController, []}, |
||||
"token" => {RPC.TokenController, []}, |
||||
"stats" => {RPC.StatsController, []}, |
||||
"contract" => {RPC.ContractController, [:verify]}, |
||||
"transaction" => {RPC.TransactionController, []} |
||||
}) |
||||
end |
||||
end |
@ -0,0 +1,204 @@ |
||||
defmodule BlockScoutWeb.WebRouter do |
||||
@moduledoc """ |
||||
Router for web app |
||||
""" |
||||
use BlockScoutWeb, :router |
||||
|
||||
pipeline :browser do |
||||
plug(:accepts, ["html"]) |
||||
plug(:fetch_session) |
||||
plug(:fetch_flash) |
||||
plug(:protect_from_forgery) |
||||
plug(BlockScoutWeb.CSPHeader) |
||||
end |
||||
|
||||
# Disallows Iframes (write routes) |
||||
scope "/", BlockScoutWeb do |
||||
pipe_through(:browser) |
||||
end |
||||
|
||||
# Allows Iframes (read-only routes) |
||||
scope "/", BlockScoutWeb do |
||||
pipe_through([:browser, BlockScoutWeb.Plug.AllowIframe]) |
||||
|
||||
resources("/", ChainController, only: [:show], singleton: true, as: :chain) |
||||
|
||||
resources("/market_history_chart", Chain.MarketHistoryChartController, |
||||
only: [:show], |
||||
singleton: true |
||||
) |
||||
|
||||
resources "/blocks", BlockController, only: [:index, :show], param: "hash_or_number" do |
||||
resources("/transactions", BlockTransactionController, only: [:index], as: :transaction) |
||||
end |
||||
|
||||
get("/reorgs", BlockController, :reorg, as: :reorg) |
||||
|
||||
get("/uncles", BlockController, :uncle, as: :uncle) |
||||
|
||||
resources("/pending_transactions", PendingTransactionController, only: [:index]) |
||||
|
||||
resources("/recent_transactions", RecentTransactionsController, only: [:index]) |
||||
|
||||
get("/txs", TransactionController, :index) |
||||
|
||||
resources "/tx", TransactionController, only: [:show] do |
||||
resources( |
||||
"/internal_transactions", |
||||
TransactionInternalTransactionController, |
||||
only: [:index], |
||||
as: :internal_transaction |
||||
) |
||||
|
||||
resources( |
||||
"/raw_trace", |
||||
TransactionRawTraceController, |
||||
only: [:index], |
||||
as: :raw_trace |
||||
) |
||||
|
||||
resources("/logs", TransactionLogController, only: [:index], as: :log) |
||||
|
||||
resources("/token_transfers", TransactionTokenTransferController, |
||||
only: [:index], |
||||
as: :token_transfer |
||||
) |
||||
end |
||||
|
||||
resources("/accounts", AddressController, only: [:index]) |
||||
|
||||
resources "/address", AddressController, only: [:show] do |
||||
resources("/transactions", AddressTransactionController, only: [:index], as: :transaction) |
||||
|
||||
resources( |
||||
"/internal_transactions", |
||||
AddressInternalTransactionController, |
||||
only: [:index], |
||||
as: :internal_transaction |
||||
) |
||||
|
||||
resources( |
||||
"/validations", |
||||
AddressValidationController, |
||||
only: [:index], |
||||
as: :validation |
||||
) |
||||
|
||||
resources( |
||||
"/contracts", |
||||
AddressContractController, |
||||
only: [:index], |
||||
as: :contract |
||||
) |
||||
|
||||
resources( |
||||
"/decompiled_contracts", |
||||
AddressDecompiledContractController, |
||||
only: [:index], |
||||
as: :decompiled_contract |
||||
) |
||||
|
||||
resources( |
||||
"/logs", |
||||
AddressLogsController, |
||||
only: [:index], |
||||
as: :logs |
||||
) |
||||
|
||||
resources( |
||||
"/contract_verifications", |
||||
AddressContractVerificationController, |
||||
only: [:new], |
||||
as: :verify_contract |
||||
) |
||||
|
||||
resources( |
||||
"/read_contract", |
||||
AddressReadContractController, |
||||
only: [:index, :show], |
||||
as: :read_contract |
||||
) |
||||
|
||||
resources("/tokens", AddressTokenController, only: [:index], as: :token) do |
||||
resources( |
||||
"/token_transfers", |
||||
AddressTokenTransferController, |
||||
only: [:index], |
||||
as: :transfers |
||||
) |
||||
end |
||||
|
||||
resources( |
||||
"/token_balances", |
||||
AddressTokenBalanceController, |
||||
only: [:index], |
||||
as: :token_balance |
||||
) |
||||
|
||||
resources( |
||||
"/coin_balances", |
||||
AddressCoinBalanceController, |
||||
only: [:index], |
||||
as: :coin_balance |
||||
) |
||||
|
||||
resources( |
||||
"/coin_balances/by_day", |
||||
AddressCoinBalanceByDayController, |
||||
only: [:index], |
||||
as: :coin_balance_by_day |
||||
) |
||||
end |
||||
|
||||
resources "/tokens", Tokens.TokenController, only: [:show], as: :token do |
||||
resources( |
||||
"/token_transfers", |
||||
Tokens.TransferController, |
||||
only: [:index], |
||||
as: :transfer |
||||
) |
||||
|
||||
resources( |
||||
"/read_contract", |
||||
Tokens.ReadContractController, |
||||
only: [:index], |
||||
as: :read_contract |
||||
) |
||||
|
||||
resources( |
||||
"/token_holders", |
||||
Tokens.HolderController, |
||||
only: [:index], |
||||
as: :holder |
||||
) |
||||
|
||||
resources( |
||||
"/inventory", |
||||
Tokens.InventoryController, |
||||
only: [:index], |
||||
as: :inventory |
||||
) |
||||
end |
||||
|
||||
resources( |
||||
"/smart_contracts", |
||||
SmartContractController, |
||||
only: [:index, :show], |
||||
as: :smart_contract |
||||
) |
||||
|
||||
get("/search", ChainController, :search) |
||||
|
||||
get("/search_logs", AddressLogsController, :search_logs) |
||||
|
||||
get("/transactions_csv", AddressTransactionController, :transactions_csv) |
||||
|
||||
get("/token_autocomplete", ChainController, :token_autocomplete) |
||||
|
||||
get("/token_transfers_csv", AddressTransactionController, :token_transfers_csv) |
||||
|
||||
get("/chain_blocks", ChainController, :chain_blocks, as: :chain_blocks) |
||||
|
||||
get("/*path", PageNotFoundController, :index) |
||||
end |
||||
end |
Loading…
Reference in new issue