From e3b485771deb9e3eb44723ca2494592462b32aa6 Mon Sep 17 00:00:00 2001 From: saneery Date: Wed, 17 Jul 2019 14:54:47 +0300 Subject: [PATCH 01/54] Split API's endpoints into separate router --- apps/block_scout_web/config/config.exs | 2 + .../lib/block_scout_web/api_router.ex | 72 +++++++++++++++++++ .../lib/block_scout_web/router.ex | 56 +++------------ 3 files changed, 85 insertions(+), 45 deletions(-) create mode 100644 apps/block_scout_web/lib/block_scout_web/api_router.ex diff --git a/apps/block_scout_web/config/config.exs b/apps/block_scout_web/config/config.exs index 836a21ba02..f99647694d 100644 --- a/apps/block_scout_web/config/config.exs +++ b/apps/block_scout_web/config/config.exs @@ -86,6 +86,8 @@ config :wobserver, discovery: :none, mode: :plug +config :block_scout_web, BlockScoutWeb.ApiRouter, enabled: System.get_env("DISABLE_API") != "true" + # Import environment specific config. This must remain at the bottom # of this file so it overrides the configuration defined above. import_config "#{Mix.env()}.exs" diff --git a/apps/block_scout_web/lib/block_scout_web/api_router.ex b/apps/block_scout_web/lib/block_scout_web/api_router.ex new file mode 100644 index 0000000000..c40bd69e73 --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/api_router.ex @@ -0,0 +1,72 @@ +defmodule BlockScoutWeb.ApiRouter do + @moduledoc """ + Router for API + """ + use BlockScoutWeb, :router + + alias BlockScoutWeb.API.RPC + alias BlockScoutWeb.Plug.GraphQL + + pipeline :api do + plug(:accepts, ["json"]) + end + + scope "/v1", BlockScoutWeb.API.V1, as: :api_v1 do + pipe_through(:api) + + get("/supply", SupplyController, :supply) + + get("/health", HealthController, :health) + + post("/decompiled_smart_contract", DecompiledSmartContractController, :create) + post("/verified_smart_contracts", VerifiedSmartContractController, :create) + post("/contract_verifications", BlockScoutWeb.AddressContractVerificationController, :create) + + post("/eth_rpc", EthController, :eth_request) + + forward("/", RPCTranslator, %{ + "block" => RPC.BlockController, + "account" => RPC.AddressController, + "logs" => RPC.LogsController, + "token" => RPC.TokenController, + "stats" => RPC.StatsController, + "contract" => RPC.ContractController, + "transaction" => RPC.TransactionController + }) + end + + # Needs to be 200 to support the schema introspection for graphiql + @max_complexity 200 + + forward("/graphql", Absinthe.Plug, + schema: BlockScoutWeb.Schema, + analyze_complexity: true, + max_complexity: @max_complexity + ) + + forward("/graphiql", Absinthe.Plug.GraphiQL, + schema: BlockScoutWeb.Schema, + interface: :advanced, + default_query: GraphQL.default_query(), + socket: BlockScoutWeb.UserSocket, + analyze_complexity: true, + max_complexity: @max_complexity + ) + + # For backward compatibility. Should be removed + scope "/", BlockScoutWeb.API.RPC do + pipe_through(:api) + + post("/eth_rpc", EthController, :eth_request) + + forward("/", RPCTranslator, %{ + "block" => RPC.BlockController, + "account" => RPC.AddressController, + "logs" => RPC.LogsController, + "token" => RPC.TokenController, + "stats" => RPC.StatsController, + "contract" => RPC.ContractController, + "transaction" => RPC.TransactionController + }) + end +end diff --git a/apps/block_scout_web/lib/block_scout_web/router.ex b/apps/block_scout_web/lib/block_scout_web/router.ex index 4f5a8e1bed..f52493d25c 100644 --- a/apps/block_scout_web/lib/block_scout_web/router.ex +++ b/apps/block_scout_web/lib/block_scout_web/router.ex @@ -6,53 +6,11 @@ defmodule BlockScoutWeb.Router do forward("/wobserver", Wobserver.Web.Router) forward("/admin", BlockScoutWeb.AdminRouter) - pipeline :browser do - plug(:accepts, ["html"]) - plug(:fetch_session) - plug(:fetch_flash) - plug(:protect_from_forgery) - plug(BlockScoutWeb.CSPHeader) - end - - pipeline :api do - plug(:accepts, ["json"]) - end - - scope "/api/v1", BlockScoutWeb.API.V1, as: :api_v1 do - pipe_through(:api) - - get("/supply", SupplyController, :supply) - - get("/health", HealthController, :health) - - resources("/decompiled_smart_contract", DecompiledSmartContractController, only: [:create]) - resources("/verified_smart_contracts", VerifiedSmartContractController, only: [:create]) - end - - scope "/verify_smart_contract" do - pipe_through(:api) - - post("/contract_verifications", BlockScoutWeb.AddressContractVerificationController, :create) - end - - scope "/api", BlockScoutWeb.API.RPC do - pipe_through(:api) - - alias BlockScoutWeb.API.RPC - - post("/eth_rpc", EthController, :eth_request) - - forward("/", RPCTranslator, %{ - "block" => RPC.BlockController, - "account" => RPC.AddressController, - "logs" => RPC.LogsController, - "token" => RPC.TokenController, - "stats" => RPC.StatsController, - "contract" => RPC.ContractController, - "transaction" => RPC.TransactionController - }) + if Application.get_env(:block_scout_web, BlockScoutWeb.ApiRouter, :enabled) do + forward("/api", BlockScoutWeb.ApiRouter) end + # For backward compatibility. Should be removed # Needs to be 200 to support the schema introspection for graphiql @max_complexity 200 @@ -71,6 +29,14 @@ defmodule BlockScoutWeb.Router do max_complexity: @max_complexity ) + 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) From 6bb49e01303f04b2b661d7822c61dd2ddca4f74d Mon Sep 17 00:00:00 2001 From: saneery Date: Wed, 17 Jul 2019 14:59:10 +0300 Subject: [PATCH 02/54] Update tests to work with new routes path --- .../templates/address_contract_verification/new.html.eex | 2 +- .../views/address_contract_verification_view.ex | 5 +++++ .../api/v1/decompiled_smart_contract_controller_test.exs | 5 +++++ .../controllers/api/v1/health_controller_test.exs | 6 ++++++ .../controllers/api/v1/supply_controller_test.exs | 5 +++++ .../api/v1/verified_smart_contract_controller_test.exs | 5 +++++ 6 files changed, 27 insertions(+), 1 deletion(-) diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_contract_verification/new.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_contract_verification/new.html.eex index fd93b0af2b..a1a715a734 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_contract_verification/new.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_contract_verification/new.html.eex @@ -9,7 +9,7 @@

<%= gettext "New Smart Contract Verification" %>

<%= form_for @changeset, - address_contract_verification_path(@conn, :create), + api_v1_address_contract_verification_path(@conn, :create), [], fn f -> %> diff --git a/apps/block_scout_web/lib/block_scout_web/views/address_contract_verification_view.ex b/apps/block_scout_web/lib/block_scout_web/views/address_contract_verification_view.ex index 874b470406..b8e39ab547 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/address_contract_verification_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/address_contract_verification_view.ex @@ -1,3 +1,8 @@ defmodule BlockScoutWeb.AddressContractVerificationView do use BlockScoutWeb, :view + alias BlockScoutWeb.ApiRouter.Helpers + + def api_v1_address_contract_verification_path(conn, action) do + "/api" <> Helpers.api_v1_address_contract_verification_path(conn, action) + end end diff --git a/apps/block_scout_web/test/block_scout_web/controllers/api/v1/decompiled_smart_contract_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/api/v1/decompiled_smart_contract_controller_test.exs index d6b52c8490..b39d6688e0 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/api/v1/decompiled_smart_contract_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/api/v1/decompiled_smart_contract_controller_test.exs @@ -1,6 +1,7 @@ defmodule BlockScoutWeb.API.V1.DecompiledControllerTest do use BlockScoutWeb.ConnCase + alias BlockScoutWeb.ApiRouter.Helpers alias Explorer.Repo alias Explorer.Chain.{Address, DecompiledSmartContract} @@ -114,4 +115,8 @@ defmodule BlockScoutWeb.API.V1.DecompiledControllerTest do assert request.status == 403 end end + + def api_v1_decompiled_smart_contract_path(conn, action) do + "/api" <> Helpers.api_v1_decompiled_smart_contract_path(conn, action) + end end diff --git a/apps/block_scout_web/test/block_scout_web/controllers/api/v1/health_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/api/v1/health_controller_test.exs index 41735f685a..53abd8b880 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/api/v1/health_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/api/v1/health_controller_test.exs @@ -1,6 +1,8 @@ defmodule BlockScoutWeb.API.V1.HealthControllerTest do use BlockScoutWeb.ConnCase + alias BlockScoutWeb.ApiRouter.Helpers + describe "GET last_block_status/0" do test "returns error when there are no blocks in db", %{conn: conn} do request = get(conn, api_v1_health_path(conn, :health)) @@ -47,4 +49,8 @@ defmodule BlockScoutWeb.API.V1.HealthControllerTest do } = Poison.decode!(request.resp_body) end end + + def api_v1_health_path(conn, action) do + "/api" <> Helpers.api_v1_health_path(conn, action) + end end diff --git a/apps/block_scout_web/test/block_scout_web/controllers/api/v1/supply_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/api/v1/supply_controller_test.exs index 268169a21c..2ad2f41758 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/api/v1/supply_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/api/v1/supply_controller_test.exs @@ -1,6 +1,7 @@ defmodule BlockScoutWeb.API.V1.SupplyControllerTest do use BlockScoutWeb.ConnCase + alias BlockScoutWeb.ApiRouter.Helpers alias Explorer.Chain test "supply", %{conn: conn} do @@ -10,4 +11,8 @@ defmodule BlockScoutWeb.API.V1.SupplyControllerTest do assert response["total_supply"] == Chain.total_supply() assert response["circulating_supply"] == Chain.circulating_supply() end + + def api_v1_supply_path(conn, action) do + "/api" <> Helpers.api_v1_supply_path(conn, action) + end end diff --git a/apps/block_scout_web/test/block_scout_web/controllers/api/v1/verified_smart_contract_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/api/v1/verified_smart_contract_controller_test.exs index 2e51f42467..d11844e933 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/api/v1/verified_smart_contract_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/api/v1/verified_smart_contract_controller_test.exs @@ -1,6 +1,7 @@ defmodule BlockScoutWeb.API.V1.VerifiedControllerTest do use BlockScoutWeb.ConnCase + alias BlockScoutWeb.ApiRouter.Helpers alias Explorer.Factory # alias Explorer.Chain.DecompiledSmartContract @@ -69,4 +70,8 @@ defmodule BlockScoutWeb.API.V1.VerifiedControllerTest do assert response.status == 201 assert Jason.decode!(response.resp_body) == %{"status" => "success"} end + + def api_v1_verified_smart_contract_path(conn, action) do + "/api" <> Helpers.api_v1_verified_smart_contract_path(conn, action) + end end From a883d248ae60a0569e45990b0449c09c79c68e7b Mon Sep 17 00:00:00 2001 From: saneery Date: Wed, 17 Jul 2019 15:43:49 +0300 Subject: [PATCH 03/54] Split web app's endpoints into a new router --- apps/block_scout_web/config/config.exs | 1 + apps/block_scout_web/lib/block_scout_web.ex | 2 + .../lib/block_scout_web/router.ex | 232 ++---------------- .../lib/block_scout_web/web_router.ex | 207 ++++++++++++++++ 4 files changed, 232 insertions(+), 210 deletions(-) create mode 100644 apps/block_scout_web/lib/block_scout_web/web_router.ex diff --git a/apps/block_scout_web/config/config.exs b/apps/block_scout_web/config/config.exs index f99647694d..84f60a2842 100644 --- a/apps/block_scout_web/config/config.exs +++ b/apps/block_scout_web/config/config.exs @@ -87,6 +87,7 @@ config :wobserver, mode: :plug config :block_scout_web, BlockScoutWeb.ApiRouter, enabled: System.get_env("DISABLE_API") != "true" +config :block_scout_web, BlockScoutWeb.WebRouter, enabled: System.get_env("DISABLE_WEBAPP") != "true" # Import environment specific config. This must remain at the bottom # of this file so it overrides the configuration defined above. diff --git a/apps/block_scout_web/lib/block_scout_web.ex b/apps/block_scout_web/lib/block_scout_web.ex index 4e1f857526..7cbe856f5f 100644 --- a/apps/block_scout_web/lib/block_scout_web.ex +++ b/apps/block_scout_web/lib/block_scout_web.ex @@ -24,6 +24,7 @@ defmodule BlockScoutWeb do import BlockScoutWeb.Controller import BlockScoutWeb.Router.Helpers + import BlockScoutWeb.WebRouter.Helpers, except: [static_path: 2] import BlockScoutWeb.Gettext import BlockScoutWeb.ErrorHelpers import Plug.Conn @@ -54,6 +55,7 @@ defmodule BlockScoutWeb do Views.ScriptHelpers, WeiHelpers } + import BlockScoutWeb.WebRouter.Helpers, except: [static_path: 2] import PhoenixFormAwesomplete end diff --git a/apps/block_scout_web/lib/block_scout_web/router.ex b/apps/block_scout_web/lib/block_scout_web/router.ex index f52493d25c..e522ce842e 100644 --- a/apps/block_scout_web/lib/block_scout_web/router.ex +++ b/apps/block_scout_web/lib/block_scout_web/router.ex @@ -3,32 +3,6 @@ defmodule BlockScoutWeb.Router do alias BlockScoutWeb.Plug.GraphQL - forward("/wobserver", Wobserver.Web.Router) - forward("/admin", BlockScoutWeb.AdminRouter) - - if Application.get_env(:block_scout_web, BlockScoutWeb.ApiRouter, :enabled) do - forward("/api", BlockScoutWeb.ApiRouter) - end - - # For backward compatibility. Should be removed - # Needs to be 200 to support the schema introspection for graphiql - @max_complexity 200 - - forward("/graphql", Absinthe.Plug, - schema: BlockScoutWeb.Schema, - analyze_complexity: true, - max_complexity: @max_complexity - ) - - forward("/graphiql", Absinthe.Plug.GraphiQL, - schema: BlockScoutWeb.Schema, - interface: :advanced, - default_query: GraphQL.default_query(), - socket: BlockScoutWeb.UserSocket, - analyze_complexity: true, - max_complexity: @max_complexity - ) - pipeline :browser do plug(:accepts, ["html"]) plug(:fetch_session) @@ -37,196 +11,34 @@ defmodule BlockScoutWeb.Router do plug(BlockScoutWeb.CSPHeader) end - # Disallows Iframes (write routes) - scope "/", BlockScoutWeb do - pipe_through(:browser) - end + forward("/wobserver", Wobserver.Web.Router) + forward("/admin", BlockScoutWeb.AdminRouter) - # Allows Iframes (read-only routes) - scope "/", BlockScoutWeb do - pipe_through([:browser, BlockScoutWeb.Plug.AllowIframe]) + if Application.get_env(:block_scout_web, BlockScoutWeb.ApiRouter, :enabled) do + forward("/api", BlockScoutWeb.ApiRouter) - resources("/", ChainController, only: [:show], singleton: true, as: :chain) + # For backward compatibility. Should be removed + # Needs to be 200 to support the schema introspection for graphiql + @max_complexity 200 - resources("/market_history_chart", Chain.MarketHistoryChartController, - only: [:show], - singleton: true + forward("/graphql", Absinthe.Plug, + schema: BlockScoutWeb.Schema, + analyze_complexity: true, + max_complexity: @max_complexity ) - 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 + forward("/graphiql", Absinthe.Plug.GraphiQL, + schema: BlockScoutWeb.Schema, + interface: :advanced, + default_query: GraphQL.default_query(), + socket: BlockScoutWeb.UserSocket, + analyze_complexity: true, + max_complexity: @max_complexity ) + end - 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("/api_docs", APIDocsController, :index) - get("/eth_rpc_api_docs", APIDocsController, :eth_rpc) - - get("/:page", PageNotFoundController, :index) + if Application.get_env(:block_scout_web, BlockScoutWeb.WebRouter, :enabled) do + forward("/", BlockScoutWeb.WebRouter) end + end diff --git a/apps/block_scout_web/lib/block_scout_web/web_router.ex b/apps/block_scout_web/lib/block_scout_web/web_router.ex new file mode 100644 index 0000000000..9b250332db --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/web_router.ex @@ -0,0 +1,207 @@ +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("/api_docs", APIDocsController, :index) + get("/eth_rpc_api_docs", APIDocsController, :eth_rpc) + + get("/:page", PageNotFoundController, :index) + end +end From d3c60b0ec5fd7accac278c685124f1ea5c8ddef3 Mon Sep 17 00:00:00 2001 From: saneery Date: Wed, 17 Jul 2019 15:44:50 +0300 Subject: [PATCH 04/54] Update test to work with a new web app's router --- .../controllers/address_contract_controller_test.exs | 2 +- .../address_internal_transaction_controller_test.exs | 2 +- .../controllers/address_token_controller_test.exs | 2 +- .../controllers/address_token_transfer_controller_test.exs | 2 +- .../controllers/address_transaction_controller_test.exs | 2 +- .../block_scout_web/controllers/api_docs_controller_test.exs | 2 +- .../controllers/block_transaction_controller_test.exs | 2 +- .../test/block_scout_web/controllers/chain_controller_test.exs | 2 +- .../controllers/pending_transaction_controller_test.exs | 2 +- .../controllers/recent_transactions_controller_test.exs | 2 +- .../block_scout_web/controllers/transaction_controller_test.exs | 2 +- .../transaction_internal_transaction_controller_test.exs | 2 +- .../controllers/transaction_log_controller_test.exs | 2 +- .../controllers/transaction_token_transfer_controller_test.exs | 2 +- .../block_scout_web/features/pages/transaction_logs_page.ex | 2 +- apps/block_scout_web/test/support/conn_case.ex | 1 + 16 files changed, 16 insertions(+), 15 deletions(-) diff --git a/apps/block_scout_web/test/block_scout_web/controllers/address_contract_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/address_contract_controller_test.exs index 3e3c92cb7f..3b62a40bd5 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/address_contract_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/address_contract_controller_test.exs @@ -1,7 +1,7 @@ defmodule BlockScoutWeb.AddressContractControllerTest do use BlockScoutWeb.ConnCase, async: true - import BlockScoutWeb.Router.Helpers, only: [address_contract_path: 3] + import BlockScoutWeb.WebRouter.Helpers, only: [address_contract_path: 3] alias Explorer.Chain.Hash alias Explorer.ExchangeRates.Token diff --git a/apps/block_scout_web/test/block_scout_web/controllers/address_internal_transaction_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/address_internal_transaction_controller_test.exs index 8f5bc9a667..90b0c6500f 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/address_internal_transaction_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/address_internal_transaction_controller_test.exs @@ -1,7 +1,7 @@ defmodule BlockScoutWeb.AddressInternalTransactionControllerTest do use BlockScoutWeb.ConnCase, async: true - import BlockScoutWeb.Router.Helpers, + import BlockScoutWeb.WebRouter.Helpers, only: [address_internal_transaction_path: 3, address_internal_transaction_path: 4] alias Explorer.Chain.{Block, InternalTransaction, Transaction} diff --git a/apps/block_scout_web/test/block_scout_web/controllers/address_token_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/address_token_controller_test.exs index 31a1c2c5cf..16df97b9fc 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/address_token_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/address_token_controller_test.exs @@ -1,7 +1,7 @@ defmodule BlockScoutWeb.AddressTokenControllerTest do use BlockScoutWeb.ConnCase, async: true - import BlockScoutWeb.Router.Helpers, only: [address_token_path: 3] + import BlockScoutWeb.WebRouter.Helpers, only: [address_token_path: 3] alias Explorer.Chain.{Token} diff --git a/apps/block_scout_web/test/block_scout_web/controllers/address_token_transfer_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/address_token_transfer_controller_test.exs index a7e29efd10..70a362b109 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/address_token_transfer_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/address_token_transfer_controller_test.exs @@ -1,7 +1,7 @@ defmodule BlockScoutWeb.AddressTokenTransferControllerTest do use BlockScoutWeb.ConnCase - import BlockScoutWeb.Router.Helpers, + import BlockScoutWeb.WebRouter.Helpers, only: [address_token_transfers_path: 4, address_token_transfers_path: 5] alias Explorer.Chain.{Address, Token} diff --git a/apps/block_scout_web/test/block_scout_web/controllers/address_transaction_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/address_transaction_controller_test.exs index a29d6b9be6..6476432e91 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/address_transaction_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/address_transaction_controller_test.exs @@ -1,7 +1,7 @@ defmodule BlockScoutWeb.AddressTransactionControllerTest do use BlockScoutWeb.ConnCase, async: true - import BlockScoutWeb.Router.Helpers, only: [address_transaction_path: 3, address_transaction_path: 4] + import BlockScoutWeb.WebRouter.Helpers, only: [address_transaction_path: 3, address_transaction_path: 4] alias Explorer.Chain.Transaction alias Explorer.ExchangeRates.Token diff --git a/apps/block_scout_web/test/block_scout_web/controllers/api_docs_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/api_docs_controller_test.exs index 3b2cb99ff0..4db9eccd6d 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/api_docs_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/api_docs_controller_test.exs @@ -1,7 +1,7 @@ defmodule BlockScoutWeb.APIDocsControllerTest do use BlockScoutWeb.ConnCase - import BlockScoutWeb.Router.Helpers, only: [api_docs_path: 2] + import BlockScoutWeb.WebRouter.Helpers, only: [api_docs_path: 2] describe "GET index/2" do test "renders documentation tiles for each API module#action", %{conn: conn} do diff --git a/apps/block_scout_web/test/block_scout_web/controllers/block_transaction_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/block_transaction_controller_test.exs index da159b6e6e..d76a2fcd1c 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/block_transaction_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/block_transaction_controller_test.exs @@ -1,7 +1,7 @@ defmodule BlockScoutWeb.BlockTransactionControllerTest do use BlockScoutWeb.ConnCase - import BlockScoutWeb.Router.Helpers, only: [block_transaction_path: 3] + import BlockScoutWeb.WebRouter.Helpers, only: [block_transaction_path: 3] describe "GET index/2" do test "with invalid block number", %{conn: conn} do diff --git a/apps/block_scout_web/test/block_scout_web/controllers/chain_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/chain_controller_test.exs index f902f15ad4..00a53689c8 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/chain_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/chain_controller_test.exs @@ -3,7 +3,7 @@ defmodule BlockScoutWeb.ChainControllerTest do # ETS table is shared in `Explorer.Counters.AddressesWithBalanceCounter` async: false - import BlockScoutWeb.Router.Helpers, only: [chain_path: 2, block_path: 3, transaction_path: 3, address_path: 3] + import BlockScoutWeb.WebRouter.Helpers, only: [chain_path: 2, block_path: 3, transaction_path: 3, address_path: 3] alias Explorer.Chain.Block alias Explorer.Counters.AddressesWithBalanceCounter diff --git a/apps/block_scout_web/test/block_scout_web/controllers/pending_transaction_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/pending_transaction_controller_test.exs index d632154294..b19bec2520 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/pending_transaction_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/pending_transaction_controller_test.exs @@ -2,7 +2,7 @@ defmodule BlockScoutWeb.PendingTransactionControllerTest do use BlockScoutWeb.ConnCase alias Explorer.Chain.{Hash, Transaction} - import BlockScoutWeb.Router.Helpers, only: [pending_transaction_path: 2, pending_transaction_path: 3] + import BlockScoutWeb.WebRouter.Helpers, only: [pending_transaction_path: 2, pending_transaction_path: 3] describe "GET index/2" do test "returns no transactions that are in a block", %{conn: conn} do diff --git a/apps/block_scout_web/test/block_scout_web/controllers/recent_transactions_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/recent_transactions_controller_test.exs index a35ea19491..0a2267f18c 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/recent_transactions_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/recent_transactions_controller_test.exs @@ -1,7 +1,7 @@ defmodule BlockScoutWeb.RecentTransactionsControllerTest do use BlockScoutWeb.ConnCase - import BlockScoutWeb.Router.Helpers, only: [recent_transactions_path: 2] + import BlockScoutWeb.WebRouter.Helpers, only: [recent_transactions_path: 2] alias Explorer.Chain.Hash diff --git a/apps/block_scout_web/test/block_scout_web/controllers/transaction_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/transaction_controller_test.exs index cd2e557f93..80e8b12b70 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/transaction_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/transaction_controller_test.exs @@ -1,7 +1,7 @@ defmodule BlockScoutWeb.TransactionControllerTest do use BlockScoutWeb.ConnCase - import BlockScoutWeb.Router.Helpers, + import BlockScoutWeb.WebRouter.Helpers, only: [transaction_path: 3, transaction_internal_transaction_path: 3, transaction_token_transfer_path: 3] alias Explorer.Chain.Transaction diff --git a/apps/block_scout_web/test/block_scout_web/controllers/transaction_internal_transaction_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/transaction_internal_transaction_controller_test.exs index 6b9a32d280..773b51a36c 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/transaction_internal_transaction_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/transaction_internal_transaction_controller_test.exs @@ -1,7 +1,7 @@ defmodule BlockScoutWeb.TransactionInternalTransactionControllerTest do use BlockScoutWeb.ConnCase - import BlockScoutWeb.Router.Helpers, only: [transaction_internal_transaction_path: 3] + import BlockScoutWeb.WebRouter.Helpers, only: [transaction_internal_transaction_path: 3] alias Explorer.Chain.InternalTransaction alias Explorer.ExchangeRates.Token diff --git a/apps/block_scout_web/test/block_scout_web/controllers/transaction_log_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/transaction_log_controller_test.exs index 05c7638d52..65142dd0ce 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/transaction_log_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/transaction_log_controller_test.exs @@ -1,7 +1,7 @@ defmodule BlockScoutWeb.TransactionLogControllerTest do use BlockScoutWeb.ConnCase - import BlockScoutWeb.Router.Helpers, only: [transaction_log_path: 3] + import BlockScoutWeb.WebRouter.Helpers, only: [transaction_log_path: 3] alias Explorer.ExchangeRates.Token diff --git a/apps/block_scout_web/test/block_scout_web/controllers/transaction_token_transfer_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/transaction_token_transfer_controller_test.exs index ca183f5289..6d3c83980b 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/transaction_token_transfer_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/transaction_token_transfer_controller_test.exs @@ -1,7 +1,7 @@ defmodule BlockScoutWeb.TransactionTokenTransferControllerTest do use BlockScoutWeb.ConnCase - import BlockScoutWeb.Router.Helpers, only: [transaction_token_transfer_path: 3] + import BlockScoutWeb.WebRouter.Helpers, only: [transaction_token_transfer_path: 3] alias Explorer.ExchangeRates.Token diff --git a/apps/block_scout_web/test/block_scout_web/features/pages/transaction_logs_page.ex b/apps/block_scout_web/test/block_scout_web/features/pages/transaction_logs_page.ex index bbb0c7c311..3969cd559c 100644 --- a/apps/block_scout_web/test/block_scout_web/features/pages/transaction_logs_page.ex +++ b/apps/block_scout_web/test/block_scout_web/features/pages/transaction_logs_page.ex @@ -4,7 +4,7 @@ defmodule BlockScoutWeb.TransactionLogsPage do use Wallaby.DSL import Wallaby.Query, only: [css: 1, css: 2] - import BlockScoutWeb.Router.Helpers, only: [transaction_log_path: 3] + import BlockScoutWeb.WebRouter.Helpers, only: [transaction_log_path: 3] alias Explorer.Chain.Transaction alias BlockScoutWeb.Endpoint diff --git a/apps/block_scout_web/test/support/conn_case.ex b/apps/block_scout_web/test/support/conn_case.ex index ca486b33c2..19b125e40a 100644 --- a/apps/block_scout_web/test/support/conn_case.ex +++ b/apps/block_scout_web/test/support/conn_case.ex @@ -20,6 +20,7 @@ defmodule BlockScoutWeb.ConnCase do # Import conveniences for testing with connections use Phoenix.ConnTest import BlockScoutWeb.Router.Helpers + import BlockScoutWeb.WebRouter.Helpers, except: [static_path: 2] # The default endpoint for testing @endpoint BlockScoutWeb.Endpoint From b717c37c0ba110960a9343b50754333b720c58b6 Mon Sep 17 00:00:00 2001 From: saneery Date: Wed, 17 Jul 2019 16:10:17 +0300 Subject: [PATCH 05/54] Fix failed contract verifications test --- apps/block_scout_web/lib/block_scout_web.ex | 1 + .../lib/block_scout_web/api_router.ex | 35 ++++++++++--------- .../lib/block_scout_web/router.ex | 5 ++- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/apps/block_scout_web/lib/block_scout_web.ex b/apps/block_scout_web/lib/block_scout_web.ex index 7cbe856f5f..20ca4351df 100644 --- a/apps/block_scout_web/lib/block_scout_web.ex +++ b/apps/block_scout_web/lib/block_scout_web.ex @@ -55,6 +55,7 @@ defmodule BlockScoutWeb do Views.ScriptHelpers, WeiHelpers } + import BlockScoutWeb.WebRouter.Helpers, except: [static_path: 2] import PhoenixFormAwesomplete diff --git a/apps/block_scout_web/lib/block_scout_web/api_router.ex b/apps/block_scout_web/lib/block_scout_web/api_router.ex index c40bd69e73..650188b6a2 100644 --- a/apps/block_scout_web/lib/block_scout_web/api_router.ex +++ b/apps/block_scout_web/lib/block_scout_web/api_router.ex @@ -11,28 +11,31 @@ defmodule BlockScoutWeb.ApiRouter do plug(:accepts, ["json"]) end - scope "/v1", BlockScoutWeb.API.V1, as: :api_v1 do + scope "/v1", as: :api_v1 do pipe_through(:api) - get("/supply", SupplyController, :supply) + post("/contract_verifications", BlockScoutWeb.AddressContractVerificationController, :create) - get("/health", HealthController, :health) + scope "/", BlockScoutWeb.API.V1 do + get("/supply", SupplyController, :supply) - post("/decompiled_smart_contract", DecompiledSmartContractController, :create) - post("/verified_smart_contracts", VerifiedSmartContractController, :create) - post("/contract_verifications", BlockScoutWeb.AddressContractVerificationController, :create) + get("/health", HealthController, :health) - post("/eth_rpc", EthController, :eth_request) + post("/decompiled_smart_contract", DecompiledSmartContractController, :create) + post("/verified_smart_contracts", VerifiedSmartContractController, :create) - forward("/", RPCTranslator, %{ - "block" => RPC.BlockController, - "account" => RPC.AddressController, - "logs" => RPC.LogsController, - "token" => RPC.TokenController, - "stats" => RPC.StatsController, - "contract" => RPC.ContractController, - "transaction" => RPC.TransactionController - }) + post("/eth_rpc", EthController, :eth_request) + + forward("/", RPCTranslator, %{ + "block" => RPC.BlockController, + "account" => RPC.AddressController, + "logs" => RPC.LogsController, + "token" => RPC.TokenController, + "stats" => RPC.StatsController, + "contract" => RPC.ContractController, + "transaction" => RPC.TransactionController + }) + end end # Needs to be 200 to support the schema introspection for graphiql diff --git a/apps/block_scout_web/lib/block_scout_web/router.ex b/apps/block_scout_web/lib/block_scout_web/router.ex index e522ce842e..1354c57d56 100644 --- a/apps/block_scout_web/lib/block_scout_web/router.ex +++ b/apps/block_scout_web/lib/block_scout_web/router.ex @@ -14,7 +14,7 @@ defmodule BlockScoutWeb.Router do forward("/wobserver", Wobserver.Web.Router) forward("/admin", BlockScoutWeb.AdminRouter) - if Application.get_env(:block_scout_web, BlockScoutWeb.ApiRouter, :enabled) do + if Application.get_env(:block_scout_web, BlockScoutWeb.ApiRouter)[:enabled] do forward("/api", BlockScoutWeb.ApiRouter) # For backward compatibility. Should be removed @@ -37,8 +37,7 @@ defmodule BlockScoutWeb.Router do ) end - if Application.get_env(:block_scout_web, BlockScoutWeb.WebRouter, :enabled) do + if Application.get_env(:block_scout_web, BlockScoutWeb.WebRouter)[:enabled] do forward("/", BlockScoutWeb.WebRouter) end - end From 9a7629765194cc8ce5c19462d22a7ab103e153e7 Mon Sep 17 00:00:00 2001 From: saneery Date: Thu, 18 Jul 2019 16:59:13 +0300 Subject: [PATCH 06/54] Update routers to hide and show api's docs --- .../lib/block_scout_web/api_router.ex | 21 -- .../lib/block_scout_web/router.ex | 46 +++- .../new.html.eex | 2 +- .../templates/layout/_topnav.html.eex | 204 +++++++++--------- .../address_contract_verification_view.ex | 5 - .../lib/block_scout_web/web_router.ex | 3 - .../api/v1/health_controller_test.exs | 6 - .../controllers/api_docs_controller_test.exs | 2 +- 8 files changed, 147 insertions(+), 142 deletions(-) diff --git a/apps/block_scout_web/lib/block_scout_web/api_router.ex b/apps/block_scout_web/lib/block_scout_web/api_router.ex index 650188b6a2..73386dd4fa 100644 --- a/apps/block_scout_web/lib/block_scout_web/api_router.ex +++ b/apps/block_scout_web/lib/block_scout_web/api_router.ex @@ -5,7 +5,6 @@ defmodule BlockScoutWeb.ApiRouter do use BlockScoutWeb, :router alias BlockScoutWeb.API.RPC - alias BlockScoutWeb.Plug.GraphQL pipeline :api do plug(:accepts, ["json"]) @@ -19,8 +18,6 @@ defmodule BlockScoutWeb.ApiRouter do scope "/", BlockScoutWeb.API.V1 do get("/supply", SupplyController, :supply) - get("/health", HealthController, :health) - post("/decompiled_smart_contract", DecompiledSmartContractController, :create) post("/verified_smart_contracts", VerifiedSmartContractController, :create) @@ -38,24 +35,6 @@ defmodule BlockScoutWeb.ApiRouter do end end - # Needs to be 200 to support the schema introspection for graphiql - @max_complexity 200 - - forward("/graphql", Absinthe.Plug, - schema: BlockScoutWeb.Schema, - analyze_complexity: true, - max_complexity: @max_complexity - ) - - forward("/graphiql", Absinthe.Plug.GraphiQL, - schema: BlockScoutWeb.Schema, - interface: :advanced, - default_query: GraphQL.default_query(), - socket: BlockScoutWeb.UserSocket, - analyze_complexity: true, - max_complexity: @max_complexity - ) - # For backward compatibility. Should be removed scope "/", BlockScoutWeb.API.RPC do pipe_through(:api) diff --git a/apps/block_scout_web/lib/block_scout_web/router.ex b/apps/block_scout_web/lib/block_scout_web/router.ex index 1354c57d56..62c6e09d91 100644 --- a/apps/block_scout_web/lib/block_scout_web/router.ex +++ b/apps/block_scout_web/lib/block_scout_web/router.ex @@ -2,6 +2,10 @@ defmodule BlockScoutWeb.Router do use BlockScoutWeb, :router alias BlockScoutWeb.Plug.GraphQL + alias BlockScoutWeb.{ApiRouter, WebRouter} + + forward("/wobserver", Wobserver.Web.Router) + forward("/admin", BlockScoutWeb.AdminRouter) pipeline :browser do plug(:accepts, ["html"]) @@ -11,13 +15,24 @@ defmodule BlockScoutWeb.Router do plug(BlockScoutWeb.CSPHeader) end - forward("/wobserver", Wobserver.Web.Router) - forward("/admin", BlockScoutWeb.AdminRouter) + pipeline :api do + plug(:accepts, ["json"]) + end + + scope "/", BlockScoutWeb.API.V1, as: :api_v1 do + pipe_through(:api) + get("/api/v1/health", HealthController, :health) + end - if Application.get_env(:block_scout_web, BlockScoutWeb.ApiRouter)[:enabled] do - forward("/api", BlockScoutWeb.ApiRouter) + scope "/verify_smart_contract" do + pipe_through(:api) + + post("/contract_verifications", BlockScoutWeb.AddressContractVerificationController, :create) + end + + if Application.get_env(:block_scout_web, ApiRouter)[:enabled] do + forward("/api", ApiRouter) - # For backward compatibility. Should be removed # Needs to be 200 to support the schema introspection for graphiql @max_complexity 200 @@ -35,9 +50,28 @@ defmodule BlockScoutWeb.Router do analyze_complexity: true, max_complexity: @max_complexity ) + else + scope "/", BlockScoutWeb do + pipe_through(:browser) + get("/api_docs", PageNotFoundController, :index) + get("/eth_rpc_api_docs", PageNotFoundController, :index) + end end - if Application.get_env(:block_scout_web, BlockScoutWeb.WebRouter)[:enabled] do + scope "/", BlockScoutWeb do + pipe_through(:browser) + + get("/api_docs", APIDocsController, :index) + get("/eth_rpc_api_docs", APIDocsController, :eth_rpc) + end + + if Application.get_env(:block_scout_web, WebRouter)[:enabled] do forward("/", BlockScoutWeb.WebRouter) + else + scope "/", BlockScoutWeb do + pipe_through(:browser) + + forward("/", APIDocsController, :index) + end end end diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_contract_verification/new.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_contract_verification/new.html.eex index a1a715a734..fd93b0af2b 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_contract_verification/new.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_contract_verification/new.html.eex @@ -9,7 +9,7 @@

<%= gettext "New Smart Contract Verification" %>

<%= form_for @changeset, - api_v1_address_contract_verification_path(@conn, :create), + address_contract_verification_path(@conn, :create), [], fn f -> %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex index f152ec6bf9..3ae4779284 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex @@ -8,79 +8,83 @@ - - - - + + <% end %> + <%= if Application.get_env(:block_scout_web, BlockScoutWeb.ApiRouter)[:enabled] do %> + + <% end %> -
- <%= form_for @conn, chain_path(@conn, :search), [class: "form-inline my-2 my-lg-0", method: :get, enforce_utf8: false], fn f -> %> -
- <%= awesomplete(f, :q, - [ - class: "form-control me auto", - placeholder: gettext("Search by address, token symbol name, transaction hash, or block number"), - "aria-describedby": "search-icon", - "aria-label": gettext("Search"), - "data-test": "search_input" - ], - [ url: "#{chain_path(@conn, :token_autocomplete)}?q=", - limit: 0, - minChars: 2, - value: "contract_address_hash", - label: "contract_address_hash", - descrSearch: true, - descr: "symbol" - ]) %> -
- -
-
- - <% end %> -
+ <%= if Application.get_env(:block_scout_web, BlockScoutWeb.WebRouter)[:enabled] do %> +
+ <%= form_for @conn, chain_path(@conn, :search), [class: "form-inline my-2 my-lg-0", method: :get, enforce_utf8: false], fn f -> %> +
+ <%= awesomplete(f, :q, + [ + class: "form-control me auto", + placeholder: gettext("Search by address, token symbol name, transaction hash, or block number"), + "aria-describedby": "search-icon", + "aria-label": gettext("Search"), + "data-test": "search_input" + ], + [ url: "#{chain_path(@conn, :token_autocomplete)}?q=", + limit: 0, + minChars: 2, + value: "contract_address_hash", + label: "contract_address_hash", + descrSearch: true, + descr: "symbol" + ]) %> +
+ +
+
+ + <% end %> +
+ <% end %> diff --git a/apps/block_scout_web/lib/block_scout_web/views/address_contract_verification_view.ex b/apps/block_scout_web/lib/block_scout_web/views/address_contract_verification_view.ex index b8e39ab547..874b470406 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/address_contract_verification_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/address_contract_verification_view.ex @@ -1,8 +1,3 @@ defmodule BlockScoutWeb.AddressContractVerificationView do use BlockScoutWeb, :view - alias BlockScoutWeb.ApiRouter.Helpers - - def api_v1_address_contract_verification_path(conn, action) do - "/api" <> Helpers.api_v1_address_contract_verification_path(conn, action) - end end diff --git a/apps/block_scout_web/lib/block_scout_web/web_router.ex b/apps/block_scout_web/lib/block_scout_web/web_router.ex index 9b250332db..6b445a7b41 100644 --- a/apps/block_scout_web/lib/block_scout_web/web_router.ex +++ b/apps/block_scout_web/lib/block_scout_web/web_router.ex @@ -199,9 +199,6 @@ defmodule BlockScoutWeb.WebRouter do get("/chain_blocks", ChainController, :chain_blocks, as: :chain_blocks) - get("/api_docs", APIDocsController, :index) - get("/eth_rpc_api_docs", APIDocsController, :eth_rpc) - get("/:page", PageNotFoundController, :index) end end diff --git a/apps/block_scout_web/test/block_scout_web/controllers/api/v1/health_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/api/v1/health_controller_test.exs index 53abd8b880..41735f685a 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/api/v1/health_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/api/v1/health_controller_test.exs @@ -1,8 +1,6 @@ defmodule BlockScoutWeb.API.V1.HealthControllerTest do use BlockScoutWeb.ConnCase - alias BlockScoutWeb.ApiRouter.Helpers - describe "GET last_block_status/0" do test "returns error when there are no blocks in db", %{conn: conn} do request = get(conn, api_v1_health_path(conn, :health)) @@ -49,8 +47,4 @@ defmodule BlockScoutWeb.API.V1.HealthControllerTest do } = Poison.decode!(request.resp_body) end end - - def api_v1_health_path(conn, action) do - "/api" <> Helpers.api_v1_health_path(conn, action) - end end diff --git a/apps/block_scout_web/test/block_scout_web/controllers/api_docs_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/api_docs_controller_test.exs index 4db9eccd6d..3b2cb99ff0 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/api_docs_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/api_docs_controller_test.exs @@ -1,7 +1,7 @@ defmodule BlockScoutWeb.APIDocsControllerTest do use BlockScoutWeb.ConnCase - import BlockScoutWeb.WebRouter.Helpers, only: [api_docs_path: 2] + import BlockScoutWeb.Router.Helpers, only: [api_docs_path: 2] describe "GET index/2" do test "renders documentation tiles for each API module#action", %{conn: conn} do From 3652aa2a46549a43ae2bab290506e467eefe349d Mon Sep 17 00:00:00 2001 From: saneery Date: Thu, 18 Jul 2019 17:03:57 +0300 Subject: [PATCH 07/54] Update gettext --- .../lib/block_scout_web/router.ex | 4 +-- apps/block_scout_web/priv/gettext/default.pot | 32 +++++++++---------- .../priv/gettext/en/LC_MESSAGES/default.po | 32 +++++++++---------- 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/apps/block_scout_web/lib/block_scout_web/router.ex b/apps/block_scout_web/lib/block_scout_web/router.ex index 62c6e09d91..3cbb8dd3bf 100644 --- a/apps/block_scout_web/lib/block_scout_web/router.ex +++ b/apps/block_scout_web/lib/block_scout_web/router.ex @@ -19,9 +19,9 @@ defmodule BlockScoutWeb.Router do plug(:accepts, ["json"]) end - scope "/", BlockScoutWeb.API.V1, as: :api_v1 do + scope "/api/v1", BlockScoutWeb.API.V1, as: :api_v1 do pipe_through(:api) - get("/api/v1/health", HealthController, :health) + get("/health", HealthController, :health) end scope "/verify_smart_contract" do diff --git a/apps/block_scout_web/priv/gettext/default.pot b/apps/block_scout_web/priv/gettext/default.pot index 8217a39d9c..021b81144e 100644 --- a/apps/block_scout_web/priv/gettext/default.pot +++ b/apps/block_scout_web/priv/gettext/default.pot @@ -87,7 +87,7 @@ msgid "API for the %{subnetwork} - BlockScout" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/layout/_topnav.html.eex:56 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:57 msgid "Accounts" msgstr "" @@ -178,8 +178,8 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/chain/show.html.eex:87 -#: lib/block_scout_web/templates/layout/_topnav.html.eex:16 -#: lib/block_scout_web/templates/layout/_topnav.html.eex:20 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:17 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:21 msgid "Blocks" msgstr "" @@ -400,7 +400,7 @@ msgid "Fetching tokens..." msgstr "" #, elixir-format -#: lib/block_scout_web/templates/layout/_topnav.html.eex:26 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:27 msgid "Forked Blocks (Reorgs)" msgstr "" @@ -602,7 +602,7 @@ msgid "Parent Hash" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/layout/_topnav.html.eex:44 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:45 #: lib/block_scout_web/views/transaction_view.ex:143 #: lib/block_scout_web/views/transaction_view.ex:177 msgid "Pending" @@ -667,8 +667,8 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address_logs/index.html.eex:14 -#: lib/block_scout_web/templates/layout/_topnav.html.eex:102 -#: lib/block_scout_web/templates/layout/_topnav.html.eex:119 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:107 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:124 msgid "Search" msgstr "" @@ -871,7 +871,7 @@ msgstr "" #: lib/block_scout_web/templates/block_transaction/index.html.eex:10 #: lib/block_scout_web/templates/block_transaction/index.html.eex:18 #: lib/block_scout_web/templates/chain/show.html.eex:108 -#: lib/block_scout_web/templates/layout/_topnav.html.eex:35 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:36 #: lib/block_scout_web/views/address_view.ex:305 msgid "Transactions" msgstr "" @@ -898,7 +898,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/block/overview.html.eex:80 -#: lib/block_scout_web/templates/layout/_topnav.html.eex:23 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:24 msgid "Uncles" msgstr "" @@ -913,7 +913,7 @@ msgid "Used" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/layout/_topnav.html.eex:39 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:40 msgid "Validated" msgstr "" @@ -1067,12 +1067,12 @@ msgid "Loading...." msgstr "" #, elixir-format -#: lib/block_scout_web/templates/layout/_topnav.html.eex:64 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:67 msgid "APIs" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/layout/_topnav.html.eex:68 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:71 msgid "GraphQL" msgstr "" @@ -1082,7 +1082,7 @@ msgid "Loading" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/layout/_topnav.html.eex:73 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:76 msgid "RPC" msgstr "" @@ -1481,8 +1481,8 @@ msgid "Error: Could not determine contract creator." msgstr "" #, elixir-format -#: lib/block_scout_web/templates/layout/_topnav.html.eex:96 -#: lib/block_scout_web/templates/layout/_topnav.html.eex:100 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:101 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:105 msgid "Search by address, token symbol name, transaction hash, or block number" msgstr "" @@ -1708,7 +1708,7 @@ msgid "ETH RPC API Documentation" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/layout/_topnav.html.eex:78 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:81 msgid "Eth RPC" msgstr "" diff --git a/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po b/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po index b58c06af59..abd5fcd3a3 100644 --- a/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po +++ b/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po @@ -87,7 +87,7 @@ msgid "API for the %{subnetwork} - BlockScout" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/layout/_topnav.html.eex:56 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:57 msgid "Accounts" msgstr "" @@ -178,8 +178,8 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/chain/show.html.eex:87 -#: lib/block_scout_web/templates/layout/_topnav.html.eex:16 -#: lib/block_scout_web/templates/layout/_topnav.html.eex:20 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:17 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:21 msgid "Blocks" msgstr "" @@ -400,7 +400,7 @@ msgid "Fetching tokens..." msgstr "" #, elixir-format -#: lib/block_scout_web/templates/layout/_topnav.html.eex:26 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:27 msgid "Forked Blocks (Reorgs)" msgstr "" @@ -602,7 +602,7 @@ msgid "Parent Hash" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/layout/_topnav.html.eex:44 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:45 #: lib/block_scout_web/views/transaction_view.ex:143 #: lib/block_scout_web/views/transaction_view.ex:177 msgid "Pending" @@ -667,8 +667,8 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address_logs/index.html.eex:14 -#: lib/block_scout_web/templates/layout/_topnav.html.eex:102 -#: lib/block_scout_web/templates/layout/_topnav.html.eex:119 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:107 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:124 msgid "Search" msgstr "" @@ -871,7 +871,7 @@ msgstr "" #: lib/block_scout_web/templates/block_transaction/index.html.eex:10 #: lib/block_scout_web/templates/block_transaction/index.html.eex:18 #: lib/block_scout_web/templates/chain/show.html.eex:108 -#: lib/block_scout_web/templates/layout/_topnav.html.eex:35 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:36 #: lib/block_scout_web/views/address_view.ex:305 msgid "Transactions" msgstr "" @@ -898,7 +898,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/block/overview.html.eex:80 -#: lib/block_scout_web/templates/layout/_topnav.html.eex:23 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:24 msgid "Uncles" msgstr "" @@ -913,7 +913,7 @@ msgid "Used" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/layout/_topnav.html.eex:39 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:40 msgid "Validated" msgstr "" @@ -1067,12 +1067,12 @@ msgid "Loading...." msgstr "" #, elixir-format -#: lib/block_scout_web/templates/layout/_topnav.html.eex:64 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:67 msgid "APIs" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/layout/_topnav.html.eex:68 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:71 msgid "GraphQL" msgstr "" @@ -1082,7 +1082,7 @@ msgid "Loading" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/layout/_topnav.html.eex:73 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:76 msgid "RPC" msgstr "" @@ -1481,8 +1481,8 @@ msgid "Error: Could not determine contract creator." msgstr "" #, elixir-format -#: lib/block_scout_web/templates/layout/_topnav.html.eex:96 -#: lib/block_scout_web/templates/layout/_topnav.html.eex:100 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:101 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:105 msgid "Search by address, token symbol name, transaction hash, or block number" msgstr "" @@ -1708,7 +1708,7 @@ msgid "ETH RPC API Documentation" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/layout/_topnav.html.eex:78 +#: lib/block_scout_web/templates/layout/_topnav.html.eex:81 msgid "Eth RPC" msgstr "" From 16a280f7c5af7731bb39a23150efa320b57c4fee Mon Sep 17 00:00:00 2001 From: saneery Date: Mon, 22 Jul 2019 10:36:14 +0300 Subject: [PATCH 08/54] add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9c8934f3d..aed0547a76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## Current ### Features +- [#2376](https://github.com/poanetwork/blockscout/pull/2376) - Split API and WebApp routes - [#2379](https://github.com/poanetwork/blockscout/pull/2379) - Disable network selector when is empty - [#2360](https://github.com/poanetwork/blockscout/pull/2360) - add default evm version to smart contract verification - [#2352](https://github.com/poanetwork/blockscout/pull/2352) - Fetch rewards in parallel with transactions From c7e835178165fffadb3155c68139397940c9ce4c Mon Sep 17 00:00:00 2001 From: saneery Date: Mon, 22 Jul 2019 15:26:57 +0300 Subject: [PATCH 09/54] Return gasPrice at gettxinfo API's method --- apps/block_scout_web/lib/block_scout_web/etherscan.ex | 2 ++ .../lib/block_scout_web/views/api/rpc/transaction_view.ex | 1 + .../controllers/api/rpc/transaction_controller_test.exs | 1 + 3 files changed, 4 insertions(+) diff --git a/apps/block_scout_web/lib/block_scout_web/etherscan.ex b/apps/block_scout_web/lib/block_scout_web/etherscan.ex index 2191a86fa2..73f1967900 100644 --- a/apps/block_scout_web/lib/block_scout_web/etherscan.ex +++ b/apps/block_scout_web/lib/block_scout_web/etherscan.ex @@ -440,6 +440,7 @@ defmodule BlockScoutWeb.Etherscan do "from" => "0x000000000000000000000000000000000000000c", "gasLimit" => "91966", "gasUsed" => "95123", + "gasPrice" => "100000", "hash" => "0x0000000000000000000000000000000000000000000000000000000000000004", "input" => "0x04", "logs" => [ @@ -986,6 +987,7 @@ defmodule BlockScoutWeb.Etherscan do input: @input_type, gasLimit: @wei_type, gasUsed: @gas_type, + gasPrice: @wei_type, logs: %{ type: "array", array_type: @logs_details diff --git a/apps/block_scout_web/lib/block_scout_web/views/api/rpc/transaction_view.ex b/apps/block_scout_web/lib/block_scout_web/views/api/rpc/transaction_view.ex index e792be8f40..b9e8f7430d 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/api/rpc/transaction_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/api/rpc/transaction_view.ex @@ -68,6 +68,7 @@ defmodule BlockScoutWeb.API.RPC.TransactionView do "input" => "#{transaction.input}", "gasLimit" => "#{transaction.gas}", "gasUsed" => "#{transaction.gas_used}", + "gasPrice" => "#{transaction.gas_price.value}", "logs" => Enum.map(logs, &prepare_log/1), "next_page_params" => next_page_params } diff --git a/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/transaction_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/transaction_controller_test.exs index 9d151e382c..1ac026bc3c 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/transaction_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/api/rpc/transaction_controller_test.exs @@ -456,6 +456,7 @@ defmodule BlockScoutWeb.API.RPC.TransactionControllerTest do "input" => "#{transaction.input}", "gasLimit" => "#{transaction.gas}", "gasUsed" => "#{transaction.gas_used}", + "gasPrice" => "#{transaction.gas_price.value}", "logs" => [ %{ "address" => "#{address.hash}", From 04c72f71d792c9f692461e0f79b6d232734a121f Mon Sep 17 00:00:00 2001 From: saneery Date: Mon, 22 Jul 2019 15:32:40 +0300 Subject: [PATCH 10/54] add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9c8934f3d..75a5e56e6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## Current ### Features +- [#2403](https://github.com/poanetwork/blockscout/pull/2403) - Return gasPrice field at the result of gettxinfo method - [#2379](https://github.com/poanetwork/blockscout/pull/2379) - Disable network selector when is empty - [#2360](https://github.com/poanetwork/blockscout/pull/2360) - add default evm version to smart contract verification - [#2352](https://github.com/poanetwork/blockscout/pull/2352) - Fetch rewards in parallel with transactions From 1e4de6e41e2936dd4629f70e72f5dde95972698c Mon Sep 17 00:00:00 2001 From: saneery Date: Tue, 23 Jul 2019 12:07:09 +0300 Subject: [PATCH 11/54] Add env to disable indexer supervisor --- apps/indexer/config/config.exs | 2 ++ apps/indexer/lib/indexer/application.ex | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/apps/indexer/config/config.exs b/apps/indexer/config/config.exs index 4e84e9bcfe..b01a09c450 100644 --- a/apps/indexer/config/config.exs +++ b/apps/indexer/config/config.exs @@ -41,6 +41,8 @@ config :indexer, # config :indexer, Indexer.Fetcher.BlockReward.Supervisor, disabled?: true config :indexer, Indexer.Fetcher.StakingPools.Supervisor, disabled?: true +config :indexer, Indexer.Supervisor, enabled: System.get_env("DISABLE_INDEXER") != "true" + config :indexer, Indexer.Tracer, service: :indexer, adapter: SpandexDatadog.Adapter, diff --git a/apps/indexer/lib/indexer/application.ex b/apps/indexer/lib/indexer/application.ex index cb696567b7..f261ba8057 100644 --- a/apps/indexer/lib/indexer/application.ex +++ b/apps/indexer/lib/indexer/application.ex @@ -17,11 +17,17 @@ defmodule Indexer.Application do memory_monitor_name = Memory.Monitor - children = [ - {Memory.Monitor, [memory_monitor_options, [name: memory_monitor_name]]}, - {Indexer.Supervisor, [%{memory_monitor: memory_monitor_name}]} + base_children = [ + {Memory.Monitor, [memory_monitor_options, [name: memory_monitor_name]]} ] + children = + if Application.get_env(:indexer, Indexer.Supervisor)[:enabled] do + Enum.reverse([{Indexer.Supervisor, [%{memory_monitor: memory_monitor_name}]} | base_children]) + else + base_children + end + opts = [ # If the `Memory.Monitor` dies, it needs all the `Shrinkable`s to re-register, so restart them. strategy: :rest_for_one, From 8584a7fc28e84e19d18de9b11933c14d1532697f Mon Sep 17 00:00:00 2001 From: saneery Date: Mon, 29 Jul 2019 10:49:10 +0300 Subject: [PATCH 12/54] Disable market history cataloger with indexer --- apps/explorer/config/config.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/explorer/config/config.exs b/apps/explorer/config/config.exs index fed5124a2a..f20d704135 100644 --- a/apps/explorer/config/config.exs +++ b/apps/explorer/config/config.exs @@ -51,7 +51,7 @@ config :explorer, Explorer.KnownTokens, enabled: true, store: :ets config :explorer, Explorer.Integrations.EctoLogger, query_time_ms_threshold: :timer.seconds(2) -config :explorer, Explorer.Market.History.Cataloger, enabled: true +config :explorer, Explorer.Market.History.Cataloger, enabled: System.get_env("DISABLE_INDEXER") != "true" config :explorer, Explorer.Repo, migration_timestamps: [type: :utc_datetime_usec] From c09766e7922be147022c4770bb0c50dd31f6b680 Mon Sep 17 00:00:00 2001 From: saneery Date: Mon, 29 Jul 2019 11:09:23 +0300 Subject: [PATCH 13/54] Disable MetadataProcessor with indexer --- apps/explorer/config/config.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/explorer/config/config.exs b/apps/explorer/config/config.exs index f20d704135..1ceed7c387 100644 --- a/apps/explorer/config/config.exs +++ b/apps/explorer/config/config.exs @@ -65,7 +65,7 @@ if System.get_env("METADATA_CONTRACT") && System.get_env("VALIDATORS_CONTRACT") metadata_contract_address: System.get_env("METADATA_CONTRACT"), validators_contract_address: System.get_env("VALIDATORS_CONTRACT") - config :explorer, Explorer.Validator.MetadataProcessor, enabled: true + config :explorer, Explorer.Validator.MetadataProcessor, enabled: System.get_env("DISABLE_INDEXER") != "true" else config :explorer, Explorer.Validator.MetadataProcessor, enabled: false end From 60be9a8a5fc3acf82bc03d914747bd14ea989cbe Mon Sep 17 00:00:00 2001 From: saneery Date: Mon, 29 Jul 2019 11:48:12 +0300 Subject: [PATCH 14/54] Add WEBAPP_URL var --- apps/block_scout_web/config/config.exs | 3 ++- .../templates/layout/_footer.html.eex | 2 +- .../templates/layout/_topnav.html.eex | 2 +- .../lib/block_scout_web/views/layout_view.ex | 19 +++++++++++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/apps/block_scout_web/config/config.exs b/apps/block_scout_web/config/config.exs index 84f60a2842..ff842fd294 100644 --- a/apps/block_scout_web/config/config.exs +++ b/apps/block_scout_web/config/config.exs @@ -28,7 +28,8 @@ config :block_scout_web, "EtherChain" => "https://www.etherchain.org/", "Bloxy" => "https://bloxy.info/" }, - other_networks: System.get_env("SUPPORTED_CHAINS") + other_networks: System.get_env("SUPPORTED_CHAINS"), + webapp_url: System.get_env("WEBAPP_URL") config :block_scout_web, BlockScoutWeb.Counters.BlocksIndexedCounter, enabled: true diff --git a/apps/block_scout_web/lib/block_scout_web/templates/layout/_footer.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/layout/_footer.html.eex index 9d84836a5a..999a39ed11 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/layout/_footer.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/layout/_footer.html.eex @@ -3,7 +3,7 @@