Merge branch 'master' into upstream/bugfix/token_balance_fetch

pull/4538/head
Donald Hutchison 3 years ago committed by GitHub
commit 4ae918982d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 66
      apps/block_scout_web/lib/block_scout_web/controllers/address_contract_verification_controller.ex
  3. 6
      apps/block_scout_web/lib/block_scout_web/templates/address_token_balance/_tokens.html.eex
  4. 1
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/block.ex
  5. 53
      apps/indexer/lib/indexer/transform/token_transfers.ex

@ -8,6 +8,7 @@
- [#4452](https://github.com/blockscout/blockscout/pull/4452) - Add names for smart-conrtact's function response - [#4452](https://github.com/blockscout/blockscout/pull/4452) - Add names for smart-conrtact's function response
### Fixes ### Fixes
- [#4535](https://github.com/blockscout/blockscout/pull/4535) - Indexer performance update:: Eliminate multiple updates of the same token while parsing mint/burn token transfers batch
- [#4527](https://github.com/blockscout/blockscout/pull/4527) - Indexer performance update: refactor coin balance daily fetcher - [#4527](https://github.com/blockscout/blockscout/pull/4527) - Indexer performance update: refactor coin balance daily fetcher
- [#4525](https://github.com/blockscout/blockscout/pull/4525) - Uncataloged token transfers query performance improvement - [#4525](https://github.com/blockscout/blockscout/pull/4525) - Uncataloged token transfers query performance improvement
- [#4513](https://github.com/blockscout/blockscout/pull/4513) - Fix installation with custom default path: add NETWORK_PATH variable to the current_path - [#4513](https://github.com/blockscout/blockscout/pull/4513) - Fix installation with custom default path: add NETWORK_PATH variable to the current_path

@ -134,7 +134,7 @@ defmodule BlockScoutWeb.AddressContractVerificationController do
def get_metadata_and_publish(address_hash_string, nil) do def get_metadata_and_publish(address_hash_string, nil) do
case Sourcify.get_metadata(address_hash_string) do case Sourcify.get_metadata(address_hash_string) do
{:ok, verification_metadata} -> {:ok, verification_metadata} ->
proccess_metadata_add_publish(address_hash_string, verification_metadata, false) process_metadata_and_publish(address_hash_string, verification_metadata, false)
{:error, %{"error" => error}} -> {:error, %{"error" => error}} ->
{:error, error: error} {:error, error: error}
@ -144,7 +144,7 @@ defmodule BlockScoutWeb.AddressContractVerificationController do
def get_metadata_and_publish(address_hash_string, conn) do def get_metadata_and_publish(address_hash_string, conn) do
case Sourcify.get_metadata(address_hash_string) do case Sourcify.get_metadata(address_hash_string) do
{:ok, verification_metadata} -> {:ok, verification_metadata} ->
proccess_metadata_add_publish(address_hash_string, verification_metadata, false, conn) process_metadata_and_publish(address_hash_string, verification_metadata, false, conn)
{:error, %{"error" => error}} -> {:error, %{"error" => error}} ->
EventsPublisher.broadcast( EventsPublisher.broadcast(
@ -154,7 +154,7 @@ defmodule BlockScoutWeb.AddressContractVerificationController do
end end
end end
defp proccess_metadata_add_publish(address_hash_string, verification_metadata, is_partial, conn \\ nil) do defp process_metadata_and_publish(address_hash_string, verification_metadata, is_partial, conn \\ nil) do
%{"params_to_publish" => params_to_publish, "abi" => abi, "secondary_sources" => secondary_sources} = %{"params_to_publish" => params_to_publish, "abi" => abi, "secondary_sources" => secondary_sources} =
parse_params_from_sourcify(address_hash_string, verification_metadata) parse_params_from_sourcify(address_hash_string, verification_metadata)
@ -187,10 +187,9 @@ defmodule BlockScoutWeb.AddressContractVerificationController do
end end
def parse_params_from_sourcify(address_hash_string, verification_metadata) do def parse_params_from_sourcify(address_hash_string, verification_metadata) do
verification_metadata_json = [verification_metadata_json] =
verification_metadata verification_metadata
|> Enum.filter(fn %{"name" => name, "content" => _content} -> name =~ ".json" end) |> Enum.filter(&(Map.get(&1, "name") == "metadata.json"))
|> Enum.at(0)
full_params_initial = parse_json_from_sourcify_for_insertion(verification_metadata_json) full_params_initial = parse_json_from_sourcify_for_insertion(verification_metadata_json)
@ -198,34 +197,31 @@ defmodule BlockScoutWeb.AddressContractVerificationController do
verification_metadata verification_metadata
|> Enum.filter(fn %{"name" => name, "content" => _content} -> name =~ ".sol" end) |> Enum.filter(fn %{"name" => name, "content" => _content} -> name =~ ".sol" end)
full_params = verification_metadata_sol
verification_metadata_sol |> Enum.reduce(full_params_initial, fn %{"name" => name, "content" => content, "path" => _path} = param,
|> Enum.reduce(full_params_initial, fn %{"name" => name, "content" => content, "path" => _path} = param, full_params_acc ->
full_params_acc -> compilation_target_file_name = Map.get(full_params_acc, "compilation_target_file_name")
compilation_target_file_name = Map.get(full_params_acc, "compilation_target_file_name")
if String.downcase(name) == String.downcase(compilation_target_file_name) do
%{
"params_to_publish" => extract_primary_source_code(content, Map.get(full_params_acc, "params_to_publish")),
"abi" => Map.get(full_params_acc, "abi"),
"secondary_sources" => Map.get(full_params_acc, "secondary_sources"),
"compilation_target_file_name" => Map.get(full_params_acc, "compilation_target_file_name")
}
else
secondary_sources = [
prepare_additional_source(address_hash_string, param) | Map.get(full_params_acc, "secondary_sources")
]
%{
"params_to_publish" => Map.get(full_params_acc, "params_to_publish"),
"abi" => Map.get(full_params_acc, "abi"),
"secondary_sources" => secondary_sources,
"compilation_target_file_name" => Map.get(full_params_acc, "compilation_target_file_name")
}
end
end)
full_params if String.downcase(name) == String.downcase(compilation_target_file_name) do
%{
"params_to_publish" => extract_primary_source_code(content, Map.get(full_params_acc, "params_to_publish")),
"abi" => Map.get(full_params_acc, "abi"),
"secondary_sources" => Map.get(full_params_acc, "secondary_sources"),
"compilation_target_file_name" => Map.get(full_params_acc, "compilation_target_file_name")
}
else
secondary_sources = [
prepare_additional_source(address_hash_string, param) | Map.get(full_params_acc, "secondary_sources")
]
%{
"params_to_publish" => Map.get(full_params_acc, "params_to_publish"),
"abi" => Map.get(full_params_acc, "abi"),
"secondary_sources" => secondary_sources,
"compilation_target_file_name" => Map.get(full_params_acc, "compilation_target_file_name")
}
end
end)
end end
defp prepare_additional_source(address_hash_string, %{"name" => name, "content" => content, "path" => _path}) do defp prepare_additional_source(address_hash_string, %{"name" => name, "content" => content, "path" => _path}) do
@ -293,10 +289,10 @@ defmodule BlockScoutWeb.AddressContractVerificationController do
else else
case Sourcify.check_by_address_any(address_hash_string) do case Sourcify.check_by_address_any(address_hash_string) do
{:ok, "full", metadata} -> {:ok, "full", metadata} ->
proccess_metadata_add_publish(address_hash_string, metadata, false) process_metadata_and_publish(address_hash_string, metadata, false)
{:ok, "partial", metadata} -> {:ok, "partial", metadata} ->
proccess_metadata_add_publish(address_hash_string, metadata, true) process_metadata_and_publish(address_hash_string, metadata, true)
_ -> _ ->
{:error, :not_verified} {:error, :not_verified}

@ -8,7 +8,7 @@
class="border-bottom" class="border-bottom"
data-dropdown-token-balance-test data-dropdown-token-balance-test
data-token-name="<%= token_name(token_balance.token) %>" data-token-name="<%= token_name(token_balance.token) %>"
data-token-symbol="<%= token_balance.token.symbol %>" data-token-symbol="<%= token_symbol(token_balance.token) %>"
> >
<%= link( <%= link(
to: token_path(@conn, :show, to_string(token_balance.token.contract_address_hash)), to: token_path(@conn, :show, to_string(token_balance.token.contract_address_hash)),
@ -36,7 +36,7 @@
<div class="row"> <div class="row">
<% col_md = if token_balance.token.usd_value, do: "col-md-6", else: "col-md-12" %> <% col_md = if token_balance.token.usd_value, do: "col-md-6", else: "col-md-12" %>
<p class="mb-0 <%= col_md %> "> <p class="mb-0 <%= col_md %> ">
<%= format_according_to_decimals(token_balance.value, token_balance.token.decimals) %> <%= token_balance.token.symbol %> <%= format_according_to_decimals(token_balance.value, token_balance.token.decimals) %> <%= token_symbol(token_balance.token) %>
</p> </p>
<%= if token_balance.token.usd_value do %> <%= if token_balance.token.usd_value do %>
<p class="mb-0 col-md-6 text-right text-muted"> <p class="mb-0 col-md-6 text-right text-muted">
@ -47,4 +47,4 @@
<% end %> <% end %>
</div> </div>
<% end %> <% end %>
</div> </div>

@ -510,5 +510,4 @@ defmodule EthereumJSONRPC.Block do
defp entry_to_elixir({"l1BlockNumber", _}) do defp entry_to_elixir({"l1BlockNumber", _}) do
{:ignore, :ignore} {:ignore, :ignore}
end end
end end

@ -18,9 +18,24 @@ defmodule Indexer.Transform.TokenTransfers do
def parse(logs) do def parse(logs) do
initial_acc = %{tokens: [], token_transfers: []} initial_acc = %{tokens: [], token_transfers: []}
logs token_transfers_from_logs =
|> Enum.filter(&(&1.first_topic == unquote(TokenTransfer.constant()))) logs
|> Enum.reduce(initial_acc, &do_parse/2) |> Enum.filter(&(&1.first_topic == unquote(TokenTransfer.constant())))
|> Enum.reduce(initial_acc, &do_parse/2)
token_transfers = token_transfers_from_logs.token_transfers
token_transfers
|> Enum.filter(fn token_transfer ->
token_transfer.to_address_hash == @burn_address || token_transfer.from_address_hash == @burn_address
end)
|> Enum.map(fn token_transfer ->
token_transfer.token_contract_address_hash
end)
|> Enum.dedup()
|> Enum.each(&update_token/1)
token_transfers_from_logs
end end
defp do_parse(log, %{tokens: tokens, token_transfers: token_transfers} = acc) do defp do_parse(log, %{tokens: tokens, token_transfers: token_transfers} = acc) do
@ -58,8 +73,6 @@ defmodule Indexer.Transform.TokenTransfers do
type: "ERC-20" type: "ERC-20"
} }
update_token(log.address_hash, token_transfer)
{token, token_transfer} {token, token_transfer}
end end
@ -85,8 +98,6 @@ defmodule Indexer.Transform.TokenTransfers do
type: "ERC-721" type: "ERC-721"
} }
update_token(log.address_hash, token_transfer)
{token, token_transfer} {token, token_transfer}
end end
@ -112,28 +123,26 @@ defmodule Indexer.Transform.TokenTransfers do
type: "ERC-721" type: "ERC-721"
} }
update_token(log.address_hash, token_transfer)
{token, token_transfer} {token, token_transfer}
end end
defp update_token(address_hash_string, token_transfer) do defp update_token(nil), do: :ok
if token_transfer.to_address_hash == @burn_address || token_transfer.from_address_hash == @burn_address do
{:ok, address_hash} = Chain.string_to_address_hash(address_hash_string) defp update_token(address_hash_string) do
{:ok, address_hash} = Chain.string_to_address_hash(address_hash_string)
token_params = token_params =
address_hash_string address_hash_string
|> MetadataRetriever.get_functions_of() |> MetadataRetriever.get_functions_of()
token = Repo.get_by(Token, contract_address_hash: address_hash) token = Repo.get_by(Token, contract_address_hash: address_hash)
if token do if token do
token_to_update = token_to_update =
token token
|> Repo.preload([:contract_address]) |> Repo.preload([:contract_address])
{:ok, _} = Chain.update_token(%{token_to_update | updated_at: DateTime.utc_now()}, token_params) {:ok, _} = Chain.update_token(%{token_to_update | updated_at: DateTime.utc_now()}, token_params)
end
end end
:ok :ok

Loading…
Cancel
Save