From ec2719936fad336cc5e2f25000f2a8774820bcfc Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 18 Jun 2019 13:08:34 +0300 Subject: [PATCH 01/19] show all token transfers --- .../templates/transaction/overview.html.eex | 8 +++++--- .../lib/block_scout_web/views/transaction_view.ex | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/block_scout_web/lib/block_scout_web/templates/transaction/overview.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/transaction/overview.html.eex index 396b8dd7c0..ca188ea231 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/transaction/overview.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/transaction/overview.html.eex @@ -170,18 +170,20 @@ <%= case token_transfer_type(@transaction) do %> - <% {type, token_transfer} -> %> + <% {type, transaction_with_transfers} when is_atom(type) -> %>

<%= if type == :erc20, do: gettext("ERC-20"), else: gettext("ERC-721")%><%= gettext " Token Transfer" %>

+ <%= for transfer <- transaction_with_transfers.token_transfers do %>

- <%= token_transfer_amount(token_transfer) %> - <%= link(token_symbol(token_transfer.token), to: token_path(BlockScoutWeb.Endpoint, :show, token_transfer.token.contract_address_hash)) %> + <%= token_transfer_amount(transfer) %> + <%= link(token_symbol(transfer.token), to: token_path(BlockScoutWeb.Endpoint, :show, transfer.token.contract_address_hash)) %>

+ <% end %>
<% _ -> %> diff --git a/apps/block_scout_web/lib/block_scout_web/views/transaction_view.ex b/apps/block_scout_web/lib/block_scout_web/views/transaction_view.ex index 026147ac3e..a012e138a0 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/transaction_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/transaction_view.ex @@ -3,7 +3,7 @@ defmodule BlockScoutWeb.TransactionView do alias BlockScoutWeb.{AddressView, BlockView, TabHelpers} alias Cldr.Number - alias Explorer.Chain + alias Explorer.{Chain, Repo} alias Explorer.Chain.Block.Reward alias Explorer.Chain.{Address, Block, InternalTransaction, Transaction, Wei} alias Explorer.ExchangeRates.Token @@ -33,7 +33,9 @@ defmodule BlockScoutWeb.TransactionView do def value_transfer?(_), do: false def token_transfer_type(transaction) do - Chain.transaction_token_transfer_type(transaction) + transaction_with_transfers = Repo.preload(transaction, token_transfers: :token) + + {Chain.transaction_token_transfer_type(transaction), transaction_with_transfers} end def processing_time_duration(%Transaction{block: nil}) do From 9470d33a50463c9002f513fa4e86d52758e2be8d Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 18 Jun 2019 13:08:46 +0300 Subject: [PATCH 02/19] token transfer type fixes --- apps/explorer/lib/explorer/chain.ex | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index c40c2a492b..72b907d552 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -2907,8 +2907,6 @@ defmodule Explorer.Chain do ) do zero_wei = %Wei{value: Decimal.new(0)} - transaction = Repo.preload(transaction, token_transfers: :token) - # https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/token/ERC721/ERC721.sol#L35 case {to_string(input), value} do # transferFrom(address,address,uint256) @@ -2932,6 +2930,9 @@ defmodule Explorer.Chain do find_erc721_token_transfer(transaction.token_transfers, {from_address, to_address}) + {"0xf907fc5b" <> _params, ^zero_wei} -> + :erc20 + # check for ERC 20 or for old ERC 721 token versions {unquote(TokenTransfer.transfer_function_signature()) <> params, ^zero_wei} -> types = [:address, {:uint, 256}] @@ -2957,22 +2958,23 @@ defmodule Explorer.Chain do token_transfer.from_address_hash.bytes == from_address && token_transfer.to_address_hash.bytes == to_address end) - if token_transfer, do: {:erc721, token_transfer} + if token_transfer, do: :erc721 end defp find_erc721_or_erc20_token_transfer(token_transfers, {address, decimal_value}) do token_transfer = Enum.find(token_transfers, fn token_transfer -> - token_transfer.to_address_hash.bytes == address && - (token_transfer.amount == decimal_value || token_transfer.token_id) + token_transfer.to_address_hash.bytes == address && token_transfer.amount == decimal_value end) if token_transfer do case token_transfer.token do - %Token{type: "ERC-20"} -> {:erc20, token_transfer} - %Token{type: "ERC-721"} -> {:erc721, token_transfer} + %Token{type: "ERC-20"} -> :erc20 + %Token{type: "ERC-721"} -> :erc721 _ -> nil end + else + :erc20 end end From 2790cf5f88e65eaf5fefe1b718097a45b868dc88 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 18 Jun 2019 13:25:52 +0300 Subject: [PATCH 03/19] add generic title for token transfers --- .../templates/transaction/overview.html.eex | 2 +- .../lib/block_scout_web/views/transaction_view.ex | 11 ++++++++++- apps/explorer/lib/explorer/chain.ex | 3 +++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/apps/block_scout_web/lib/block_scout_web/templates/transaction/overview.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/transaction/overview.html.eex index ca188ea231..b168045fe1 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/transaction/overview.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/transaction/overview.html.eex @@ -175,7 +175,7 @@
-

<%= if type == :erc20, do: gettext("ERC-20"), else: gettext("ERC-721")%><%= gettext " Token Transfer" %>

+

<%= token_type_name(type)%><%= gettext " Token Transfer" %>

<%= for transfer <- transaction_with_transfers.token_transfers do %>

diff --git a/apps/block_scout_web/lib/block_scout_web/views/transaction_view.ex b/apps/block_scout_web/lib/block_scout_web/views/transaction_view.ex index a012e138a0..1ed50d28ab 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/transaction_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/transaction_view.ex @@ -35,7 +35,16 @@ defmodule BlockScoutWeb.TransactionView do def token_transfer_type(transaction) do transaction_with_transfers = Repo.preload(transaction, token_transfers: :token) - {Chain.transaction_token_transfer_type(transaction), transaction_with_transfers} + type = Chain.transaction_token_transfer_type(transaction) + if type, do: {type, transaction_with_transfers} + end + + def token_type_name(type) do + case type do + :erc20 -> gettext("ERC-20 ") + :erc721 -> gettext("ERC-721 ") + :token_transfer -> "" + end end def processing_time_duration(%Transaction{block: nil}) do diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 72b907d552..e24db3ef89 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -2943,6 +2943,9 @@ defmodule Explorer.Chain do find_erc721_or_erc20_token_transfer(transaction.token_transfers, {address, decimal_value}) + {_params, ^zero_wei} -> + if Enum.count(transaction.token_transfers) > 0, do: :token_transfer + _ -> nil end From 79bed238e919537e62b534320308cfc4a2ac8296 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 18 Jun 2019 14:07:54 +0300 Subject: [PATCH 04/19] fix gettext --- apps/block_scout_web/priv/gettext/default.pot | 60 +++++++++--------- .../priv/gettext/en/LC_MESSAGES/default.po | 62 +++++++++---------- 2 files changed, 61 insertions(+), 61 deletions(-) diff --git a/apps/block_scout_web/priv/gettext/default.pot b/apps/block_scout_web/priv/gettext/default.pot index 4e05e8266f..01aa2921c3 100644 --- a/apps/block_scout_web/priv/gettext/default.pot +++ b/apps/block_scout_web/priv/gettext/default.pot @@ -49,7 +49,7 @@ msgid "%{subnetwork} Explorer - BlockScout" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:133 +#: lib/block_scout_web/views/transaction_view.ex:144 msgid "(Awaiting internal transactions for status)" msgstr "" @@ -274,12 +274,12 @@ msgid "Contract Address Pending" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:210 +#: lib/block_scout_web/views/transaction_view.ex:221 msgid "Contract Call" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:209 +#: lib/block_scout_web/views/transaction_view.ex:220 msgid "Contract Creation" msgstr "" @@ -362,12 +362,12 @@ msgid "Error trying to fetch balances." msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:137 +#: lib/block_scout_web/views/transaction_view.ex:148 msgid "Error: %{reason}" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:135 +#: lib/block_scout_web/views/transaction_view.ex:146 msgid "Error: (Awaiting internal transactions for reason)" msgstr "" @@ -377,7 +377,7 @@ msgstr "" #: lib/block_scout_web/templates/layout/app.html.eex:55 #: lib/block_scout_web/templates/transaction/_pending_tile.html.eex:20 #: lib/block_scout_web/templates/transaction/_tile.html.eex:30 -#: lib/block_scout_web/templates/transaction/overview.html.eex:192 +#: lib/block_scout_web/templates/transaction/overview.html.eex:194 #: lib/block_scout_web/views/wei_helpers.ex:78 msgid "Ether" msgstr "" @@ -472,7 +472,7 @@ msgstr "" #: lib/block_scout_web/templates/transaction/_tabs.html.eex:11 #: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:6 #: lib/block_scout_web/views/address_view.ex:306 -#: lib/block_scout_web/views/transaction_view.ex:263 +#: lib/block_scout_web/views/transaction_view.ex:274 msgid "Internal Transactions" msgstr "" @@ -489,7 +489,7 @@ msgid "Less than" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:220 +#: lib/block_scout_web/templates/transaction/overview.html.eex:222 msgid "Limit" msgstr "" @@ -499,7 +499,7 @@ msgstr "" #: lib/block_scout_web/templates/transaction/_tabs.html.eex:17 #: lib/block_scout_web/templates/transaction_log/index.html.eex:8 #: lib/block_scout_web/views/address_view.ex:312 -#: lib/block_scout_web/views/transaction_view.ex:264 +#: lib/block_scout_web/views/transaction_view.ex:275 msgid "Logs" msgstr "" @@ -511,7 +511,7 @@ msgid "Market Cap" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:118 +#: lib/block_scout_web/views/transaction_view.ex:129 msgid "Max of" msgstr "" @@ -601,8 +601,8 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/layout/_topnav.html.eex:44 -#: lib/block_scout_web/views/transaction_view.ex:132 -#: lib/block_scout_web/views/transaction_view.ex:166 +#: lib/block_scout_web/views/transaction_view.ex:143 +#: lib/block_scout_web/views/transaction_view.ex:177 msgid "Pending" msgstr "" @@ -689,7 +689,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/transaction/_emission_reward_tile.html.eex:8 -#: lib/block_scout_web/views/transaction_view.ex:134 +#: lib/block_scout_web/views/transaction_view.ex:145 msgid "Success" msgstr "" @@ -794,7 +794,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:5 #: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:4 -#: lib/block_scout_web/views/transaction_view.ex:208 +#: lib/block_scout_web/views/transaction_view.ex:219 msgid "Token Transfer" msgstr "" @@ -804,7 +804,7 @@ msgstr "" #: lib/block_scout_web/templates/transaction/_tabs.html.eex:4 #: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:7 #: lib/block_scout_web/views/tokens/overview_view.ex:35 -#: lib/block_scout_web/views/transaction_view.ex:262 +#: lib/block_scout_web/views/transaction_view.ex:273 msgid "Token Transfers" msgstr "" @@ -844,7 +844,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address_logs/_logs.html.eex:3 -#: lib/block_scout_web/views/transaction_view.ex:211 +#: lib/block_scout_web/views/transaction_view.ex:222 msgid "Transaction" msgstr "" @@ -906,7 +906,7 @@ msgid "Unique Token" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:214 +#: lib/block_scout_web/templates/transaction/overview.html.eex:216 msgid "Used" msgstr "" @@ -926,7 +926,7 @@ msgid "Validations" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:192 +#: lib/block_scout_web/templates/transaction/overview.html.eex:194 msgid "Value" msgstr "" @@ -1519,16 +1519,6 @@ msgstr "" msgid "Optimization runs" msgstr "" -#, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:178 -msgid "ERC-20" -msgstr "" - -#, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:178 -msgid "ERC-721" -msgstr "" - #, elixir-format #: lib/block_scout_web/templates/api_docs/index.html.eex:4 msgid "API Documentation" @@ -1545,14 +1535,14 @@ msgid "View All Transactions" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:210 +#: lib/block_scout_web/templates/transaction/overview.html.eex:212 msgid "Gas" msgstr "" #, elixir-format #: lib/block_scout_web/templates/transaction/_tabs.html.eex:24 #: lib/block_scout_web/templates/transaction_raw_trace/index.html.eex:7 -#: lib/block_scout_web/views/transaction_view.ex:265 +#: lib/block_scout_web/views/transaction_view.ex:276 msgid "Raw Trace" msgstr "" @@ -1702,3 +1692,13 @@ msgstr "" #: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:27 msgid "There is no decompilded contracts for this address." msgstr "" + +#, elixir-format +#: lib/block_scout_web/views/transaction_view.ex:44 +msgid "ERC-20 " +msgstr "" + +#, elixir-format +#: lib/block_scout_web/views/transaction_view.ex:45 +msgid "ERC-721 " +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 142aec2b37..b90f812c34 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 @@ -49,7 +49,7 @@ msgid "%{subnetwork} Explorer - BlockScout" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:133 +#: lib/block_scout_web/views/transaction_view.ex:144 msgid "(Awaiting internal transactions for status)" msgstr "" @@ -274,12 +274,12 @@ msgid "Contract Address Pending" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:210 +#: lib/block_scout_web/views/transaction_view.ex:221 msgid "Contract Call" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:209 +#: lib/block_scout_web/views/transaction_view.ex:220 msgid "Contract Creation" msgstr "" @@ -362,12 +362,12 @@ msgid "Error trying to fetch balances." msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:137 +#: lib/block_scout_web/views/transaction_view.ex:148 msgid "Error: %{reason}" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:135 +#: lib/block_scout_web/views/transaction_view.ex:146 msgid "Error: (Awaiting internal transactions for reason)" msgstr "" @@ -377,7 +377,7 @@ msgstr "" #: lib/block_scout_web/templates/layout/app.html.eex:55 #: lib/block_scout_web/templates/transaction/_pending_tile.html.eex:20 #: lib/block_scout_web/templates/transaction/_tile.html.eex:30 -#: lib/block_scout_web/templates/transaction/overview.html.eex:192 +#: lib/block_scout_web/templates/transaction/overview.html.eex:194 #: lib/block_scout_web/views/wei_helpers.ex:78 msgid "Ether" msgstr "POA" @@ -472,7 +472,7 @@ msgstr "" #: lib/block_scout_web/templates/transaction/_tabs.html.eex:11 #: lib/block_scout_web/templates/transaction_internal_transaction/index.html.eex:6 #: lib/block_scout_web/views/address_view.ex:306 -#: lib/block_scout_web/views/transaction_view.ex:263 +#: lib/block_scout_web/views/transaction_view.ex:274 msgid "Internal Transactions" msgstr "" @@ -489,7 +489,7 @@ msgid "Less than" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:220 +#: lib/block_scout_web/templates/transaction/overview.html.eex:222 msgid "Limit" msgstr "" @@ -499,7 +499,7 @@ msgstr "" #: lib/block_scout_web/templates/transaction/_tabs.html.eex:17 #: lib/block_scout_web/templates/transaction_log/index.html.eex:8 #: lib/block_scout_web/views/address_view.ex:312 -#: lib/block_scout_web/views/transaction_view.ex:264 +#: lib/block_scout_web/views/transaction_view.ex:275 msgid "Logs" msgstr "" @@ -511,7 +511,7 @@ msgid "Market Cap" msgstr "" #, elixir-format -#: lib/block_scout_web/views/transaction_view.ex:118 +#: lib/block_scout_web/views/transaction_view.ex:129 msgid "Max of" msgstr "" @@ -601,8 +601,8 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/layout/_topnav.html.eex:44 -#: lib/block_scout_web/views/transaction_view.ex:132 -#: lib/block_scout_web/views/transaction_view.ex:166 +#: lib/block_scout_web/views/transaction_view.ex:143 +#: lib/block_scout_web/views/transaction_view.ex:177 msgid "Pending" msgstr "" @@ -689,7 +689,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/transaction/_emission_reward_tile.html.eex:8 -#: lib/block_scout_web/views/transaction_view.ex:134 +#: lib/block_scout_web/views/transaction_view.ex:145 msgid "Success" msgstr "" @@ -794,7 +794,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/tokens/transfer/_token_transfer.html.eex:5 #: lib/block_scout_web/templates/transaction_token_transfer/_token_transfer.html.eex:4 -#: lib/block_scout_web/views/transaction_view.ex:208 +#: lib/block_scout_web/views/transaction_view.ex:219 msgid "Token Transfer" msgstr "" @@ -804,7 +804,7 @@ msgstr "" #: lib/block_scout_web/templates/transaction/_tabs.html.eex:4 #: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:7 #: lib/block_scout_web/views/tokens/overview_view.ex:35 -#: lib/block_scout_web/views/transaction_view.ex:262 +#: lib/block_scout_web/views/transaction_view.ex:273 msgid "Token Transfers" msgstr "" @@ -844,7 +844,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address_logs/_logs.html.eex:3 -#: lib/block_scout_web/views/transaction_view.ex:211 +#: lib/block_scout_web/views/transaction_view.ex:222 msgid "Transaction" msgstr "" @@ -906,7 +906,7 @@ msgid "Unique Token" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:214 +#: lib/block_scout_web/templates/transaction/overview.html.eex:216 msgid "Used" msgstr "" @@ -926,7 +926,7 @@ msgid "Validations" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:192 +#: lib/block_scout_web/templates/transaction/overview.html.eex:194 msgid "Value" msgstr "" @@ -1519,16 +1519,6 @@ msgstr "" msgid "Optimization runs" msgstr "" -#, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:178 -msgid "ERC-20" -msgstr "" - -#, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:178 -msgid "ERC-721" -msgstr "" - #, elixir-format #: lib/block_scout_web/templates/api_docs/index.html.eex:4 msgid "API Documentation" @@ -1545,14 +1535,14 @@ msgid "View All Transactions" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:210 +#: lib/block_scout_web/templates/transaction/overview.html.eex:212 msgid "Gas" msgstr "" #, elixir-format #: lib/block_scout_web/templates/transaction/_tabs.html.eex:24 #: lib/block_scout_web/templates/transaction_raw_trace/index.html.eex:7 -#: lib/block_scout_web/views/transaction_view.ex:265 +#: lib/block_scout_web/views/transaction_view.ex:276 msgid "Raw Trace" msgstr "" @@ -1698,7 +1688,17 @@ msgstr "" msgid " Token Transfer" msgstr "" -#, elixir-format, fuzzy +#, elixir-format #: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:27 msgid "There is no decompilded contracts for this address." msgstr "" + +#, elixir-format, fuzzy +#: lib/block_scout_web/views/transaction_view.ex:44 +msgid "ERC-20 " +msgstr "" + +#, elixir-format, fuzzy +#: lib/block_scout_web/views/transaction_view.ex:45 +msgid "ERC-721 " +msgstr "" From 20140b0fcb272309f4a1e7710c2d9979d52e0128 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 18 Jun 2019 14:09:01 +0300 Subject: [PATCH 05/19] fix dialyzer --- apps/explorer/lib/explorer/chain.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index e24db3ef89..8284a0e2ac 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -2896,7 +2896,7 @@ defmodule Explorer.Chain do end @spec transaction_token_transfer_type(Transaction.t()) :: - {:erc20, TokenTransfer.t()} | {:erc721, TokenTransfer.t()} | nil + :erc20 | :erc721 | :token_transfer | nil def transaction_token_transfer_type( %Transaction{ status: :ok, From 33eb12091054995f7b9be9c694d7e2cdd24186ef Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 18 Jun 2019 14:48:30 +0300 Subject: [PATCH 06/19] fix tests --- apps/explorer/test/explorer/chain_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/explorer/test/explorer/chain_test.exs b/apps/explorer/test/explorer/chain_test.exs index 442d051e0d..2cc8273adf 100644 --- a/apps/explorer/test/explorer/chain_test.exs +++ b/apps/explorer/test/explorer/chain_test.exs @@ -3954,7 +3954,7 @@ defmodule Explorer.ChainTest do insert(:token_transfer, from_address: from_address, to_address: to_address, transaction: transaction) - assert {:erc721, _found_token_transfer} = Chain.transaction_token_transfer_type(transaction) + assert :erc721 = Chain.transaction_token_transfer_type(Repo.preload(transaction, :token_trasfers)) end test "detects erc20 token transfer" do @@ -3980,7 +3980,7 @@ defmodule Explorer.ChainTest do amount: 8_025_000_000_000_000_000_000 ) - assert {:erc20, _found_token_transfer} = Chain.transaction_token_transfer_type(transaction) + assert :erc20 = Chain.transaction_token_transfer_type(Repo.preload(transaction, :token_trasfers)) end end From 96bfe828fb7e8f161562c7f6798e122d71400860 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 18 Jun 2019 14:56:14 +0300 Subject: [PATCH 07/19] fix typo --- apps/explorer/test/explorer/chain_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/explorer/test/explorer/chain_test.exs b/apps/explorer/test/explorer/chain_test.exs index 2cc8273adf..5e7472bae1 100644 --- a/apps/explorer/test/explorer/chain_test.exs +++ b/apps/explorer/test/explorer/chain_test.exs @@ -3954,7 +3954,7 @@ defmodule Explorer.ChainTest do insert(:token_transfer, from_address: from_address, to_address: to_address, transaction: transaction) - assert :erc721 = Chain.transaction_token_transfer_type(Repo.preload(transaction, :token_trasfers)) + assert :erc721 = Chain.transaction_token_transfer_type(Repo.preload(transaction, :token_transfers)) end test "detects erc20 token transfer" do @@ -3980,7 +3980,7 @@ defmodule Explorer.ChainTest do amount: 8_025_000_000_000_000_000_000 ) - assert :erc20 = Chain.transaction_token_transfer_type(Repo.preload(transaction, :token_trasfers)) + assert :erc20 = Chain.transaction_token_transfer_type(Repo.preload(transaction, :token_transfers)) end end From 0ac8d0e10a331dc6caed54cf1b5b3658bf9763da Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 18 Jun 2019 15:04:59 +0300 Subject: [PATCH 08/19] preload token --- apps/explorer/test/explorer/chain_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/explorer/test/explorer/chain_test.exs b/apps/explorer/test/explorer/chain_test.exs index 5e7472bae1..f789a883ea 100644 --- a/apps/explorer/test/explorer/chain_test.exs +++ b/apps/explorer/test/explorer/chain_test.exs @@ -3954,7 +3954,7 @@ defmodule Explorer.ChainTest do insert(:token_transfer, from_address: from_address, to_address: to_address, transaction: transaction) - assert :erc721 = Chain.transaction_token_transfer_type(Repo.preload(transaction, :token_transfers)) + assert :erc721 = Chain.transaction_token_transfer_type(Repo.preload(transaction, token_transfers: :token)) end test "detects erc20 token transfer" do @@ -3980,7 +3980,7 @@ defmodule Explorer.ChainTest do amount: 8_025_000_000_000_000_000_000 ) - assert :erc20 = Chain.transaction_token_transfer_type(Repo.preload(transaction, :token_transfers)) + assert :erc20 = Chain.transaction_token_transfer_type(Repo.preload(transaction, token_transfers: :token)) end end From b30ff3de25f9540e629bcee8751a10ee3797b4af Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 18 Jun 2019 15:16:46 +0300 Subject: [PATCH 09/19] add CHANGELOG entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb0a5f0898..487e4d6266 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## Current ### Features +- [#2190](https://github.com/poanetwork/blockscout/pull/2190) - show all token transfers - [#2109](https://github.com/poanetwork/blockscout/pull/2109) - use bigger updates instead of `Multi` transactions in BlocksTransactionsMismatch - [#2075](https://github.com/poanetwork/blockscout/pull/2075) - add blocks cache - [#2151](https://github.com/poanetwork/blockscout/pull/2151) - hide dropdown menu then other networks list is empty From 99d0a98fd37e0d5fd150c942072b6d60ed17c919 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 18 Jun 2019 15:18:00 +0300 Subject: [PATCH 10/19] fix CHANGELOG --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 487e4d6266..891517bd5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ ## Current +### Features + - [#2190](https://github.com/poanetwork/blockscout/pull/2190) - show all token transfers ### Features -- [#2190](https://github.com/poanetwork/blockscout/pull/2190) - show all token transfers - [#2109](https://github.com/poanetwork/blockscout/pull/2109) - use bigger updates instead of `Multi` transactions in BlocksTransactionsMismatch - [#2075](https://github.com/poanetwork/blockscout/pull/2075) - add blocks cache - [#2151](https://github.com/poanetwork/blockscout/pull/2151) - hide dropdown menu then other networks list is empty From 262b59abcee564a53492d256d031a4b955bdeab4 Mon Sep 17 00:00:00 2001 From: zachdaniel Date: Tue, 18 Jun 2019 11:08:33 -0400 Subject: [PATCH 11/19] feat: add BLOCKSCOUT_HOST, and use it in API docs --- CHANGELOG.md | 1 + apps/block_scout_web/config/config.exs | 2 +- .../lib/block_scout_web/templates/api_docs/eth_rpc.html.eex | 2 +- .../lib/block_scout_web/templates/api_docs/index.html.eex | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4e62d4751..4d440f38ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - [#2075](https://github.com/poanetwork/blockscout/pull/2075) - add blocks cache - [#2151](https://github.com/poanetwork/blockscout/pull/2151) - hide dropdown menu then other networks list is empty - [#2146](https://github.com/poanetwork/blockscout/pull/2146) - feat: add eth_getLogs rpc endpoint +- [#2193](https://github.com/poanetwork/blockscout/pull/2193) - feat: add BLOCKSCOUT_HOST, and use it in API docs ### Fixes - [#2201](https://github.com/poanetwork/blockscout/pull/2201) - footer columns fix diff --git a/apps/block_scout_web/config/config.exs b/apps/block_scout_web/config/config.exs index e601e299f8..28d142eb5c 100644 --- a/apps/block_scout_web/config/config.exs +++ b/apps/block_scout_web/config/config.exs @@ -41,7 +41,7 @@ config :block_scout_web, BlockScoutWeb.Endpoint, ] ], url: [ - host: "localhost", + host: System.get_env("BLOCKSCOUT_HOST") || "localhost", path: System.get_env("NETWORK_PATH") || "/" ], render_errors: [view: BlockScoutWeb.ErrorView, accepts: ~w(html json)], diff --git a/apps/block_scout_web/lib/block_scout_web/templates/api_docs/eth_rpc.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/api_docs/eth_rpc.html.eex index f85620681a..3a0338f4a3 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/api_docs/eth_rpc.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/api_docs/eth_rpc.html.eex @@ -2,7 +2,7 @@

<%= gettext("ETH RPC API Documentation") %>

-

[ <%= gettext "Base URL:" %> <%= @conn.host %>/api/eth_rpc ]

+

[ <%= gettext "Base URL:" %> <%= BlockScoutWeb.Endpoint.url() %>/api/eth_rpc ]

<%= gettext "This API is provided to support some rpc methods in the exact format specified for ethereum nodes, which can be found " %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/api_docs/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/api_docs/index.html.eex index c665fb88e6..0f97b67d45 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/api_docs/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/api_docs/index.html.eex @@ -2,7 +2,7 @@

<%= gettext("API Documentation") %>

-

[ <%= gettext "Base URL:" %> <%= @conn.host %>/api ]

+

[ <%= gettext "Base URL:" %> <%= BlockScoutWeb.Endpoint.url() %>/api ]

<%= gettext "This API is provided for developers transitioning their applications from Etherscan to BlockScout. It supports GET and POST requests." %>

From 91f33e2f38f9dfb154f861f3c48f2cfc8e1b72a5 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 25 Jun 2019 10:33:49 +0300 Subject: [PATCH 12/19] fix gettext --- apps/block_scout_web/priv/gettext/default.pot | 57 +++++++++++++- .../priv/gettext/en/LC_MESSAGES/default.po | 77 ++++++++++++++++--- 2 files changed, 122 insertions(+), 12 deletions(-) diff --git a/apps/block_scout_web/priv/gettext/default.pot b/apps/block_scout_web/priv/gettext/default.pot index b6fcc69fcc..d21d2703bd 100644 --- a/apps/block_scout_web/priv/gettext/default.pot +++ b/apps/block_scout_web/priv/gettext/default.pot @@ -1692,4 +1692,59 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:27 msgid "There is no decompilded contracts for this address." -msgstr "" \ No newline at end of file +msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:14 +msgid " is recommended." +msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:15 +msgid "Anything not in this list is not supported. Click on the method to be taken to the documentation for that method, and check the notes section for any potential differences." +msgstr "" + +#, elixir-format +#: lib/block_scout_web/views/transaction_view.ex:44 +msgid "ERC-20 " +msgstr "" + +#, elixir-format +#: lib/block_scout_web/views/transaction_view.ex:45 +msgid "ERC-721 " +msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:4 +msgid "ETH RPC API Documentation" +msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/layout/_topnav.html.eex:78 +msgid "Eth RPC" +msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:11 +msgid "However, in general, the" +msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:7 +msgid "This API is provided to support some rpc methods in the exact format specified for ethereum nodes, which can be found " +msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:10 +msgid "This is useful to allow sending requests to blockscout without having to change anything about the request." +msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:12 +msgid "custom RPC" +msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:9 +msgid "here." +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 be7eb43b58..ee32dea6ce 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 @@ -105,7 +105,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/index.html.eex:4 -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:59 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:60 msgid "Addresses" msgstr "" @@ -210,8 +210,8 @@ msgstr "" #: lib/block_scout_web/templates/address/_validator_metadata_modal.html.eex:37 #: lib/block_scout_web/templates/address/overview.html.eex:144 #: lib/block_scout_web/templates/address/overview.html.eex:152 -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:106 -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:114 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:107 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:115 msgid "Close" msgstr "" @@ -626,8 +626,8 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/overview.html.eex:33 #: lib/block_scout_web/templates/address/overview.html.eex:143 -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:35 -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:105 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:36 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:106 msgid "QR Code" msgstr "" @@ -684,7 +684,7 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address/overview.html.eex:34 -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:36 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:37 msgid "Show QR Code" msgstr "" @@ -834,7 +834,7 @@ msgid "Total Difficulty" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:74 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:75 msgid "Total Supply" msgstr "" @@ -881,7 +881,7 @@ msgid "Transactions sent" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:60 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:61 msgid "Transfers" msgstr "" @@ -943,7 +943,7 @@ msgid "Verify & publish" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:54 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:55 msgid "View Contract" msgstr "" @@ -1048,7 +1048,7 @@ msgid "Self-Destruct" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:62 +#: lib/block_scout_web/templates/tokens/overview/_details.html.eex:63 msgid "Decimals" msgstr "" @@ -1692,4 +1692,59 @@ msgstr "" #, elixir-format #: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:27 msgid "There is no decompilded contracts for this address." -msgstr "" \ No newline at end of file +msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:14 +msgid " is recommended." +msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:15 +msgid "Anything not in this list is not supported. Click on the method to be taken to the documentation for that method, and check the notes section for any potential differences." +msgstr "" + +#, elixir-format +#: lib/block_scout_web/views/transaction_view.ex:44 +msgid "ERC-20 " +msgstr "" + +#, elixir-format +#: lib/block_scout_web/views/transaction_view.ex:45 +msgid "ERC-721 " +msgstr "" + +#, elixir-format, fuzzy +#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:4 +msgid "ETH RPC API Documentation" +msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/layout/_topnav.html.eex:78 +msgid "Eth RPC" +msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:11 +msgid "However, in general, the" +msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:7 +msgid "This API is provided to support some rpc methods in the exact format specified for ethereum nodes, which can be found " +msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:10 +msgid "This is useful to allow sending requests to blockscout without having to change anything about the request." +msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:12 +msgid "custom RPC" +msgstr "" + +#, elixir-format, fuzzy +#: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:9 +msgid "here." +msgstr "" From 7cb662d09999b76443ecb16640d401110ea5d10f Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 25 Jun 2019 10:44:47 +0300 Subject: [PATCH 13/19] fix unidentified token transfers --- apps/explorer/lib/explorer/chain.ex | 61 +++++++++++++++-------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 4834a20adf..01a44e1cbe 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -2935,47 +2935,50 @@ defmodule Explorer.Chain do zero_wei = %Wei{value: Decimal.new(0)} # https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/token/ERC721/ERC721.sol#L35 - case {to_string(input), value} do - # transferFrom(address,address,uint256) - {"0x23b872dd" <> params, ^zero_wei} -> - types = [:address, :address, {:uint, 256}] - [from_address, to_address, _value] = decode_params(params, types) + result = + case {to_string(input), value} do + # transferFrom(address,address,uint256) + {"0x23b872dd" <> params, ^zero_wei} -> + types = [:address, :address, {:uint, 256}] + [from_address, to_address, _value] = decode_params(params, types) - find_erc721_token_transfer(transaction.token_transfers, {from_address, to_address}) + find_erc721_token_transfer(transaction.token_transfers, {from_address, to_address}) - # safeTransferFrom(address,address,uint256) - {"0x42842e0e" <> params, ^zero_wei} -> - types = [:address, :address, {:uint, 256}] - [from_address, to_address, _value] = decode_params(params, types) + # safeTransferFrom(address,address,uint256) + {"0x42842e0e" <> params, ^zero_wei} -> + types = [:address, :address, {:uint, 256}] + [from_address, to_address, _value] = decode_params(params, types) - find_erc721_token_transfer(transaction.token_transfers, {from_address, to_address}) + find_erc721_token_transfer(transaction.token_transfers, {from_address, to_address}) - # safeTransferFrom(address,address,uint256,bytes) - {"0xb88d4fde" <> params, ^zero_wei} -> - types = [:address, :address, {:uint, 256}, :bytes] - [from_address, to_address, _value, _data] = decode_params(params, types) + # safeTransferFrom(address,address,uint256,bytes) + {"0xb88d4fde" <> params, ^zero_wei} -> + types = [:address, :address, {:uint, 256}, :bytes] + [from_address, to_address, _value, _data] = decode_params(params, types) - find_erc721_token_transfer(transaction.token_transfers, {from_address, to_address}) + find_erc721_token_transfer(transaction.token_transfers, {from_address, to_address}) - {"0xf907fc5b" <> _params, ^zero_wei} -> - :erc20 + {"0xf907fc5b" <> _params, ^zero_wei} -> + :erc20 - # check for ERC 20 or for old ERC 721 token versions - {unquote(TokenTransfer.transfer_function_signature()) <> params, ^zero_wei} -> - types = [:address, {:uint, 256}] + # check for ERC 20 or for old ERC 721 token versions + {unquote(TokenTransfer.transfer_function_signature()) <> params, ^zero_wei} -> + types = [:address, {:uint, 256}] - [address, value] = decode_params(params, types) + [address, value] = decode_params(params, types) - decimal_value = Decimal.new(value) + decimal_value = Decimal.new(value) - find_erc721_or_erc20_token_transfer(transaction.token_transfers, {address, decimal_value}) + find_erc721_or_erc20_token_transfer(transaction.token_transfers, {address, decimal_value}) - {_params, ^zero_wei} -> - if Enum.count(transaction.token_transfers) > 0, do: :token_transfer + {_params, ^zero_wei} -> + if Enum.count(transaction.token_transfers) > 0, do: :token_transfer - _ -> - nil - end + _ -> + nil + end + + if is_nil(result) && Enum.count(transaction.token_transfers) > 0, do: :token_transfer, else: result rescue _ -> nil end From d8f904f063c9628a2eb08f3e2015aadf8a865337 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 25 Jun 2019 11:04:26 +0300 Subject: [PATCH 14/19] fix spaces --- .../block_scout_web/templates/transaction/overview.html.eex | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/block_scout_web/lib/block_scout_web/templates/transaction/overview.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/transaction/overview.html.eex index b168045fe1..fe347ee904 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/transaction/overview.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/transaction/overview.html.eex @@ -176,14 +176,16 @@

<%= token_type_name(type)%><%= gettext " Token Transfer" %>

- <%= for transfer <- transaction_with_transfers.token_transfers do %>
+ <%= for transfer <- transaction_with_transfers.token_transfers do %> +

<%= token_transfer_amount(transfer) %> <%= link(token_symbol(transfer.token), to: token_path(BlockScoutWeb.Endpoint, :show, transfer.token.contract_address_hash)) %>

-
+ <% end %> +
<% _ -> %> From 41b069c1e1fd09137ee09cb04557cf4676de1aca Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 25 Jun 2019 11:11:22 +0300 Subject: [PATCH 15/19] fix credo --- apps/explorer/lib/explorer/chain.ex | 75 +++++++++++++++-------------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 01a44e1cbe..e4416030b0 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -2933,58 +2933,61 @@ defmodule Explorer.Chain do } = transaction ) do zero_wei = %Wei{value: Decimal.new(0)} + result = find_token_transfer_type(transaction, input, value) - # https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/token/ERC721/ERC721.sol#L35 - result = - case {to_string(input), value} do - # transferFrom(address,address,uint256) - {"0x23b872dd" <> params, ^zero_wei} -> - types = [:address, :address, {:uint, 256}] - [from_address, to_address, _value] = decode_params(params, types) + if is_nil(result) && Enum.count(transaction.token_transfers) > 0 && value == zero_wei, + do: :token_transfer, + else: result + rescue + _ -> nil + end + + def transaction_token_transfer_type(_), do: nil - find_erc721_token_transfer(transaction.token_transfers, {from_address, to_address}) + defp find_token_transfer_type(transaction, input, value) do + zero_wei = %Wei{value: Decimal.new(0)} - # safeTransferFrom(address,address,uint256) - {"0x42842e0e" <> params, ^zero_wei} -> - types = [:address, :address, {:uint, 256}] - [from_address, to_address, _value] = decode_params(params, types) + # https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/token/ERC721/ERC721.sol#L35 + case {to_string(input), value} do + # transferFrom(address,address,uint256) + {"0x23b872dd" <> params, ^zero_wei} -> + types = [:address, :address, {:uint, 256}] + [from_address, to_address, _value] = decode_params(params, types) - find_erc721_token_transfer(transaction.token_transfers, {from_address, to_address}) + find_erc721_token_transfer(transaction.token_transfers, {from_address, to_address}) - # safeTransferFrom(address,address,uint256,bytes) - {"0xb88d4fde" <> params, ^zero_wei} -> - types = [:address, :address, {:uint, 256}, :bytes] - [from_address, to_address, _value, _data] = decode_params(params, types) + # safeTransferFrom(address,address,uint256) + {"0x42842e0e" <> params, ^zero_wei} -> + types = [:address, :address, {:uint, 256}] + [from_address, to_address, _value] = decode_params(params, types) - find_erc721_token_transfer(transaction.token_transfers, {from_address, to_address}) + find_erc721_token_transfer(transaction.token_transfers, {from_address, to_address}) - {"0xf907fc5b" <> _params, ^zero_wei} -> - :erc20 + # safeTransferFrom(address,address,uint256,bytes) + {"0xb88d4fde" <> params, ^zero_wei} -> + types = [:address, :address, {:uint, 256}, :bytes] + [from_address, to_address, _value, _data] = decode_params(params, types) - # check for ERC 20 or for old ERC 721 token versions - {unquote(TokenTransfer.transfer_function_signature()) <> params, ^zero_wei} -> - types = [:address, {:uint, 256}] + find_erc721_token_transfer(transaction.token_transfers, {from_address, to_address}) - [address, value] = decode_params(params, types) + {"0xf907fc5b" <> _params, ^zero_wei} -> + :erc20 - decimal_value = Decimal.new(value) + # check for ERC 20 or for old ERC 721 token versions + {unquote(TokenTransfer.transfer_function_signature()) <> params, ^zero_wei} -> + types = [:address, {:uint, 256}] - find_erc721_or_erc20_token_transfer(transaction.token_transfers, {address, decimal_value}) + [address, value] = decode_params(params, types) - {_params, ^zero_wei} -> - if Enum.count(transaction.token_transfers) > 0, do: :token_transfer + decimal_value = Decimal.new(value) - _ -> - nil - end + find_erc721_or_erc20_token_transfer(transaction.token_transfers, {address, decimal_value}) - if is_nil(result) && Enum.count(transaction.token_transfers) > 0, do: :token_transfer, else: result - rescue - _ -> nil + _ -> + nil + end end - def transaction_token_transfer_type(_), do: nil - defp find_erc721_token_transfer(token_transfers, {from_address, to_address}) do token_transfer = Enum.find(token_transfers, fn token_transfer -> From 6d2e355ece5007f8c86edbcb840633d0f0a0aeb0 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 25 Jun 2019 11:12:00 +0300 Subject: [PATCH 16/19] fix gettext --- apps/block_scout_web/priv/gettext/default.pot | 10 +++++----- .../priv/gettext/en/LC_MESSAGES/default.po | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/apps/block_scout_web/priv/gettext/default.pot b/apps/block_scout_web/priv/gettext/default.pot index d21d2703bd..5a0edf2bfe 100644 --- a/apps/block_scout_web/priv/gettext/default.pot +++ b/apps/block_scout_web/priv/gettext/default.pot @@ -378,7 +378,7 @@ msgstr "" #: lib/block_scout_web/templates/layout/app.html.eex:55 #: lib/block_scout_web/templates/transaction/_pending_tile.html.eex:20 #: lib/block_scout_web/templates/transaction/_tile.html.eex:30 -#: lib/block_scout_web/templates/transaction/overview.html.eex:194 +#: lib/block_scout_web/templates/transaction/overview.html.eex:196 #: lib/block_scout_web/views/wei_helpers.ex:78 msgid "Ether" msgstr "" @@ -490,7 +490,7 @@ msgid "Less than" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:222 +#: lib/block_scout_web/templates/transaction/overview.html.eex:224 msgid "Limit" msgstr "" @@ -907,7 +907,7 @@ msgid "Unique Token" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:216 +#: lib/block_scout_web/templates/transaction/overview.html.eex:218 msgid "Used" msgstr "" @@ -927,7 +927,7 @@ msgid "Validations" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:194 +#: lib/block_scout_web/templates/transaction/overview.html.eex:196 msgid "Value" msgstr "" @@ -1536,7 +1536,7 @@ msgid "View All Transactions" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:212 +#: lib/block_scout_web/templates/transaction/overview.html.eex:214 msgid "Gas" 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 ee32dea6ce..45a2e7d8de 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 @@ -378,7 +378,7 @@ msgstr "" #: lib/block_scout_web/templates/layout/app.html.eex:55 #: lib/block_scout_web/templates/transaction/_pending_tile.html.eex:20 #: lib/block_scout_web/templates/transaction/_tile.html.eex:30 -#: lib/block_scout_web/templates/transaction/overview.html.eex:194 +#: lib/block_scout_web/templates/transaction/overview.html.eex:196 #: lib/block_scout_web/views/wei_helpers.ex:78 msgid "Ether" msgstr "POA" @@ -490,7 +490,7 @@ msgid "Less than" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:222 +#: lib/block_scout_web/templates/transaction/overview.html.eex:224 msgid "Limit" msgstr "" @@ -907,7 +907,7 @@ msgid "Unique Token" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:216 +#: lib/block_scout_web/templates/transaction/overview.html.eex:218 msgid "Used" msgstr "" @@ -927,7 +927,7 @@ msgid "Validations" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:194 +#: lib/block_scout_web/templates/transaction/overview.html.eex:196 msgid "Value" msgstr "" @@ -1536,7 +1536,7 @@ msgid "View All Transactions" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/transaction/overview.html.eex:212 +#: lib/block_scout_web/templates/transaction/overview.html.eex:214 msgid "Gas" msgstr "" @@ -1714,7 +1714,7 @@ msgstr "" msgid "ERC-721 " msgstr "" -#, elixir-format, fuzzy +#, elixir-format #: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:4 msgid "ETH RPC API Documentation" msgstr "" @@ -1744,7 +1744,7 @@ msgstr "" msgid "custom RPC" msgstr "" -#, elixir-format, fuzzy +#, elixir-format #: lib/block_scout_web/templates/api_docs/eth_rpc.html.eex:9 msgid "here." msgstr "" From d47cb2bda41c79230be0054ee6baea82972f7e4d Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Tue, 25 Jun 2019 15:59:17 +0300 Subject: [PATCH 17/19] fix port --- .../templates/api_docs/eth_rpc.html.eex | 4 ++-- .../block_scout_web/templates/api_docs/index.html.eex | 2 +- .../lib/block_scout_web/views/api_docs_view.ex | 10 +++++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/apps/block_scout_web/lib/block_scout_web/templates/api_docs/eth_rpc.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/api_docs/eth_rpc.html.eex index 3a0338f4a3..37b9ecdaa2 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/api_docs/eth_rpc.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/api_docs/eth_rpc.html.eex @@ -2,9 +2,9 @@

<%= gettext("ETH RPC API Documentation") %>

-

[ <%= gettext "Base URL:" %> <%= BlockScoutWeb.Endpoint.url() %>/api/eth_rpc ]

+

[ <%= gettext "Base URL:" %> <%= url() %>/api/eth_rpc ]

- <%= gettext "This API is provided to support some rpc methods in the exact format specified for ethereum nodes, which can be found " %> + <%= gettext "This API is provided to support some rpc methods in the exact format specified for ethereum nodes, which can be found " %> <%= gettext "here." %> <%= gettext "This is useful to allow sending requests to blockscout without having to change anything about the request." %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/api_docs/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/api_docs/index.html.eex index 0f97b67d45..5244458bb6 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/api_docs/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/api_docs/index.html.eex @@ -2,7 +2,7 @@

<%= gettext("API Documentation") %>

-

[ <%= gettext "Base URL:" %> <%= BlockScoutWeb.Endpoint.url() %>/api ]

+

[ <%= gettext "Base URL:" %> <%= url() %>/api ]

<%= gettext "This API is provided for developers transitioning their applications from Etherscan to BlockScout. It supports GET and POST requests." %>

diff --git a/apps/block_scout_web/lib/block_scout_web/views/api_docs_view.ex b/apps/block_scout_web/lib/block_scout_web/views/api_docs_view.ex index cbc096aeb8..267099fa2b 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/api_docs_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/api_docs_view.ex @@ -1,7 +1,7 @@ defmodule BlockScoutWeb.APIDocsView do use BlockScoutWeb, :view - alias BlockScoutWeb.LayoutView + alias BlockScoutWeb.{Endpoint, LayoutView} def action_tile_id(module, action) do "#{module}-#{action}" @@ -33,4 +33,12 @@ defmodule BlockScoutWeb.APIDocsView do "&#{param.key}=" <> "{#{param.placeholder}}" end) end + + defp url do + if System.get_env("BLOCKSCOUT_HOST") do + "http://" <> System.get_env("BLOCKSCOUT_HOST") + else + Endpoint.url() + end + end end From 623be25cc208cd88924e6ca2c16e95877f29d989 Mon Sep 17 00:00:00 2001 From: maxgrapps Date: Wed, 26 Jun 2019 18:27:50 +0300 Subject: [PATCH 18/19] search length issue, tile link wrapping issue --- .../assets/css/components/_navbar.scss | 12 +++--------- .../templates/address/_responsive_hash.html.eex | 4 ++-- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/apps/block_scout_web/assets/css/components/_navbar.scss b/apps/block_scout_web/assets/css/components/_navbar.scss index 1058c529c6..b8855a63ae 100644 --- a/apps/block_scout_web/assets/css/components/_navbar.scss +++ b/apps/block_scout_web/assets/css/components/_navbar.scss @@ -151,19 +151,13 @@ $navbar-logo-width: auto !default; } @include media-breakpoint-up(xl) { - width: 280px; + width: 340px; } @media (min-width: 1366px) { - width: 330px; + width: 500px; } @media (min-width: 1440px) { - width: 380px; - } - @media (min-width: 1580px) { - width: 430px; - } - @media (min-width: 1800px) { - width: 520px; + width: 580px; } } .input-group-append { diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address/_responsive_hash.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address/_responsive_hash.html.eex index 22e0f76870..cad11f8ee6 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address/_responsive_hash.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address/_responsive_hash.html.eex @@ -5,8 +5,8 @@ <%= if assigns[:truncate] do %> <%= BlockScoutWeb.AddressView.trimmed_hash(@address.hash) %> <% else %> - <%= @address %> - <%= BlockScoutWeb.AddressView.trimmed_hash(@address.hash) %> + <%= @address %> + <%= BlockScoutWeb.AddressView.trimmed_hash(@address.hash) %> <% end %> <% end %> From baae13933d7913ab310b462bce7eb6f944042376 Mon Sep 17 00:00:00 2001 From: maxgrapps <50101080+maxgrapps@users.noreply.github.com> Date: Wed, 26 Jun 2019 18:31:01 +0300 Subject: [PATCH 19/19] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bba5170e0b..a578eab389 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - [#2193](https://github.com/poanetwork/blockscout/pull/2193) - feat: add BLOCKSCOUT_HOST, and use it in API docs ### Fixes +- [#2254](https://github.com/poanetwork/blockscout/pull/2254) - search length issue, tile link wrapping issue - [#2238](https://github.com/poanetwork/blockscout/pull/2238) - header content alignment issue, hide navbar on outside click - [#2229](https://github.com/poanetwork/blockscout/pull/2229) - gap issue between qr and copy button in token transfers, top cards width and height issue - [#2201](https://github.com/poanetwork/blockscout/pull/2201) - footer columns fix