|
|
@ -95,24 +95,24 @@ defmodule BlockScoutWeb.API.V2.AddressView do |
|
|
|
|
|
|
|
|
|
|
|
is_proxy = AddressView.smart_contract_is_proxy?(address_with_smart_contract, @api_true) |
|
|
|
is_proxy = AddressView.smart_contract_is_proxy?(address_with_smart_contract, @api_true) |
|
|
|
|
|
|
|
|
|
|
|
{implementation_addresses, implementation_names} = |
|
|
|
implementations = |
|
|
|
with true <- is_proxy, |
|
|
|
with true <- is_proxy, |
|
|
|
{addresses, names} <- |
|
|
|
{addresses, names} <- |
|
|
|
Implementation.get_implementation(address_with_smart_contract.smart_contract, @api_true), |
|
|
|
Implementation.get_implementation(address_with_smart_contract.smart_contract, @api_true), |
|
|
|
false <- addresses && Enum.empty?(addresses) do |
|
|
|
false <- addresses && Enum.empty?(addresses) do |
|
|
|
addresses |
|
|
|
addresses |
|
|
|
|> Enum.zip(names) |
|
|
|
|> Enum.zip(names) |
|
|
|
|> Enum.reduce({[], []}, fn {address, name}, {addresses, names} = acc -> |
|
|
|
|> Enum.reduce([], fn {address, name}, acc -> |
|
|
|
with {:ok, address_hash} <- Chain.string_to_address_hash(address), |
|
|
|
with {:ok, address_hash} <- Chain.string_to_address_hash(address), |
|
|
|
checksummed_address <- Address.checksum(address_hash) do |
|
|
|
checksummed_address <- Address.checksum(address_hash) do |
|
|
|
{[checksummed_address | addresses], [name | names]} |
|
|
|
[%{"address" => checksummed_address, "name" => name} | acc] |
|
|
|
else |
|
|
|
else |
|
|
|
_ -> acc |
|
|
|
_ -> acc |
|
|
|
end |
|
|
|
end |
|
|
|
end) |
|
|
|
end) |
|
|
|
else |
|
|
|
else |
|
|
|
_ -> |
|
|
|
_ -> |
|
|
|
{[], []} |
|
|
|
[] |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
balance = address.fetched_coin_balance && address.fetched_coin_balance.value |
|
|
|
balance = address.fetched_coin_balance && address.fetched_coin_balance.value |
|
|
@ -123,8 +123,7 @@ defmodule BlockScoutWeb.API.V2.AddressView do |
|
|
|
token = address.token && TokenView.render("token.json", %{token: address.token}) |
|
|
|
token = address.token && TokenView.render("token.json", %{token: address.token}) |
|
|
|
|
|
|
|
|
|
|
|
# todo: added for backward compatibility, remove when frontend unbound from these props |
|
|
|
# todo: added for backward compatibility, remove when frontend unbound from these props |
|
|
|
{implementation_address, implementation_name} = |
|
|
|
{implementation_address, implementation_name} = single_implementation(implementations) |
|
|
|
single_implementation(implementation_addresses, implementation_names) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map.merge(base_info, %{ |
|
|
|
Map.merge(base_info, %{ |
|
|
|
"creator_address_hash" => creator_hash && Address.checksum(creator_hash), |
|
|
|
"creator_address_hash" => creator_hash && Address.checksum(creator_hash), |
|
|
@ -133,10 +132,9 @@ defmodule BlockScoutWeb.API.V2.AddressView do |
|
|
|
"coin_balance" => balance, |
|
|
|
"coin_balance" => balance, |
|
|
|
"exchange_rate" => exchange_rate, |
|
|
|
"exchange_rate" => exchange_rate, |
|
|
|
# todo: added for backward compatibility, remove when frontend unbound from these props |
|
|
|
# todo: added for backward compatibility, remove when frontend unbound from these props |
|
|
|
"implementation_name" => implementation_name, |
|
|
|
|
|
|
|
"implementation_names" => implementation_names, |
|
|
|
|
|
|
|
"implementation_address" => implementation_address, |
|
|
|
"implementation_address" => implementation_address, |
|
|
|
"implementation_addresses" => implementation_addresses, |
|
|
|
"implementation_name" => implementation_name, |
|
|
|
|
|
|
|
"implementations" => implementations, |
|
|
|
"block_number_balance_updated_at" => address.fetched_coin_balance_block_number, |
|
|
|
"block_number_balance_updated_at" => address.fetched_coin_balance_block_number, |
|
|
|
"has_decompiled_code" => AddressView.has_decompiled_code?(address), |
|
|
|
"has_decompiled_code" => AddressView.has_decompiled_code?(address), |
|
|
|
"has_validated_blocks" => Counters.check_if_validated_blocks_at_address(address.hash, @api_true), |
|
|
|
"has_validated_blocks" => Counters.check_if_validated_blocks_at_address(address.hash, @api_true), |
|
|
@ -148,19 +146,12 @@ defmodule BlockScoutWeb.API.V2.AddressView do |
|
|
|
}) |
|
|
|
}) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp single_implementation(implementation_addresses, implementation_names) do |
|
|
|
defp single_implementation(implementations) do |
|
|
|
implementation_name = |
|
|
|
%{"address" => implementation_address, "name" => implementation_name} = |
|
|
|
if implementation_names && !Enum.empty?(implementation_names) do |
|
|
|
if implementations && !Enum.empty?(implementations) do |
|
|
|
implementation_names |> Enum.at(0) |
|
|
|
implementations |> Enum.at(0) |
|
|
|
else |
|
|
|
else |
|
|
|
nil |
|
|
|
%{"address" => nil, "name" => nil} |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
implementation_address = |
|
|
|
|
|
|
|
if implementation_addresses && !Enum.empty?(implementation_addresses) do |
|
|
|
|
|
|
|
implementation_addresses |> Enum.at(0) |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
nil |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
{implementation_address, implementation_name} |
|
|
|
{implementation_address, implementation_name} |
|
|
|