From 44cd19a178fa3bcc054d702a0c8a795db2ea5cfb Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Fri, 19 Jul 2019 11:23:54 +0300 Subject: [PATCH 01/14] fix not existing keys in transaction json rpc --- .../lib/ethereum_jsonrpc/transaction.ex | 7 ++++++- .../test/ethereum_jsonrpc/transaction_test.exs | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/transaction.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/transaction.ex index f021bfa153..8bcaedf1b4 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/transaction.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/transaction.ex @@ -14,7 +14,8 @@ defmodule EthereumJSONRPC.Transaction do alias EthereumJSONRPC @type elixir :: %{ - String.t() => EthereumJSONRPC.address() | EthereumJSONRPC.hash() | String.t() | non_neg_integer() | nil + String.t() + | nil => EthereumJSONRPC.address() | EthereumJSONRPC.hash() | String.t() | non_neg_integer() | nil } @typedoc """ @@ -353,4 +354,8 @@ defmodule EthereumJSONRPC.Transaction do _ -> {key, quantity_to_integer(chain_id)} end end + + defp entry_to_elixir(_) do + {nil, nil} + end end diff --git a/apps/ethereum_jsonrpc/test/ethereum_jsonrpc/transaction_test.exs b/apps/ethereum_jsonrpc/test/ethereum_jsonrpc/transaction_test.exs index ad7780181d..a8a8fcdfd2 100644 --- a/apps/ethereum_jsonrpc/test/ethereum_jsonrpc/transaction_test.exs +++ b/apps/ethereum_jsonrpc/test/ethereum_jsonrpc/transaction_test.exs @@ -2,4 +2,14 @@ defmodule EthereumJSONRPC.TransactionTest do use ExUnit.Case, async: true doctest EthereumJSONRPC.Transaction + + alias EthereumJSONRPC.Transaction + + describe "to_elixir/1" do + test "skips unsupported keys" do + map = %{"key" => "value", "key1" => "value1"} + + assert %{nil: nil} = Transaction.to_elixir(map) + end + end end From dbbd81b60592d458201cdc83c30f437ffc7570b0 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Fri, 19 Jul 2019 11:25:39 +0300 Subject: [PATCH 02/14] add CHANGELOG entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9c8934f3d..783de20494 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - [#2294](https://github.com/poanetwork/blockscout/pull/2294) - add healthy block period checking endpoint ### Fixes +- [#2387](https://github.com/poanetwork/blockscout/pull/2387) - fix not existing keys in transaction json rpc - [#2378](https://github.com/poanetwork/blockscout/pull/2378) - Page performance: exclude moment.js localization files except EN, remove unused css - [#2368](https://github.com/poanetwork/blockscout/pull/2368) - add two columns of smart contract info - [#2375](https://github.com/poanetwork/blockscout/pull/2375) - Update created_contract_code_indexed_at on transaction import conflict From 9fb6bf1521d7a103bd040236b9321620902d916c Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Fri, 19 Jul 2019 11:34:18 +0300 Subject: [PATCH 03/14] fix build --- apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/transaction.ex | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/transaction.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/transaction.ex index 8bcaedf1b4..7992c0e63c 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/transaction.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/transaction.ex @@ -14,8 +14,7 @@ defmodule EthereumJSONRPC.Transaction do alias EthereumJSONRPC @type elixir :: %{ - String.t() - | nil => EthereumJSONRPC.address() | EthereumJSONRPC.hash() | String.t() | non_neg_integer() | nil + String.t() => EthereumJSONRPC.address() | EthereumJSONRPC.hash() | String.t() | non_neg_integer() | nil } @typedoc """ From ba2fb3557b776cbd72914b50937836af5957aec1 Mon Sep 17 00:00:00 2001 From: pasqu4le Date: Fri, 19 Jul 2019 14:01:52 +0200 Subject: [PATCH 04/14] Improve controllers queries Problem: after #2111, #2249, #2216 and #2305 a few remaining controllers still have not been checked for possible improvements. Solution: check them and remove unnecessary preloads and queries. --- .../address_contract_controller.ex | 12 +- .../address_read_contract_controller.ex | 12 +- .../controllers/api/rpc/block_controller.ex | 3 +- .../controllers/chain_controller.ex | 12 +- apps/explorer/lib/explorer/chain.ex | 47 ++++---- .../lib/explorer/smart_contract/reader.ex | 104 ++++++++++-------- apps/explorer/test/explorer/chain_test.exs | 14 ++- .../explorer/smart_contract/reader_test.exs | 2 +- 8 files changed, 131 insertions(+), 75 deletions(-) diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_controller.ex index bc4df8c4be..5db900b12b 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_contract_controller.ex @@ -8,8 +8,18 @@ defmodule BlockScoutWeb.AddressContractController do alias Indexer.Fetcher.CoinBalanceOnDemand def index(conn, %{"address_id" => address_hash_string}) do + address_options = [ + necessity_by_association: %{ + :contracts_creation_internal_transaction => :optional, + :names => :optional, + :smart_contract => :optional, + :token => :optional, + :contracts_creation_transaction => :optional + } + ] + with {:ok, address_hash} <- Chain.string_to_address_hash(address_hash_string), - {:ok, address} <- Chain.find_contract_address(address_hash) do + {:ok, address} <- Chain.find_contract_address(address_hash, address_options, true) do render( conn, "index.html", diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_read_contract_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_read_contract_controller.ex index d57aa30807..0849689dce 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_read_contract_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_read_contract_controller.ex @@ -15,8 +15,18 @@ defmodule BlockScoutWeb.AddressReadContractController do import BlockScoutWeb.AddressController, only: [transaction_count: 1, validation_count: 1] def index(conn, %{"address_id" => address_hash_string}) do + address_options = [ + necessity_by_association: %{ + :contracts_creation_internal_transaction => :optional, + :names => :optional, + :smart_contract => :optional, + :token => :optional, + :contracts_creation_transaction => :optional + } + ] + with {:ok, address_hash} <- Chain.string_to_address_hash(address_hash_string), - {:ok, address} <- Chain.find_contract_address(address_hash) do + {:ok, address} <- Chain.find_contract_address(address_hash, address_options, true) do render( conn, "index.html", diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/block_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/block_controller.ex index 91569a96da..16d73d420f 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/block_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/block_controller.ex @@ -8,8 +8,7 @@ defmodule BlockScoutWeb.API.RPC.BlockController do def getblockreward(conn, params) do with {:block_param, {:ok, unsafe_block_number}} <- {:block_param, Map.fetch(params, "blockno")}, {:ok, block_number} <- ChainWeb.param_to_block_number(unsafe_block_number), - block_options = [necessity_by_association: %{transactions: :optional}], - {:ok, block} <- Chain.number_to_block(block_number, block_options) do + {:ok, block} <- Chain.number_to_block(block_number) do reward = Chain.block_reward(block) render(conn, :block_reward, block: block, reward: reward) diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/chain_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/chain_controller.ex index 40a0fd3bbb..2c16cd1b03 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/chain_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/chain_controller.ex @@ -2,7 +2,7 @@ defmodule BlockScoutWeb.ChainController do use BlockScoutWeb, :controller alias BlockScoutWeb.ChainView - alias Explorer.{Chain, PagingOptions, Repo} + alias Explorer.{Chain, PagingOptions} alias Explorer.Chain.{Address, Block, Transaction} alias Explorer.Chain.Supply.RSK alias Explorer.Counters.AverageBlockTime @@ -72,9 +72,15 @@ defmodule BlockScoutWeb.ChainController do def chain_blocks(conn, _params) do if ajax?(conn) do blocks = - [paging_options: %PagingOptions{page_size: 4}] + [ + paging_options: %PagingOptions{page_size: 4}, + necessity_by_association: %{ + [miner: :names] => :optional, + :transactions => :optional, + :rewards => :optional + } + ] |> Chain.list_blocks() - |> Repo.preload([[miner: :names], :transactions, :rewards]) |> Enum.map(fn block -> %{ chain_block_html: diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 17116658bf..59836a90a6 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -930,29 +930,40 @@ defmodule Explorer.Chain do Repo.all(query) end - @spec find_contract_address(Hash.t()) :: {:ok, Address.t()} | {:error, :not_found} - def find_contract_address(%Hash{byte_count: unquote(Hash.Address.byte_count())} = hash) do + @doc """ + Finds an `t:Explorer.Chain.Address.t/0` that has the provided `t:Explorer.Chain.Address.t/0` `hash` and a contract. + + ## Options + + * `:necessity_by_association` - use to load `t:association/0` as `:required` or `:optional`. If an association is + `:required`, and the `t:Explorer.Chain.Address.t/0` has no associated record for that association, + then the `t:Explorer.Chain.Address.t/0` will not be included in the list. + + Optionally it also accepts a boolean to fetch the `has_decompiled_code?` virtual field or not + + """ + @spec find_contract_address(Hash.Address.t(), [necessity_by_association_option], boolean()) :: + {:ok, Address.t()} | {:error, :not_found} + def find_contract_address( + %Hash{byte_count: unquote(Hash.Address.byte_count())} = hash, + options \\ [], + query_decompiled_code_flag \\ false + ) do + necessity_by_association = Keyword.get(options, :necessity_by_association, %{}) + query = from( address in Address, - preload: [ - :contracts_creation_internal_transaction, - :names, - :smart_contract, - :token, - :contracts_creation_transaction - ], where: address.hash == ^hash and not is_nil(address.contract_code) ) - query_with_decompiled_flag = with_decompiled_code_flag(query, hash) - - address = Repo.one(query_with_decompiled_flag) - - if address do - {:ok, address} - else - {:error, :not_found} + query + |> join_associations(necessity_by_association) + |> with_decompiled_code_flag(hash, query_decompiled_code_flag) + |> Repo.one() + |> case do + nil -> {:error, :not_found} + address -> {:ok, address} end end @@ -3276,8 +3287,6 @@ defmodule Explorer.Chain do defp staking_pool_filter(query, _), do: query - defp with_decompiled_code_flag(query, hash, use_option \\ true) - defp with_decompiled_code_flag(query, _hash, false), do: query defp with_decompiled_code_flag(query, hash, true) do diff --git a/apps/explorer/lib/explorer/smart_contract/reader.ex b/apps/explorer/lib/explorer/smart_contract/reader.ex index 72b40f55a4..cc3aae5e83 100644 --- a/apps/explorer/lib/explorer/smart_contract/reader.ex +++ b/apps/explorer/lib/explorer/smart_contract/reader.ex @@ -8,7 +8,7 @@ defmodule Explorer.SmartContract.Reader do alias EthereumJSONRPC.Contract alias Explorer.Chain - alias Explorer.Chain.Hash + alias Explorer.Chain.{Hash, SmartContract} @typedoc """ Map of functions to call with the values for the function to be called with. @@ -34,6 +34,8 @@ defmodule Explorer.SmartContract.Reader do @doc """ Queries the contract functions on the blockchain and returns the call results. + Optionally accepts the abi if it has already been fetched. + ## Examples Note that for this example to work the database must be up to date with the @@ -57,14 +59,20 @@ defmodule Explorer.SmartContract.Reader do ) # => %{"sum" => {:error, "Data overflow encoding int, data `abc` cannot fit in 256 bits"}} """ - @spec query_verified_contract(Hash.Address.t(), functions()) :: functions_results() - def query_verified_contract(address_hash, functions) do + @spec query_verified_contract(Hash.Address.t(), functions(), SmartContract.abi() | nil) :: functions_results() + def query_verified_contract(address_hash, functions, mabi \\ nil) do contract_address = Hash.to_string(address_hash) abi = - address_hash - |> Chain.address_hash_to_smart_contract() - |> Map.get(:abi) + case mabi do + nil -> + address_hash + |> Chain.address_hash_to_smart_contract() + |> Map.get(:abi) + + _ -> + mabi + end query_contract(contract_address, abi, functions) end @@ -156,41 +164,41 @@ defmodule Explorer.SmartContract.Reader do """ @spec read_only_functions(Hash.t()) :: [%{}] def read_only_functions(contract_address_hash) do - contract_address_hash - |> Chain.address_hash_to_smart_contract() - |> Map.get(:abi, []) - |> Enum.filter(& &1["constant"]) - |> fetch_current_value_from_blockchain(contract_address_hash, []) - |> Enum.reverse() - end - - def fetch_current_value_from_blockchain( - [%{"inputs" => []} = function | tail], - contract_address_hash, - acc - ) do - values = - fetch_from_blockchain(contract_address_hash, %{ - name: function["name"], - args: function["inputs"], - outputs: function["outputs"] - }) + abi = + contract_address_hash + |> Chain.address_hash_to_smart_contract() + |> Map.get(:abi) - formatted = Map.replace!(function, "outputs", values) + case abi do + nil -> + [] - fetch_current_value_from_blockchain(tail, contract_address_hash, [formatted | acc]) + _ -> + abi + |> Enum.filter(& &1["constant"]) + |> Enum.map(&fetch_current_value_from_blockchain(&1, abi, contract_address_hash)) + end end - def fetch_current_value_from_blockchain([function | tail], contract_address_hash, acc) do - values = link_outputs_and_values(%{}, Map.get(function, "outputs", []), function["name"]) + defp fetch_current_value_from_blockchain(function, abi, contract_address_hash) do + values = + case function do + %{"inputs" => []} -> + name = function["name"] + args = function["inputs"] + outputs = function["outputs"] + + contract_address_hash + |> query_verified_contract(%{name => normalize_args(args)}, abi) + |> link_outputs_and_values(outputs, name) - formatted = Map.replace!(function, "outputs", values) + _ -> + link_outputs_and_values(%{}, Map.get(function, "outputs", []), function["name"]) + end - fetch_current_value_from_blockchain(tail, contract_address_hash, [formatted | acc]) + Map.replace!(function, "outputs", values) end - def fetch_current_value_from_blockchain([], _contract_address_hash, acc), do: acc - @doc """ Fetches the blockchain value of a function that requires arguments. """ @@ -201,23 +209,27 @@ defmodule Explorer.SmartContract.Reader do @spec query_function(Hash.t(), %{name: String.t(), args: [term()]}) :: [%{}] def query_function(contract_address_hash, %{name: name, args: args}) do - function = + abi = contract_address_hash |> Chain.address_hash_to_smart_contract() - |> Map.get(:abi, []) - |> Enum.filter(fn function -> function["name"] == name end) - |> List.first() - - fetch_from_blockchain(contract_address_hash, %{ - name: name, - args: args, - outputs: function["outputs"] - }) - end + |> Map.get(:abi) + + outputs = + case abi do + nil -> + nil + + _ -> + function = + abi + |> Enum.filter(fn function -> function["name"] == name end) + |> List.first() + + function["outputs"] + end - defp fetch_from_blockchain(contract_address_hash, %{name: name, args: args, outputs: outputs}) do contract_address_hash - |> query_verified_contract(%{name => normalize_args(args)}) + |> query_verified_contract(%{name => normalize_args(args)}, abi) |> link_outputs_and_values(outputs, name) end diff --git a/apps/explorer/test/explorer/chain_test.exs b/apps/explorer/test/explorer/chain_test.exs index 38e61dee7d..fc4f3eab85 100644 --- a/apps/explorer/test/explorer/chain_test.exs +++ b/apps/explorer/test/explorer/chain_test.exs @@ -2480,7 +2480,17 @@ defmodule Explorer.ChainTest do insert(:address, contract_code: Factory.data("contract_code"), smart_contract: nil, names: []) |> Repo.preload([:contracts_creation_internal_transaction, :contracts_creation_transaction, :token]) - response = Chain.find_contract_address(address.hash) + options = [ + necessity_by_association: %{ + :contracts_creation_internal_transaction => :optional, + :names => :optional, + :smart_contract => :optional, + :token => :optional, + :contracts_creation_transaction => :optional + } + ] + + response = Chain.find_contract_address(address.hash, options, true) assert response == {:ok, address} end @@ -2527,7 +2537,7 @@ defmodule Explorer.ChainTest do end test "with block without transactions", %{block: block, emission_reward: emission_reward} do - assert emission_reward.reward == Chain.block_reward(block) + assert emission_reward.reward == Chain.block_reward(block.number) end end diff --git a/apps/explorer/test/explorer/smart_contract/reader_test.exs b/apps/explorer/test/explorer/smart_contract/reader_test.exs index ab63b74d1e..82f0a54385 100644 --- a/apps/explorer/test/explorer/smart_contract/reader_test.exs +++ b/apps/explorer/test/explorer/smart_contract/reader_test.exs @@ -102,7 +102,7 @@ defmodule Explorer.SmartContract.ReaderTest do end end - describe "query_verified_contract/2" do + describe "query_verified_contract/3" do test "correctly returns the results of the smart contract functions" do hash = :smart_contract From d528d4d1f5857318c45ea1720fc4ba61843ff072 Mon Sep 17 00:00:00 2001 From: pasqu4le Date: Fri, 19 Jul 2019 14:41:00 +0200 Subject: [PATCH 05/14] Reduce chain function input to hashes (or ids) where possible Problem: a lot of function take an entity as an parameter, but only use its hash/id. This makes tracing the necessary scope of functions harder and is one of the cause for unnecessary queries/code execution. Solution: refactor these functions to take only a hash (or an id). --- .../controllers/api/rpc/block_controller.ex | 2 +- .../api/rpc/transaction_controller.ex | 2 +- .../block_transaction_controller.ex | 4 +- ...saction_internal_transaction_controller.ex | 2 +- .../controllers/transaction_log_controller.ex | 2 +- .../transaction_raw_trace_controller.ex | 2 +- .../transaction_token_transfer_controller.ex | 2 +- apps/explorer/lib/explorer/chain.ex | 48 ++++++---------- apps/explorer/test/explorer/chain_test.exs | 56 +++++++++---------- 9 files changed, 54 insertions(+), 66 deletions(-) diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/block_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/block_controller.ex index 16d73d420f..835e19bf3e 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/block_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/block_controller.ex @@ -9,7 +9,7 @@ defmodule BlockScoutWeb.API.RPC.BlockController do with {:block_param, {:ok, unsafe_block_number}} <- {:block_param, Map.fetch(params, "blockno")}, {:ok, block_number} <- ChainWeb.param_to_block_number(unsafe_block_number), {:ok, block} <- Chain.number_to_block(block_number) do - reward = Chain.block_reward(block) + reward = Chain.block_reward(block_number) render(conn, :block_reward, block: block, reward: reward) else diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/transaction_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/transaction_controller.ex index 344dbe1037..565ea4b6a5 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/transaction_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/transaction_controller.ex @@ -10,7 +10,7 @@ defmodule BlockScoutWeb.API.RPC.TransactionController do {:format, {:ok, transaction_hash}} <- to_transaction_hash(txhash_param), {:transaction, {:ok, transaction}} <- transaction_from_hash(transaction_hash), paging_options <- paging_options(params) do - logs = Chain.transaction_to_logs(transaction, paging_options) + logs = Chain.transaction_to_logs(transaction_hash, paging_options) {logs, next_page} = split_list_by_page(logs) render(conn, :gettxinfo, %{ diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/block_transaction_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/block_transaction_controller.ex index 15b06f1edd..a1e4cbeb09 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/block_transaction_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/block_transaction_controller.ex @@ -26,7 +26,7 @@ defmodule BlockScoutWeb.BlockTransactionController do paging_options(params) ) - transactions_plus_one = Chain.block_to_transactions(block, full_options) + transactions_plus_one = Chain.block_to_transactions(block.hash, full_options) {transactions, next_page} = split_list_by_page(transactions_plus_one) @@ -89,7 +89,7 @@ defmodule BlockScoutWeb.BlockTransactionController do :rewards => :optional } ) do - block_transaction_count = Chain.block_to_transaction_count(block) + block_transaction_count = Chain.block_to_transaction_count(block.hash) render( conn, diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_internal_transaction_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_internal_transaction_controller.ex index 159d144cdd..ae847b374d 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_internal_transaction_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_internal_transaction_controller.ex @@ -24,7 +24,7 @@ defmodule BlockScoutWeb.TransactionInternalTransactionController do paging_options(params) ) - internal_transactions_plus_one = Chain.transaction_to_internal_transactions(transaction, full_options) + internal_transactions_plus_one = Chain.transaction_to_internal_transactions(hash, full_options) {internal_transactions, next_page} = split_list_by_page(internal_transactions_plus_one) diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_log_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_log_controller.ex index 0a87d12493..a4bd12d66b 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_log_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_log_controller.ex @@ -22,7 +22,7 @@ defmodule BlockScoutWeb.TransactionLogController do paging_options(params) ) - logs_plus_one = Chain.transaction_to_logs(transaction, full_options) + logs_plus_one = Chain.transaction_to_logs(transaction_hash, full_options) {logs, next_page} = split_list_by_page(logs_plus_one) diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_raw_trace_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_raw_trace_controller.ex index 3d090e8a9b..250a6b4442 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_raw_trace_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_raw_trace_controller.ex @@ -19,7 +19,7 @@ defmodule BlockScoutWeb.TransactionRawTraceController do :token_transfers => :optional } ) do - internal_transactions = Chain.transaction_to_internal_transactions(transaction) + internal_transactions = Chain.transaction_to_internal_transactions(hash) render( conn, diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_token_transfer_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_token_transfer_controller.ex index cfb215da3e..5f4a9c8229 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_token_transfer_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_token_transfer_controller.ex @@ -24,7 +24,7 @@ defmodule BlockScoutWeb.TransactionTokenTransferController do paging_options(params) ) - token_transfers_plus_one = Chain.transaction_to_token_transfers(transaction, full_options) + token_transfers_plus_one = Chain.transaction_to_token_transfers(hash, full_options) {token_transfers, next_page} = split_list_by_page(token_transfers_plus_one) diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 59836a90a6..2c40f6bbc1 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -364,8 +364,8 @@ defmodule Explorer.Chain do Uncles are not currently accounted for. """ - @spec block_reward(Block.t()) :: Wei.t() - def block_reward(%Block{number: block_number}) do + @spec block_reward(Block.block_number()) :: Wei.t() + def block_reward(block_number) do query = from( block in Block, @@ -415,8 +415,8 @@ defmodule Explorer.Chain do `:key` (a tuple of the lowest/oldest `{index}`) and. Results will be the transactions older than the `index` that are passed. """ - @spec block_to_transactions(Block.t(), [paging_options | necessity_by_association_option]) :: [Transaction.t()] - def block_to_transactions(%Block{hash: block_hash}, options \\ []) when is_list(options) do + @spec block_to_transactions(Hash.Full.t(), [paging_options | necessity_by_association_option]) :: [Transaction.t()] + def block_to_transactions(block_hash, options \\ []) when is_list(options) do necessity_by_association = Keyword.get(options, :necessity_by_association, %{}) options @@ -432,8 +432,8 @@ defmodule Explorer.Chain do @doc """ Counts the number of `t:Explorer.Chain.Transaction.t/0` in the `block`. """ - @spec block_to_transaction_count(Block.t()) :: non_neg_integer() - def block_to_transaction_count(%Block{hash: block_hash}) do + @spec block_to_transaction_count(Hash.Full.t()) :: non_neg_integer() + def block_to_transaction_count(block_hash) do query = from( transaction in Transaction, @@ -843,7 +843,7 @@ defmodule Explorer.Chain do Returns `{:error, :not_found}` if there is no address by that hash present. Returns `{:error, :no_balance}` if there is no balance for that address at that block. """ - @spec get_balance_as_of_block(Hash.Address.t(), integer | :earliest | :latest | :pending) :: + @spec get_balance_as_of_block(Hash.Address.t(), Block.block_number() | :earliest | :latest | :pending) :: {:ok, Wei.t()} | {:error, :no_balance} | {:error, :not_found} def get_balance_as_of_block(address, block) when is_integer(block) do coin_balance_query = @@ -967,7 +967,7 @@ defmodule Explorer.Chain do end end - @spec find_decompiled_contract_address(Hash.t()) :: {:ok, Address.t()} | {:error, :not_found} + @spec find_decompiled_contract_address(Hash.Address.t()) :: {:ok, Address.t()} | {:error, :not_found} def find_decompiled_contract_address(%Hash{byte_count: unquote(Hash.Address.byte_count())} = hash) do query = from( @@ -2220,14 +2220,10 @@ defmodule Explorer.Chain do """ - @spec transaction_to_internal_transactions(Transaction.t(), [paging_options | necessity_by_association_option]) :: [ + @spec transaction_to_internal_transactions(Hash.Full.t(), [paging_options | necessity_by_association_option]) :: [ InternalTransaction.t() ] - def transaction_to_internal_transactions( - %Transaction{hash: %Hash{byte_count: unquote(Hash.Full.byte_count())} = hash}, - options \\ [] - ) - when is_list(options) do + def transaction_to_internal_transactions(hash, options \\ []) when is_list(options) do necessity_by_association = Keyword.get(options, :necessity_by_association, %{}) paging_options = Keyword.get(options, :paging_options, @default_paging_options) @@ -2255,12 +2251,8 @@ defmodule Explorer.Chain do the `index` that are passed. """ - @spec transaction_to_logs(Transaction.t(), [paging_options | necessity_by_association_option]) :: [Log.t()] - def transaction_to_logs( - %Transaction{hash: %Hash{byte_count: unquote(Hash.Full.byte_count())} = transaction_hash}, - options \\ [] - ) - when is_list(options) do + @spec transaction_to_logs(Hash.Full.t(), [paging_options | necessity_by_association_option]) :: [Log.t()] + def transaction_to_logs(transaction_hash, options \\ []) when is_list(options) do necessity_by_association = Keyword.get(options, :necessity_by_association, %{}) paging_options = Keyword.get(options, :paging_options, @default_paging_options) @@ -2287,14 +2279,10 @@ defmodule Explorer.Chain do the `index` that are passed. """ - @spec transaction_to_token_transfers(Transaction.t(), [paging_options | necessity_by_association_option]) :: [ + @spec transaction_to_token_transfers(Hash.Full.t(), [paging_options | necessity_by_association_option]) :: [ TokenTransfer.t() ] - def transaction_to_token_transfers( - %Transaction{hash: %Hash{byte_count: unquote(Hash.Full.byte_count())} = transaction_hash}, - options \\ [] - ) - when is_list(options) do + def transaction_to_token_transfers(transaction_hash, options \\ []) when is_list(options) do necessity_by_association = Keyword.get(options, :necessity_by_association, %{}) paging_options = Keyword.get(options, :paging_options, @default_paging_options) @@ -2521,16 +2509,16 @@ defmodule Explorer.Chain do |> repo.insert(on_conflict: :nothing, conflict_target: [:address_hash, :name]) end - @spec address_hash_to_address_with_source_code(%Explorer.Chain.Hash{}) :: %Explorer.Chain.Address{} | nil - def address_hash_to_address_with_source_code(%Explorer.Chain.Hash{} = address_hash) do + @spec address_hash_to_address_with_source_code(Hash.Address.t()) :: Address.t() | nil + def address_hash_to_address_with_source_code(address_hash) do case Repo.get(Address, address_hash) do nil -> nil address -> Repo.preload(address, [:smart_contract, :decompiled_smart_contracts]) end end - @spec address_hash_to_smart_contract(%Explorer.Chain.Hash{}) :: %Explorer.Chain.SmartContract{} | nil - def address_hash_to_smart_contract(%Explorer.Chain.Hash{} = address_hash) do + @spec address_hash_to_smart_contract(Hash.Address.t()) :: SmartContract.t() | nil + def address_hash_to_smart_contract(address_hash) do query = from( smart_contract in SmartContract, diff --git a/apps/explorer/test/explorer/chain_test.exs b/apps/explorer/test/explorer/chain_test.exs index fc4f3eab85..5ee506982b 100644 --- a/apps/explorer/test/explorer/chain_test.exs +++ b/apps/explorer/test/explorer/chain_test.exs @@ -630,7 +630,7 @@ defmodule Explorer.ChainTest do assert Repo.aggregate(Transaction, :count, :hash) == 0 - assert [] = Chain.block_to_transactions(block) + assert [] = Chain.block_to_transactions(block.hash) end test "with transactions" do @@ -639,7 +639,7 @@ defmodule Explorer.ChainTest do |> insert() |> with_block() - assert [%Transaction{hash: ^transaction_hash}] = Chain.block_to_transactions(block) + assert [%Transaction{hash: ^transaction_hash}] = Chain.block_to_transactions(block.hash) end test "with transactions can be paginated by {index}" do @@ -657,7 +657,7 @@ defmodule Explorer.ChainTest do |> with_block(block) assert second_page_hashes == - block + block.hash |> Chain.block_to_transactions(paging_options: %PagingOptions{key: {index}, page_size: 50}) |> Enum.map(& &1.hash) |> Enum.reverse() @@ -683,7 +683,7 @@ defmodule Explorer.ChainTest do token: token ) - fetched_transaction = List.first(Explorer.Chain.block_to_transactions(block)) + fetched_transaction = List.first(Explorer.Chain.block_to_transactions(block.hash)) assert fetched_transaction.hash == transaction.hash assert length(fetched_transaction.token_transfers) == 2 end @@ -693,7 +693,7 @@ defmodule Explorer.ChainTest do test "without transactions" do block = insert(:block) - assert Chain.block_to_transaction_count(block) == 0 + assert Chain.block_to_transaction_count(block.hash) == 0 end test "with transactions" do @@ -702,7 +702,7 @@ defmodule Explorer.ChainTest do |> insert() |> with_block() - assert Chain.block_to_transaction_count(block) == 1 + assert Chain.block_to_transaction_count(block.hash) == 1 end end @@ -2090,7 +2090,7 @@ defmodule Explorer.ChainTest do test "with transaction without internal transactions" do transaction = insert(:transaction) - assert [] = Chain.transaction_to_internal_transactions(transaction) + assert [] = Chain.transaction_to_internal_transactions(transaction.hash) end test "with transaction with internal transactions returns all internal transactions for a given transaction hash" do @@ -2117,7 +2117,7 @@ defmodule Explorer.ChainTest do transaction_index: transaction.index ) - results = [internal_transaction | _] = Chain.transaction_to_internal_transactions(transaction) + results = [internal_transaction | _] = Chain.transaction_to_internal_transactions(transaction.hash) assert 2 == length(results) @@ -2151,7 +2151,7 @@ defmodule Explorer.ChainTest do to_address: %Ecto.Association.NotLoaded{}, transaction: %Transaction{block: %Ecto.Association.NotLoaded{}} } - ] = Chain.transaction_to_internal_transactions(transaction) + ] = Chain.transaction_to_internal_transactions(transaction.hash) assert [ %InternalTransaction{ @@ -2161,7 +2161,7 @@ defmodule Explorer.ChainTest do } ] = Chain.transaction_to_internal_transactions( - transaction, + transaction.hash, necessity_by_association: %{ :from_address => :optional, :to_address => :optional, @@ -2183,7 +2183,7 @@ defmodule Explorer.ChainTest do transaction_index: transaction.index ) - result = Chain.transaction_to_internal_transactions(transaction) + result = Chain.transaction_to_internal_transactions(transaction.hash) assert Enum.empty?(result) end @@ -2202,7 +2202,7 @@ defmodule Explorer.ChainTest do transaction_index: transaction.index ) - actual = Enum.at(Chain.transaction_to_internal_transactions(transaction), 0) + actual = Enum.at(Chain.transaction_to_internal_transactions(transaction.hash), 0) assert {actual.transaction_hash, actual.index} == {expected.transaction_hash, expected.index} end @@ -2222,7 +2222,7 @@ defmodule Explorer.ChainTest do transaction_index: transaction.index ) - actual = Enum.at(Chain.transaction_to_internal_transactions(transaction), 0) + actual = Enum.at(Chain.transaction_to_internal_transactions(transaction.hash), 0) assert {actual.transaction_hash, actual.index} == {expected.transaction_hash, expected.index} end @@ -2243,7 +2243,7 @@ defmodule Explorer.ChainTest do transaction_index: transaction.index ) - actual = Enum.at(Chain.transaction_to_internal_transactions(transaction), 0) + actual = Enum.at(Chain.transaction_to_internal_transactions(transaction.hash), 0) assert {actual.transaction_hash, actual.index} == {expected.transaction_hash, expected.index} end @@ -2271,7 +2271,7 @@ defmodule Explorer.ChainTest do ) result = - transaction + transaction.hash |> Chain.transaction_to_internal_transactions() |> Enum.map(&{&1.transaction_hash, &1.index}) @@ -2301,17 +2301,17 @@ defmodule Explorer.ChainTest do ) assert [{first_transaction_hash, first_index}, {second_transaction_hash, second_index}] == - transaction + transaction.hash |> Chain.transaction_to_internal_transactions(paging_options: %PagingOptions{key: {-1}, page_size: 2}) |> Enum.map(&{&1.transaction_hash, &1.index}) assert [{first_transaction_hash, first_index}] == - transaction + transaction.hash |> Chain.transaction_to_internal_transactions(paging_options: %PagingOptions{key: {-1}, page_size: 1}) |> Enum.map(&{&1.transaction_hash, &1.index}) assert [{second_transaction_hash, second_index}] == - transaction + transaction.hash |> Chain.transaction_to_internal_transactions(paging_options: %PagingOptions{key: {0}, page_size: 2}) |> Enum.map(&{&1.transaction_hash, &1.index}) end @@ -2321,7 +2321,7 @@ defmodule Explorer.ChainTest do test "without logs" do transaction = insert(:transaction) - assert [] = Chain.transaction_to_logs(transaction) + assert [] = Chain.transaction_to_logs(transaction.hash) end test "with logs" do @@ -2332,7 +2332,7 @@ defmodule Explorer.ChainTest do %Log{transaction_hash: transaction_hash, index: index} = insert(:log, transaction: transaction) - assert [%Log{transaction_hash: ^transaction_hash, index: ^index}] = Chain.transaction_to_logs(transaction) + assert [%Log{transaction_hash: ^transaction_hash, index: ^index}] = Chain.transaction_to_logs(transaction.hash) end test "with logs can be paginated" do @@ -2349,7 +2349,7 @@ defmodule Explorer.ChainTest do |> Enum.map(& &1.index) assert second_page_indexes == - transaction + transaction.hash |> Chain.transaction_to_logs(paging_options: %PagingOptions{key: {log.index}, page_size: 50}) |> Enum.map(& &1.index) end @@ -2364,7 +2364,7 @@ defmodule Explorer.ChainTest do assert [%Log{address: %Address{}, transaction: %Transaction{}}] = Chain.transaction_to_logs( - transaction, + transaction.hash, necessity_by_association: %{ address: :optional, transaction: :optional @@ -2376,7 +2376,7 @@ defmodule Explorer.ChainTest do address: %Ecto.Association.NotLoaded{}, transaction: %Ecto.Association.NotLoaded{} } - ] = Chain.transaction_to_logs(transaction) + ] = Chain.transaction_to_logs(transaction.hash) end end @@ -2384,7 +2384,7 @@ defmodule Explorer.ChainTest do test "without token transfers" do transaction = insert(:transaction) - assert [] = Chain.transaction_to_token_transfers(transaction) + assert [] = Chain.transaction_to_token_transfers(transaction.hash) end test "with token transfers" do @@ -2397,7 +2397,7 @@ defmodule Explorer.ChainTest do insert(:token_transfer, transaction: transaction) assert [%TokenTransfer{transaction_hash: ^transaction_hash, log_index: ^log_index}] = - Chain.transaction_to_token_transfers(transaction) + Chain.transaction_to_token_transfers(transaction.hash) end test "token transfers necessity_by_association loads associations" do @@ -2410,7 +2410,7 @@ defmodule Explorer.ChainTest do assert [%TokenTransfer{token: %Token{}, transaction: %Transaction{}}] = Chain.transaction_to_token_transfers( - transaction, + transaction.hash, necessity_by_association: %{ token: :optional, transaction: :optional @@ -2422,7 +2422,7 @@ defmodule Explorer.ChainTest do token: %Ecto.Association.NotLoaded{}, transaction: %Ecto.Association.NotLoaded{} } - ] = Chain.transaction_to_token_transfers(transaction) + ] = Chain.transaction_to_token_transfers(transaction.hash) end end @@ -2533,7 +2533,7 @@ defmodule Explorer.ChainTest do |> Decimal.add(Decimal.new(3)) |> Wei.from(:wei) - assert expected == Chain.block_reward(block) + assert expected == Chain.block_reward(block.number) end test "with block without transactions", %{block: block, emission_reward: emission_reward} do From 2a7cfead5a43cd9d344015bd25901a99fd18d181 Mon Sep 17 00:00:00 2001 From: pasqu4le Date: Fri, 19 Jul 2019 17:28:06 +0200 Subject: [PATCH 06/14] Check only for existence when possible Problem: some controller retrieves entire entities from the database when it only needs to check their existence. Solution: provide Exploerer.Chain functions to check for existence and use them where possible. --- .../address_coin_balance_controller.ex | 6 +- .../controllers/address_logs_controller.ex | 8 +- .../decompiled_smart_contract_controller.ex | 21 +- .../v1/verified_smart_contract_controller.ex | 21 +- .../controllers/smart_contract_controller.ex | 4 +- .../controllers/transaction_controller.ex | 6 +- ...saction_internal_transaction_controller.ex | 6 +- .../transaction_token_transfer_controller.ex | 7 +- apps/explorer/lib/explorer/chain.ex | 199 ++++++++++++++++++ 9 files changed, 224 insertions(+), 54 deletions(-) diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_coin_balance_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_coin_balance_controller.ex index 33a01959c9..9267c0dcab 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_coin_balance_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_coin_balance_controller.ex @@ -16,7 +16,7 @@ defmodule BlockScoutWeb.AddressCoinBalanceController do def index(conn, %{"address_id" => address_hash_string, "type" => "JSON"} = params) do with {:ok, address_hash} <- Chain.string_to_address_hash(address_hash_string), - {:ok, address} <- Chain.hash_to_address(address_hash, [], false) do + :ok <- Chain.check_address_exists(address_hash) do full_options = paging_options(params) coin_balances_plus_one = Chain.address_to_coin_balances(address_hash, full_options) @@ -32,7 +32,7 @@ defmodule BlockScoutWeb.AddressCoinBalanceController do address_coin_balance_path( conn, :index, - address, + address_hash, Map.delete(next_page_params, "type") ) end @@ -52,7 +52,7 @@ defmodule BlockScoutWeb.AddressCoinBalanceController do :error -> unprocessable_entity(conn) - {:error, :not_found} -> + :not_found -> not_found(conn) end end diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_logs_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_logs_controller.ex index e349ecd9ef..9e05643187 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_logs_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_logs_controller.ex @@ -16,7 +16,7 @@ defmodule BlockScoutWeb.AddressLogsController do def index(conn, %{"address_id" => address_hash_string, "type" => "JSON"} = params) do with {:ok, address_hash} <- Chain.string_to_address_hash(address_hash_string), - {:ok, address} <- Chain.hash_to_address(address_hash, [], false) do + :ok <- Chain.check_address_exists(address_hash) do logs_plus_one = Chain.address_to_logs(address_hash, paging_options(params)) {results, next_page} = split_list_by_page(logs_plus_one) @@ -26,7 +26,7 @@ defmodule BlockScoutWeb.AddressLogsController do nil next_page_params -> - address_logs_path(conn, :index, address, Map.delete(next_page_params, "type")) + address_logs_path(conn, :index, address_hash, Map.delete(next_page_params, "type")) end items = @@ -74,7 +74,7 @@ defmodule BlockScoutWeb.AddressLogsController do def search_logs(conn, %{"topic" => topic, "address_id" => address_hash_string} = params) do with {:ok, address_hash} <- Chain.string_to_address_hash(address_hash_string), - {:ok, address} <- Chain.hash_to_address(address_hash, [], false) do + :ok <- Chain.check_address_exists(address_hash) do topic = String.trim(topic) formatted_topic = if String.starts_with?(topic, "0x"), do: topic, else: "0x" <> topic @@ -89,7 +89,7 @@ defmodule BlockScoutWeb.AddressLogsController do nil next_page_params -> - address_logs_path(conn, :index, address, Map.delete(next_page_params, "type")) + address_logs_path(conn, :index, address_hash, Map.delete(next_page_params, "type")) end items = diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/api/v1/decompiled_smart_contract_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/api/v1/decompiled_smart_contract_controller.ex index 1eec849380..7b783b9761 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/api/v1/decompiled_smart_contract_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/api/v1/decompiled_smart_contract_controller.ex @@ -7,8 +7,9 @@ defmodule BlockScoutWeb.API.V1.DecompiledSmartContractController do def create(conn, params) do if auth_token(conn) == actual_token() do with {:ok, hash} <- validate_address_hash(params["address_hash"]), - :ok <- smart_contract_exists?(hash), - :ok <- decompiled_contract_exists?(params["address_hash"], params["decompiler_version"]) do + :ok <- Chain.check_address_exists(hash), + {:contract, :not_found} <- + {:contract, Chain.check_decompiled_contract_exists(params["address_hash"], params["decompiler_version"])} do case Chain.create_decompiled_smart_contract(params) do {:ok, decompiled_smart_contract} -> send_resp(conn, :created, Jason.encode!(decompiled_smart_contract)) @@ -29,7 +30,7 @@ defmodule BlockScoutWeb.API.V1.DecompiledSmartContractController do :not_found -> send_resp(conn, :unprocessable_entity, encode(%{error: "address is not found"})) - :contract_exists -> + {:contract, :ok} -> send_resp( conn, :unprocessable_entity, @@ -41,13 +42,6 @@ defmodule BlockScoutWeb.API.V1.DecompiledSmartContractController do end end - defp smart_contract_exists?(address_hash) do - case Chain.hash_to_address(address_hash) do - {:ok, _address} -> :ok - _ -> :not_found - end - end - defp validate_address_hash(address_hash) do case Address.cast(address_hash) do {:ok, hash} -> {:ok, hash} @@ -55,13 +49,6 @@ defmodule BlockScoutWeb.API.V1.DecompiledSmartContractController do end end - defp decompiled_contract_exists?(address_hash, decompiler_version) do - case Chain.decompiled_code(address_hash, decompiler_version) do - {:ok, _} -> :contract_exists - _ -> :ok - end - end - defp auth_token(conn) do case get_req_header(conn, "auth_token") do [token] -> token diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/api/v1/verified_smart_contract_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/api/v1/verified_smart_contract_controller.ex index 50334a1a45..8b3d3d71eb 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/api/v1/verified_smart_contract_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/api/v1/verified_smart_contract_controller.ex @@ -7,8 +7,8 @@ defmodule BlockScoutWeb.API.V1.VerifiedSmartContractController do def create(conn, params) do with {:ok, hash} <- validate_address_hash(params["address_hash"]), - :ok <- smart_contract_exists?(hash), - :ok <- verified_smart_contract_exists?(hash) do + :ok <- Chain.check_address_exists(hash), + {:contract, :not_found} <- {:contract, Chain.check_verified_smart_contract_exists(hash)} do external_libraries = fetch_external_libraries(params) case Publisher.publish(hash, params, external_libraries) do @@ -31,7 +31,7 @@ defmodule BlockScoutWeb.API.V1.VerifiedSmartContractController do :not_found -> send_resp(conn, :unprocessable_entity, encode(%{error: "address is not found"})) - :contract_exists -> + {:contract, :ok} -> send_resp( conn, :unprocessable_entity, @@ -40,13 +40,6 @@ defmodule BlockScoutWeb.API.V1.VerifiedSmartContractController do end end - defp smart_contract_exists?(address_hash) do - case Chain.hash_to_address(address_hash) do - {:ok, _address} -> :ok - _ -> :not_found - end - end - defp validate_address_hash(address_hash) do case Address.cast(address_hash) do {:ok, hash} -> {:ok, hash} @@ -54,14 +47,6 @@ defmodule BlockScoutWeb.API.V1.VerifiedSmartContractController do end end - defp verified_smart_contract_exists?(address_hash) do - if Chain.address_hash_to_smart_contract(address_hash) do - :contract_exists - else - :ok - end - end - defp encode(data) do Jason.encode!(data) end 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 70ec6219f3..311feb4591 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 @@ -33,7 +33,7 @@ defmodule BlockScoutWeb.SmartContractController do def show(conn, params) do with true <- ajax?(conn), {:ok, address_hash} <- Chain.string_to_address_hash(params["id"]), - {:ok, _address} <- Chain.find_contract_address(address_hash), + :ok <- Chain.check_contract_address_exists(address_hash), outputs = Reader.query_function( address_hash, @@ -51,7 +51,7 @@ defmodule BlockScoutWeb.SmartContractController do :error -> unprocessable_entity(conn) - {:error, :not_found} -> + :not_found -> not_found(conn) _ -> diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_controller.ex index 1bedf97c1d..3f849c0e7c 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_controller.ex @@ -62,15 +62,15 @@ defmodule BlockScoutWeb.TransactionController do def show(conn, %{"id" => id}) do with {:ok, transaction_hash} <- Chain.string_to_transaction_hash(id), - {:ok, %Chain.Transaction{} = transaction} <- Chain.hash_to_transaction(transaction_hash) do - if Chain.transaction_has_token_transfers?(transaction.hash) do + :ok <- Chain.check_transaction_exists(transaction_hash) do + if Chain.transaction_has_token_transfers?(transaction_hash) do redirect(conn, to: transaction_token_transfer_path(conn, :index, id)) else redirect(conn, to: transaction_internal_transaction_path(conn, :index, id)) end else :error -> conn |> put_status(422) |> render("invalid.html", transaction_hash: id) - {:error, :not_found} -> conn |> put_status(404) |> render("not_found.html", transaction_hash: id) + :not_found -> conn |> put_status(404) |> render("not_found.html", transaction_hash: id) end end end diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_internal_transaction_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_internal_transaction_controller.ex index ae847b374d..ca154a0136 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_internal_transaction_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_internal_transaction_controller.ex @@ -10,7 +10,7 @@ defmodule BlockScoutWeb.TransactionInternalTransactionController do def index(conn, %{"transaction_id" => hash_string, "type" => "JSON"} = params) do with {:ok, hash} <- Chain.string_to_transaction_hash(hash_string), - {:ok, transaction} <- Chain.hash_to_transaction(hash) do + :ok <- Chain.check_transaction_exists(hash) do full_options = Keyword.merge( [ @@ -37,7 +37,7 @@ defmodule BlockScoutWeb.TransactionInternalTransactionController do transaction_internal_transaction_path( conn, :index, - transaction, + hash, Map.delete(next_page_params, "type") ) end @@ -66,7 +66,7 @@ defmodule BlockScoutWeb.TransactionInternalTransactionController do |> put_view(TransactionView) |> render("invalid.html", transaction_hash: hash_string) - {:error, :not_found} -> + :not_found -> conn |> put_status(404) |> put_view(TransactionView) diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_token_transfer_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_token_transfer_controller.ex index 5f4a9c8229..585a01301f 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_token_transfer_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_token_transfer_controller.ex @@ -10,8 +10,7 @@ defmodule BlockScoutWeb.TransactionTokenTransferController do def index(conn, %{"transaction_id" => hash_string, "type" => "JSON"} = params) do with {:ok, hash} <- Chain.string_to_transaction_hash(hash_string), - {:ok, transaction} <- - Chain.hash_to_transaction(hash) do + :ok <- Chain.check_transaction_exists(hash) do full_options = Keyword.merge( [ @@ -34,7 +33,7 @@ defmodule BlockScoutWeb.TransactionTokenTransferController do nil next_page_params -> - transaction_token_transfer_path(conn, :index, transaction, Map.delete(next_page_params, "type")) + transaction_token_transfer_path(conn, :index, hash, Map.delete(next_page_params, "type")) end items = @@ -62,7 +61,7 @@ defmodule BlockScoutWeb.TransactionTokenTransferController do |> put_view(TransactionView) |> render("invalid.html", transaction_hash: hash_string) - {:error, :not_found} -> + :not_found -> conn |> put_status(404) |> put_view(TransactionView) diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 2c40f6bbc1..0e01212c37 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -3297,4 +3297,203 @@ defmodule Explorer.Chain do |> Base.decode16!(case: :mixed) |> TypeDecoder.decode_raw(types) end + + @doc """ + Checks if an `t:Explorer.Chain.Address.t/0` with the given `hash` exists. + + Returns `:ok` if found + + iex> {:ok, %Explorer.Chain.Address{hash: hash}} = Explorer.Chain.create_address( + ...> %{hash: "0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed"} + ...> ) + iex> Explorer.Chain.check_address_exists(hash) + :ok + + Returns `:not_found` if not found + + iex> {:ok, hash} = Explorer.Chain.string_to_address_hash("0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed") + iex> Explorer.Chain.check_address_exists(hash) + :not_found + + """ + @spec check_address_exists(Hash.Address.t()) :: :ok | :not_found + def check_address_exists(address_hash) do + address_hash + |> address_exists?() + |> boolean_to_check_result() + end + + @doc """ + Checks if an `t:Explorer.Chain.Address.t/0` with the given `hash` exists. + + Returns `true` if found + + iex> {:ok, %Explorer.Chain.Address{hash: hash}} = Explorer.Chain.create_address( + ...> %{hash: "0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed"} + ...> ) + iex> Explorer.Chain.address_exists?(hash) + true + + Returns `false` if not found + + iex> {:ok, hash} = Explorer.Chain.string_to_address_hash("0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed") + iex> Explorer.Chain.address_exists?(hash) + false + + """ + @spec address_exists?(Hash.Address.t()) :: boolean() + def address_exists?(address_hash) do + query = + from( + address in Address, + where: address.hash == ^address_hash + ) + + Repo.exists?(query) + end + + @doc """ + Checks if it exists an `t:Explorer.Chain.Address.t/0` that has the provided + `t:Explorer.Chain.Address.t/0` `hash` and a contract. + + Returns `:ok` if found and `:not_found` otherwise. + """ + @spec check_contract_address_exists(Hash.Address.t()) :: :ok | :not_found + def check_contract_address_exists(address_hash) do + address_hash + |> contract_address_exists?() + |> boolean_to_check_result() + end + + @doc """ + Checks if it exists an `t:Explorer.Chain.Address.t/0` that has the provided + `t:Explorer.Chain.Address.t/0` `hash` and a contract. + + Returns `true` if found and `false` otherwise. + """ + @spec contract_address_exists?(Hash.Address.t()) :: boolean() + def contract_address_exists?(address_hash) do + query = + from( + address in Address, + where: address.hash == ^address_hash and not is_nil(address.contract_code) + ) + + Repo.exists?(query) + end + + @doc """ + Checks if it exists a `t:Explorer.Chain.DecompiledSmartContract.t/0` for the + `t:Explorer.Chain.Address.t/0` with the provided `hash` and with the provided version. + + Returns `:ok` if found and `:not_found` otherwise. + """ + @spec check_decompiled_contract_exists(Hash.Address.t(), String.t()) :: :ok | :not_found + def check_decompiled_contract_exists(address_hash, version) do + address_hash + |> decompiled_contract_exists?(version) + |> boolean_to_check_result() + end + + @doc """ + Checks if it exists a `t:Explorer.Chain.DecompiledSmartContract.t/0` for the + `t:Explorer.Chain.Address.t/0` with the provided `hash` and with the provided version. + + Returns `true` if found and `false` otherwise. + """ + @spec decompiled_contract_exists?(Hash.Address.t(), String.t()) :: boolean() + def decompiled_contract_exists?(address_hash, version) do + query = + from(contract in DecompiledSmartContract, + where: contract.address_hash == ^address_hash and contract.decompiler_version == ^version + ) + + Repo.exists?(query) + end + + @doc """ + Checks if it exists a verified `t:Explorer.Chain.SmartContract.t/0` for the + `t:Explorer.Chain.Address.t/0` with the provided `hash`. + + Returns `:ok` if found and `:not_found` otherwise. + """ + @spec check_verified_smart_contract_exists(Hash.Address.t()) :: :ok | :not_found + def check_verified_smart_contract_exists(address_hash) do + address_hash + |> verified_smart_contract_exists?() + |> boolean_to_check_result() + end + + @doc """ + Checks if it exists a verified `t:Explorer.Chain.SmartContract.t/0` for the + `t:Explorer.Chain.Address.t/0` with the provided `hash`. + + Returns `true` if found and `false` otherwise. + """ + @spec verified_smart_contract_exists?(Hash.Address.t()) :: boolean() + def verified_smart_contract_exists?(address_hash) do + query = + from( + smart_contract in SmartContract, + where: smart_contract.address_hash == ^address_hash + ) + + Repo.exists?(query) + end + + @doc """ + Checks if a `t:Explorer.Chain.Transaction.t/0` with the given `hash` exists. + + Returns `:ok` if found + + iex> %Transaction{hash: hash} = insert(:transaction) + iex> Explorer.Chain.check_transaction_exists(hash) + :ok + + Returns `:not_found` if not found + + iex> {:ok, hash} = Explorer.Chain.string_to_transaction_hash( + ...> "0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b" + ...> ) + iex> Explorer.Chain.check_transaction_exists(hash) + :not_found + """ + @spec check_transaction_exists(Hash.Full.t()) :: :ok | :not_found + def check_transaction_exists(hash) do + hash + |> transaction_exists?() + |> boolean_to_check_result() + end + + @doc """ + Checks if a `t:Explorer.Chain.Transaction.t/0` with the given `hash` exists. + + Returns `true` if found + + iex> %Transaction{hash: hash} = insert(:transaction) + iex> Explorer.Chain.transaction_exists?(hash) + true + + Returns `false` if not found + + iex> {:ok, hash} = Explorer.Chain.string_to_transaction_hash( + ...> "0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b" + ...> ) + iex> Explorer.Chain.transaction_exists?(hash) + false + """ + @spec transaction_exists?(Hash.Full.t()) :: boolean() + def transaction_exists?(hash) do + query = + from( + transaction in Transaction, + where: transaction.hash == ^hash + ) + + Repo.exists?(query) + end + + defp boolean_to_check_result(true), do: :ok + + defp boolean_to_check_result(false), do: :not_found end From 4a46e6eec592e0b1aed26baa9cb3bcaa60e454cc Mon Sep 17 00:00:00 2001 From: pasqu4le Date: Fri, 19 Jul 2019 17:58:47 +0200 Subject: [PATCH 07/14] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9c8934f3d..c295387ba5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## Current ### Features +- [#2391](https://github.com/poanetwork/blockscout/pull/2391) - Controllers Improvements - [#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 f8c8d7aa6b73693fec9ba2905a904203c771534a Mon Sep 17 00:00:00 2001 From: maxgrapps Date: Sat, 20 Jul 2019 12:09:49 +0300 Subject: [PATCH 08/14] added templates for table loader and tile loader --- .../assets/css/components/_stakes_table.scss | 37 ++++++++ .../assets/css/components/_tile.scss | 46 ++++++++++ .../templates/address/index.html.eex | 2 +- .../templates/chain/show.html.eex | 8 +- .../templates/loaders/_table-loader.eex | 85 +++++++++++++++++++ .../templates/loaders/_tile-loader.eex | 72 ++++++++++++++++ apps/block_scout_web/priv/gettext/default.pot | 1 - 7 files changed, 242 insertions(+), 9 deletions(-) create mode 100644 apps/block_scout_web/lib/block_scout_web/templates/loaders/_table-loader.eex create mode 100644 apps/block_scout_web/lib/block_scout_web/templates/loaders/_tile-loader.eex diff --git a/apps/block_scout_web/assets/css/components/_stakes_table.scss b/apps/block_scout_web/assets/css/components/_stakes_table.scss index 79cdc20b38..1831dc4d5b 100644 --- a/apps/block_scout_web/assets/css/components/_stakes_table.scss +++ b/apps/block_scout_web/assets/css/components/_stakes_table.scss @@ -26,6 +26,43 @@ $stakes-table-cell-separation: 25px !default; } } +// Loader +.table-content-loader { + display: inline-block; + height: 24px; + width: 100%; + border-radius: 4px; + background-color: #f5f6fa; + overflow: hidden; + position: relative; + &:before { + width: inherit; + height: inherit; + content: ''; + position: absolute; + background: linear-gradient(to right, #f5f6fa 2%, #eee 18%, #f5f6fa 33%); + animation-duration: 1.7s; + animation-fill-mode: forwards; + animation-iteration-count: infinite; + animation-timing-function: linear; + animation-name: placeholderAnimate; + background-size: 1300px; + } +} + +@keyframes placeholderAnimate { + 0%{ background-position: -650px 0; } + 100% { background-position: 650px 0; } +} + +.table-content-pseudo { + td { + &:last-child { + padding-right: 24px !important; + } + } +} + .stakes-table { min-width: fit-content; width: 100%; diff --git a/apps/block_scout_web/assets/css/components/_tile.scss b/apps/block_scout_web/assets/css/components/_tile.scss index 8965715727..7fb9112d40 100644 --- a/apps/block_scout_web/assets/css/components/_tile.scss +++ b/apps/block_scout_web/assets/css/components/_tile.scss @@ -351,3 +351,49 @@ $tile-body-a-color: #5959d8 !default; } } } + +// Loader +.tile-type-loading { + background-color: #fff; + padding-top: 30px; + padding-bottom: 28px; +} + +.tile-loader { + display: inline-block; + height: 20px; + width: 100%; + border-radius: 4px; + background-color: #f5f6fa; + overflow: hidden; + position: relative; + &:before { + width: inherit; + height: inherit; + content: ''; + position: absolute; + background: linear-gradient(to right, #f5f6fa 2%, #eee 18%, #f5f6fa 33%); + animation-duration: 1.7s; + animation-fill-mode: forwards; + animation-iteration-count: infinite; + animation-timing-function: linear; + animation-name: tilePlaceholderAnimate; + background-size: 1300px; + } +} + +.tile-label-loader { + height: 14px; + width: 80px; +} + +.tile-address-loader { + & + .tile-address-loader { + margin-top: 6px; + } +} + +@keyframes tilePlaceholderAnimate { + 0%{ background-position: -650px 0; } + 100% { background-position: 650px 0; } +} diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address/index.html.eex index 3aaab46ad5..68f586adb4 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address/index.html.eex @@ -38,7 +38,7 @@ - + diff --git a/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex index 0c29001697..2848e23b55 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex @@ -117,13 +117,7 @@ <%= gettext "Something went wrong, click to retry." %> -
- - - - - <%= gettext("Loading...") %> -
+ diff --git a/apps/block_scout_web/lib/block_scout_web/templates/loaders/_table-loader.eex b/apps/block_scout_web/lib/block_scout_web/templates/loaders/_table-loader.eex new file mode 100644 index 0000000000..ac7cc71f56 --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/templates/loaders/_table-loader.eex @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/apps/block_scout_web/lib/block_scout_web/templates/loaders/_tile-loader.eex b/apps/block_scout_web/lib/block_scout_web/templates/loaders/_tile-loader.eex new file mode 100644 index 0000000000..134613a5d1 --- /dev/null +++ b/apps/block_scout_web/lib/block_scout_web/templates/loaders/_tile-loader.eex @@ -0,0 +1,72 @@ +
+
+
+ + + + + + +
+
+ + +
+
+ + + + + + +
+
+
+
+
+
+ + + + + + +
+
+ + +
+
+ + + + + + +
+
+
+
+
+
+ + + + + + +
+
+ + +
+
+ + + + + + +
+
+
\ No newline at end of file diff --git a/apps/block_scout_web/priv/gettext/default.pot b/apps/block_scout_web/priv/gettext/default.pot index 61d7465f49..c29cc13ce2 100644 --- a/apps/block_scout_web/priv/gettext/default.pot +++ b/apps/block_scout_web/priv/gettext/default.pot @@ -1058,7 +1058,6 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address_read_contract/index.html.eex:14 #: lib/block_scout_web/templates/chain/show.html.eex:99 -#: lib/block_scout_web/templates/chain/show.html.eex:125 #: lib/block_scout_web/templates/tokens/read_contract/index.html.eex:21 msgid "Loading..." msgstr "" From 4a13b9120c15759f3c6d23e9bfaf500e850fa742 Mon Sep 17 00:00:00 2001 From: maxgrapps <50101080+maxgrapps@users.noreply.github.com> Date: Sat, 20 Jul 2019 12:11:56 +0300 Subject: [PATCH 09/14] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9c8934f3d..33783ca62a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - [#2294](https://github.com/poanetwork/blockscout/pull/2294) - add healthy block period checking endpoint ### Fixes +- [#2393](https://github.com/poanetwork/blockscout/pull/2393) - added templates for table loader and tile loader - [#2378](https://github.com/poanetwork/blockscout/pull/2378) - Page performance: exclude moment.js localization files except EN, remove unused css - [#2368](https://github.com/poanetwork/blockscout/pull/2368) - add two columns of smart contract info - [#2375](https://github.com/poanetwork/blockscout/pull/2375) - Update created_contract_code_indexed_at on transaction import conflict From 86d6ba97a16b12817cd4ba39d0a1dfefbd4917d5 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Mon, 22 Jul 2019 20:23:03 +0300 Subject: [PATCH 10/14] Place loaders --- CHANGELOG.md | 2 +- apps/block_scout_web/assets/package-lock.json | 41 ++++++++++++++----- .../templates/address/index.html.eex | 2 +- .../address_coin_balance/index.html.eex | 4 +- .../index.html.eex | 4 +- .../templates/address_logs/index.html.eex | 4 +- .../templates/address_token/index.html.eex | 4 +- .../address_token_transfer/index.html.eex | 4 +- .../address_transaction/index.html.eex | 4 +- .../address_validation/index.html.eex | 4 +- .../templates/block/index.html.eex | 4 +- .../block_transaction/index.html.eex | 4 +- .../templates/chain/show.html.eex | 1 - .../_table-loader.html.eex} | 0 .../_tile-loader.html.eex} | 0 .../pending_transaction/index.html.eex | 9 +--- .../templates/tokens/holder/index.html.eex | 4 +- .../templates/tokens/inventory/index.html.eex | 4 +- .../templates/tokens/transfer/index.html.eex | 4 +- .../templates/transaction/index.html.eex | 4 +- .../index.html.eex | 4 +- .../templates/transaction_log/index.html.eex | 4 +- .../transaction_token_transfer/index.html.eex | 4 +- apps/block_scout_web/priv/gettext/default.pot | 11 ++--- .../priv/gettext/en/LC_MESSAGES/default.po | 18 +++----- 25 files changed, 91 insertions(+), 57 deletions(-) rename apps/block_scout_web/lib/block_scout_web/templates/{loaders/_table-loader.eex => common_components/_table-loader.html.eex} (100%) rename apps/block_scout_web/lib/block_scout_web/templates/{loaders/_tile-loader.eex => common_components/_tile-loader.html.eex} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b7c01b4d4..21dafca1b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,9 +8,9 @@ - [#2294](https://github.com/poanetwork/blockscout/pull/2294) - add healthy block period checking endpoint ### Fixes +- [#2405](https://github.com/poanetwork/blockscout/pull/2405) - added templates for table loader and tile loader - [#2398](https://github.com/poanetwork/blockscout/pull/2398) - show only one decoded candidate - [#2395](https://github.com/poanetwork/blockscout/pull/2395) - new block loading animation -- [#2393](https://github.com/poanetwork/blockscout/pull/2393) - added templates for table loader and tile loader - [#2389](https://github.com/poanetwork/blockscout/pull/2389) - Reduce Lodash lib size (86% of lib methods are not used) - [#2378](https://github.com/poanetwork/blockscout/pull/2378) - Page performance: exclude moment.js localization files except EN, remove unused css - [#2368](https://github.com/poanetwork/blockscout/pull/2368) - add two columns of smart contract info diff --git a/apps/block_scout_web/assets/package-lock.json b/apps/block_scout_web/assets/package-lock.json index 22c6d216de..f20e753b49 100644 --- a/apps/block_scout_web/assets/package-lock.json +++ b/apps/block_scout_web/assets/package-lock.json @@ -3816,7 +3816,8 @@ "version": "2.1.1", "resolved": false, "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -3840,13 +3841,15 @@ "version": "1.0.0", "resolved": false, "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "resolved": false, "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -3863,19 +3866,22 @@ "version": "1.1.0", "resolved": false, "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=", - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "resolved": false, "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "resolved": false, "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=", - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -4006,7 +4012,8 @@ "version": "2.0.3", "resolved": false, "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -4020,6 +4027,7 @@ "resolved": false, "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -4036,6 +4044,7 @@ "resolved": false, "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -4044,13 +4053,15 @@ "version": "0.0.8", "resolved": false, "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.2.4", "resolved": false, "integrity": "sha512-hzXIWWet/BzWhYs2b+u7dRHlruXhwdgvlTMDKC6Cb1U7ps6Ac6yQlR39xsbjWJE377YTCtKwIXIpJ5oP+j5y8g==", "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -4071,6 +4082,7 @@ "resolved": false, "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -4159,7 +4171,8 @@ "version": "1.0.1", "resolved": false, "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=", - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -4173,6 +4186,7 @@ "resolved": false, "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -4268,7 +4282,8 @@ "version": "5.1.1", "resolved": false, "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==", - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -4310,6 +4325,7 @@ "resolved": false, "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -4331,6 +4347,7 @@ "resolved": false, "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -4379,13 +4396,15 @@ "version": "1.0.2", "resolved": false, "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.0.2", "resolved": false, "integrity": "sha1-hFK0u36Dx8GI2AQcGoN8dz1ti7k=", - "dev": true + "dev": true, + "optional": true } } }, diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address/index.html.eex index 68f586adb4..c594915d9f 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address/index.html.eex @@ -38,7 +38,7 @@ - + <%= render BlockScoutWeb.CommonComponentsView, "_table-loader.html" %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_coin_balance/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_coin_balance/index.html.eex index 6b9459f5b3..2e71dd22ca 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_coin_balance/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_coin_balance/index.html.eex @@ -40,7 +40,9 @@ -
+
+ <%= render BlockScoutWeb.CommonComponentsView, "_tile-loader.html" %> +
<%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "bottom", cur_page_number: "1", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_internal_transaction/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_internal_transaction/index.html.eex index 3bc2e7fe9b..f18638db0d 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_internal_transaction/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_internal_transaction/index.html.eex @@ -66,7 +66,9 @@ -
+
+ <%= render BlockScoutWeb.CommonComponentsView, "_tile-loader.html" %> +
<%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "bottom", cur_page_number: "1", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_logs/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_logs/index.html.eex index 3a44e0cb2d..fabbc7f7d8 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_logs/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_logs/index.html.eex @@ -27,7 +27,9 @@ -
+
+ <%= render BlockScoutWeb.CommonComponentsView, "_tile-loader.html" %> +
<%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "bottom", cur_page_number: "1", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_token/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_token/index.html.eex index 840d9cc1da..8510bdca64 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_token/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_token/index.html.eex @@ -19,7 +19,9 @@ -
+
+ <%= render BlockScoutWeb.CommonComponentsView, "_tile-loader.html" %> +
diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_token_transfer/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_token_transfer/index.html.eex index c2ab502bf0..738d70883d 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_token_transfer/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_token_transfer/index.html.eex @@ -21,7 +21,9 @@ -
+
+ <%= render BlockScoutWeb.CommonComponentsView, "_tile-loader.html" %> +
<%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "bottom", cur_page_number: "1", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_transaction/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_transaction/index.html.eex index c3a4c94129..83c5454627 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_transaction/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_transaction/index.html.eex @@ -65,7 +65,9 @@
-
+
+ <%= render BlockScoutWeb.CommonComponentsView, "_tile-loader.html" %> +
diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_validation/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_validation/index.html.eex index 3f85f03aba..03b37369bc 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_validation/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_validation/index.html.eex @@ -22,7 +22,9 @@ <%= gettext "Something went wrong, click to reload." %> -
+
+ <%= render BlockScoutWeb.CommonComponentsView, "_tile-loader.html" %> +
<%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "bottom", cur_page_number: "1", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/block/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/block/index.html.eex index 92b91ce287..dd8a3ed093 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/block/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/block/index.html.eex @@ -11,7 +11,9 @@ <%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "top", cur_page_number: "1", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %> -
+
+ <%= render BlockScoutWeb.CommonComponentsView, "_tile-loader.html" %> +
<%= gettext "There are no blocks." %>
diff --git a/apps/block_scout_web/lib/block_scout_web/templates/block_transaction/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/block_transaction/index.html.eex index a497ab1b7e..e0847cac86 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/block_transaction/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/block_transaction/index.html.eex @@ -29,7 +29,9 @@
-
+
+ <%= render BlockScoutWeb.CommonComponentsView, "_tile-loader.html" %> +
<%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "bottom", cur_page_number: "1", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex index 2848e23b55..f0ffa52ca2 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex @@ -117,7 +117,6 @@ <%= gettext "Something went wrong, click to retry." %> - diff --git a/apps/block_scout_web/lib/block_scout_web/templates/loaders/_table-loader.eex b/apps/block_scout_web/lib/block_scout_web/templates/common_components/_table-loader.html.eex similarity index 100% rename from apps/block_scout_web/lib/block_scout_web/templates/loaders/_table-loader.eex rename to apps/block_scout_web/lib/block_scout_web/templates/common_components/_table-loader.html.eex diff --git a/apps/block_scout_web/lib/block_scout_web/templates/loaders/_tile-loader.eex b/apps/block_scout_web/lib/block_scout_web/templates/common_components/_tile-loader.html.eex similarity index 100% rename from apps/block_scout_web/lib/block_scout_web/templates/loaders/_tile-loader.eex rename to apps/block_scout_web/lib/block_scout_web/templates/common_components/_tile-loader.html.eex diff --git a/apps/block_scout_web/lib/block_scout_web/templates/pending_transaction/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/pending_transaction/index.html.eex index 4c97be61e1..e819285629 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/pending_transaction/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/pending_transaction/index.html.eex @@ -23,13 +23,8 @@ <%= gettext "There are no pending transactions." %> -
- -
+
+ <%= render BlockScoutWeb.CommonComponentsView, "_tile-loader.html" %> +
<%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "bottom", cur_page_number: "1", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/tokens/inventory/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/tokens/inventory/index.html.eex index da834dbc88..1e78b11353 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/tokens/inventory/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/tokens/inventory/index.html.eex @@ -27,7 +27,9 @@ -
+
+ <%= render BlockScoutWeb.CommonComponentsView, "_tile-loader.html" %> +
<%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "bottom", cur_page_number: "1", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/tokens/transfer/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/tokens/transfer/index.html.eex index 980cc4b05a..addaa0c359 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/tokens/transfer/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/tokens/transfer/index.html.eex @@ -26,7 +26,9 @@ -
+
+ <%= render BlockScoutWeb.CommonComponentsView, "_tile-loader.html" %> +
<%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "bottom", cur_page_number: "1", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/transaction/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/transaction/index.html.eex index 18928915f2..bce59eb00b 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/transaction/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/transaction/index.html.eex @@ -28,7 +28,9 @@ -
+
+ <%= render BlockScoutWeb.CommonComponentsView, "_tile-loader.html" %> +
<%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "bottom", cur_page_number: "1", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex index e6623b4061..70162a3be8 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex @@ -16,7 +16,9 @@ -
+
+ <%= render BlockScoutWeb.CommonComponentsView, "_tile-loader.html" %> +
<%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "bottom", cur_page_number: "1", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/transaction_log/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/transaction_log/index.html.eex index 3c84e7c4f9..17f480b439 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/transaction_log/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/transaction_log/index.html.eex @@ -19,7 +19,9 @@ -
+
+ <%= render BlockScoutWeb.CommonComponentsView, "_tile-loader.html" %> +
<%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "bottom", cur_page_number: "1", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/transaction_token_transfer/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/transaction_token_transfer/index.html.eex index d40dedd414..8d356a450a 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/transaction_token_transfer/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/transaction_token_transfer/index.html.eex @@ -18,7 +18,9 @@ -
+
+ <%= render BlockScoutWeb.CommonComponentsView, "_tile-loader.html" %> +
<%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "bottom", cur_page_number: "1", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %> diff --git a/apps/block_scout_web/priv/gettext/default.pot b/apps/block_scout_web/priv/gettext/default.pot index 7d8e592e3b..228501dc51 100644 --- a/apps/block_scout_web/priv/gettext/default.pot +++ b/apps/block_scout_web/priv/gettext/default.pot @@ -1077,11 +1077,6 @@ msgstr "" msgid "GraphQL" msgstr "" -#, elixir-format -#: lib/block_scout_web/templates/pending_transaction/index.html.eex:32 -msgid "Loading" -msgstr "" - #, elixir-format #: lib/block_scout_web/templates/layout/_topnav.html.eex:73 msgid "RPC" @@ -1276,7 +1271,7 @@ msgid "There are no pending transactions." msgstr "" #, elixir-format -#: lib/block_scout_web/templates/block/index.html.eex:16 +#: lib/block_scout_web/templates/block/index.html.eex:18 msgid "There are no blocks." msgstr "" @@ -1744,8 +1739,8 @@ msgid "here." msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_token/index.html.eex:26 -#: lib/block_scout_web/templates/address_transaction/index.html.eex:72 +#: lib/block_scout_web/templates/address_token/index.html.eex:28 +#: lib/block_scout_web/templates/address_transaction/index.html.eex:74 msgid "CSV" 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 5333eb95aa..7c64c47de2 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 @@ -34,7 +34,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/block/overview.html.eex:21 -#: lib/block_scout_web/templates/chain/_block.html.eex:11 +#: lib/block_scout_web/templates/chain/_block.html.eex:178 msgid "%{count} Transactions" msgstr "" @@ -522,7 +522,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/block/_tile.html.eex:38 #: lib/block_scout_web/templates/block/overview.html.eex:121 -#: lib/block_scout_web/templates/chain/_block.html.eex:15 +#: lib/block_scout_web/templates/chain/_block.html.eex:182 msgid "Miner" msgstr "" @@ -1040,7 +1040,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/block/_tile.html.eex:47 -#: lib/block_scout_web/templates/chain/_block.html.eex:23 +#: lib/block_scout_web/templates/chain/_block.html.eex:190 #: lib/block_scout_web/views/internal_transaction_view.ex:27 msgid "Reward" msgstr "" @@ -1058,7 +1058,6 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address_read_contract/index.html.eex:14 #: lib/block_scout_web/templates/chain/show.html.eex:99 -#: lib/block_scout_web/templates/chain/show.html.eex:125 #: lib/block_scout_web/templates/tokens/read_contract/index.html.eex:21 msgid "Loading..." msgstr "" @@ -1078,11 +1077,6 @@ msgstr "" msgid "GraphQL" msgstr "" -#, elixir-format -#: lib/block_scout_web/templates/pending_transaction/index.html.eex:32 -msgid "Loading" -msgstr "" - #, elixir-format #: lib/block_scout_web/templates/layout/_topnav.html.eex:73 msgid "RPC" @@ -1277,7 +1271,7 @@ msgid "There are no pending transactions." msgstr "" #, elixir-format -#: lib/block_scout_web/templates/block/index.html.eex:16 +#: lib/block_scout_web/templates/block/index.html.eex:18 msgid "There are no blocks." msgstr "" @@ -1745,8 +1739,8 @@ msgid "here." msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_token/index.html.eex:26 -#: lib/block_scout_web/templates/address_transaction/index.html.eex:72 +#: lib/block_scout_web/templates/address_token/index.html.eex:28 +#: lib/block_scout_web/templates/address_transaction/index.html.eex:74 msgid "CSV" msgstr "" From 80587f861ef920cb6a018a76b1b8114b7352d6d2 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Tue, 23 Jul 2019 18:11:28 +0300 Subject: [PATCH 11/14] Remove brackets in market cap % view --- CHANGELOG.md | 1 + .../lib/block_scout_web/templates/address/_tile.html.eex | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 634e5ac697..1f9f4f9a55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ - [#2326](https://github.com/poanetwork/blockscout/pull/2326) - fix nested constructor arguments ### Chore +- [#2418](https://github.com/poanetwork/blockscout/pull/2418) - Remove parentheses in market cap percentage - [#2401](https://github.com/poanetwork/blockscout/pull/2401) - add ENV vars to manage updating period of average block time and market history cache - [#2363](https://github.com/poanetwork/blockscout/pull/2363) - add parameters example for eth rpc - [#2342](https://github.com/poanetwork/blockscout/pull/2342) - Upgrade Postgres image version in Docker setup diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address/_tile.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address/_tile.html.eex index 9680faa2a8..56f1a2bbb2 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address/_tile.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address/_tile.html.eex @@ -21,7 +21,7 @@ <%= if @total_supply do %> - (<%= balance_percentage(@address, @total_supply) %>) + <%= balance_percentage(@address, @total_supply) %> <% end %> From ec31e82150330fc4bde05f0234b937319a5a872b Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Wed, 24 Jul 2019 11:09:44 +0300 Subject: [PATCH 12/14] Revert package-lock.json update --- apps/block_scout_web/assets/package-lock.json | 41 +++++-------------- 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/apps/block_scout_web/assets/package-lock.json b/apps/block_scout_web/assets/package-lock.json index f20e753b49..22c6d216de 100644 --- a/apps/block_scout_web/assets/package-lock.json +++ b/apps/block_scout_web/assets/package-lock.json @@ -3816,8 +3816,7 @@ "version": "2.1.1", "resolved": false, "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", - "dev": true, - "optional": true + "dev": true }, "aproba": { "version": "1.2.0", @@ -3841,15 +3840,13 @@ "version": "1.0.0", "resolved": false, "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", - "dev": true, - "optional": true + "dev": true }, "brace-expansion": { "version": "1.1.11", "resolved": false, "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "dev": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -3866,22 +3863,19 @@ "version": "1.1.0", "resolved": false, "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=", - "dev": true, - "optional": true + "dev": true }, "concat-map": { "version": "0.0.1", "resolved": false, "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true, - "optional": true + "dev": true }, "console-control-strings": { "version": "1.1.0", "resolved": false, "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=", - "dev": true, - "optional": true + "dev": true }, "core-util-is": { "version": "1.0.2", @@ -4012,8 +4006,7 @@ "version": "2.0.3", "resolved": false, "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", - "dev": true, - "optional": true + "dev": true }, "ini": { "version": "1.3.5", @@ -4027,7 +4020,6 @@ "resolved": false, "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", "dev": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -4044,7 +4036,6 @@ "resolved": false, "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "dev": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -4053,15 +4044,13 @@ "version": "0.0.8", "resolved": false, "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", - "dev": true, - "optional": true + "dev": true }, "minipass": { "version": "2.2.4", "resolved": false, "integrity": "sha512-hzXIWWet/BzWhYs2b+u7dRHlruXhwdgvlTMDKC6Cb1U7ps6Ac6yQlR39xsbjWJE377YTCtKwIXIpJ5oP+j5y8g==", "dev": true, - "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -4082,7 +4071,6 @@ "resolved": false, "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "dev": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -4171,8 +4159,7 @@ "version": "1.0.1", "resolved": false, "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=", - "dev": true, - "optional": true + "dev": true }, "object-assign": { "version": "4.1.1", @@ -4186,7 +4173,6 @@ "resolved": false, "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", "dev": true, - "optional": true, "requires": { "wrappy": "1" } @@ -4282,8 +4268,7 @@ "version": "5.1.1", "resolved": false, "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==", - "dev": true, - "optional": true + "dev": true }, "safer-buffer": { "version": "2.1.2", @@ -4325,7 +4310,6 @@ "resolved": false, "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", "dev": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -4347,7 +4331,6 @@ "resolved": false, "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", "dev": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -4396,15 +4379,13 @@ "version": "1.0.2", "resolved": false, "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "dev": true, - "optional": true + "dev": true }, "yallist": { "version": "3.0.2", "resolved": false, "integrity": "sha1-hFK0u36Dx8GI2AQcGoN8dz1ti7k=", - "dev": true, - "optional": true + "dev": true } } }, From 11c9b16ef356d17edd229cc2962507abf814be3a Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Wed, 24 Jul 2019 11:26:14 +0300 Subject: [PATCH 13/14] Tile loader on the main page --- .../lib/block_scout_web/templates/chain/show.html.eex | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex index 5e136a1007..69d1f8b6ed 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/chain/show.html.eex @@ -117,6 +117,7 @@ <%= gettext "Something went wrong, click to retry." %> + <%= render BlockScoutWeb.CommonComponentsView, "_tile-loader.html" %> From 30474994ae5c00cfdc229cb1cc17673cab9f8623 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Tue, 23 Jul 2019 15:23:11 +0300 Subject: [PATCH 14/14] Fix router page not found path --- CHANGELOG.md | 1 + .../block_scout_web/controllers/address_logs_controller.ex | 2 ++ .../controllers/address_transaction_controller.ex | 4 ++++ .../lib/block_scout_web/controllers/chain_controller.ex | 2 ++ .../block_scout_web/controllers/smart_contract_controller.ex | 2 ++ apps/block_scout_web/lib/block_scout_web/router.ex | 2 +- 6 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b333ba4ef9..85f1241c2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - [#2324](https://github.com/poanetwork/blockscout/pull/2324) - set timeout for loading message on the main page ### Fixes +- [#2416](https://github.com/poanetwork/blockscout/pull/2416) - Fix "page not found" handling in the router - [#2410](https://github.com/poanetwork/blockscout/pull/2410) - preload smart contract for logs decoding - [#2398](https://github.com/poanetwork/blockscout/pull/2398) - show only one decoded candidate - [#2395](https://github.com/poanetwork/blockscout/pull/2395) - new block loading animation diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_logs_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_logs_controller.ex index e349ecd9ef..04c37badb5 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_logs_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_logs_controller.ex @@ -115,4 +115,6 @@ defmodule BlockScoutWeb.AddressLogsController do not_found(conn) end end + + def search_logs(conn, _), do: not_found(conn) end diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/address_transaction_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/address_transaction_controller.ex index f6d9b8a30f..ba29c766c1 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/address_transaction_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/address_transaction_controller.ex @@ -130,6 +130,8 @@ defmodule BlockScoutWeb.AddressTransactionController do end end + def token_transfers_csv(conn, _), do: not_found(conn) + def transactions_csv(conn, %{"address_id" => address_hash_string}) do with {:ok, address_hash} <- Chain.string_to_address_hash(address_hash_string), {:ok, address} <- Chain.hash_to_address(address_hash) do @@ -149,4 +151,6 @@ defmodule BlockScoutWeb.AddressTransactionController do not_found(conn) end end + + def transactions_csv(conn, _), do: not_found(conn) end diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/chain_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/chain_controller.ex index 40a0fd3bbb..520fe8ea29 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/chain_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/chain_controller.ex @@ -52,6 +52,8 @@ defmodule BlockScoutWeb.ChainController do end end + def search(conn, _), do: not_found(conn) + def token_autocomplete(conn, %{"q" => term}) when is_binary(term) do if term == "" do json(conn, "{}") 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 70ec6219f3..58fb4c4432 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 @@ -30,6 +30,8 @@ defmodule BlockScoutWeb.SmartContractController do end end + def index(conn, _), do: not_found(conn) + def show(conn, params) do with true <- ajax?(conn), {:ok, address_hash} <- Chain.string_to_address_hash(params["id"]), 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..7a1f5b3ed9 100644 --- a/apps/block_scout_web/lib/block_scout_web/router.ex +++ b/apps/block_scout_web/lib/block_scout_web/router.ex @@ -261,6 +261,6 @@ defmodule BlockScoutWeb.Router do get("/api_docs", APIDocsController, :index) get("/eth_rpc_api_docs", APIDocsController, :eth_rpc) - get("/:page", PageNotFoundController, :index) + get("/*path", PageNotFoundController, :index) end end