|
|
|
@ -95,24 +95,24 @@ defmodule BlockScoutWeb.API.V2.AddressView do |
|
|
|
|
|
|
|
|
|
is_proxy = AddressView.smart_contract_is_proxy?(address_with_smart_contract, @api_true) |
|
|
|
|
|
|
|
|
|
{implementation_addresses, implementation_names} = |
|
|
|
|
implementations = |
|
|
|
|
with true <- is_proxy, |
|
|
|
|
{addresses, names} <- |
|
|
|
|
Implementation.get_implementation(address_with_smart_contract.smart_contract, @api_true), |
|
|
|
|
false <- addresses && Enum.empty?(addresses) do |
|
|
|
|
addresses |
|
|
|
|
|> 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), |
|
|
|
|
checksummed_address <- Address.checksum(address_hash) do |
|
|
|
|
{[checksummed_address | addresses], [name | names]} |
|
|
|
|
[%{"address" => checksummed_address, "name" => name} | acc] |
|
|
|
|
else |
|
|
|
|
_ -> acc |
|
|
|
|
end |
|
|
|
|
end) |
|
|
|
|
else |
|
|
|
|
_ -> |
|
|
|
|
{[], []} |
|
|
|
|
[] |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
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}) |
|
|
|
|
|
|
|
|
|
# todo: added for backward compatibility, remove when frontend unbound from these props |
|
|
|
|
{implementation_address, implementation_name} = |
|
|
|
|
single_implementation(implementation_addresses, implementation_names) |
|
|
|
|
{implementation_address, implementation_name} = single_implementation(implementations) |
|
|
|
|
|
|
|
|
|
Map.merge(base_info, %{ |
|
|
|
|
"creator_address_hash" => creator_hash && Address.checksum(creator_hash), |
|
|
|
@ -133,10 +132,9 @@ defmodule BlockScoutWeb.API.V2.AddressView do |
|
|
|
|
"coin_balance" => balance, |
|
|
|
|
"exchange_rate" => exchange_rate, |
|
|
|
|
# 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_addresses" => implementation_addresses, |
|
|
|
|
"implementation_name" => implementation_name, |
|
|
|
|
"implementations" => implementations, |
|
|
|
|
"block_number_balance_updated_at" => address.fetched_coin_balance_block_number, |
|
|
|
|
"has_decompiled_code" => AddressView.has_decompiled_code?(address), |
|
|
|
|
"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 |
|
|
|
|
|
|
|
|
|
defp single_implementation(implementation_addresses, implementation_names) do |
|
|
|
|
implementation_name = |
|
|
|
|
if implementation_names && !Enum.empty?(implementation_names) do |
|
|
|
|
implementation_names |> Enum.at(0) |
|
|
|
|
defp single_implementation(implementations) do |
|
|
|
|
%{"address" => implementation_address, "name" => implementation_name} = |
|
|
|
|
if implementations && !Enum.empty?(implementations) do |
|
|
|
|
implementations |> Enum.at(0) |
|
|
|
|
else |
|
|
|
|
nil |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
implementation_address = |
|
|
|
|
if implementation_addresses && !Enum.empty?(implementation_addresses) do |
|
|
|
|
implementation_addresses |> Enum.at(0) |
|
|
|
|
else |
|
|
|
|
nil |
|
|
|
|
%{"address" => nil, "name" => nil} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
{implementation_address, implementation_name} |
|
|
|
|