Skip to content

Commit

Permalink
Checksum some addresses in smart contract body
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitosing committed Jan 16, 2023
1 parent 5dbb974 commit 861517c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ defmodule BlockScoutWeb.API.V2.SmartContractView do
target_contract = if smart_contract_verified, do: address.smart_contract, else: metadata_for_verification

%{
"verified_twin_address_hash" => metadata_for_verification && metadata_for_verification.address_hash,
"verified_twin_address_hash" =>
metadata_for_verification && Address.checksum(metadata_for_verification.address_hash),
"is_verified" => smart_contract_verified,
"is_changed_bytecode" => smart_contract_verified && address.smart_contract.is_changed_bytecode,
"is_partially_verified" => address.smart_contract.partially_verified && smart_contract_verified,
Expand Down Expand Up @@ -189,7 +190,9 @@ defmodule BlockScoutWeb.API.V2.SmartContractView do

defp prepare_external_libraries(libraries) when is_list(libraries) do
Enum.map(libraries, fn %Explorer.Chain.SmartContract.ExternalLibrary{name: name, address_hash: address_hash} ->
%{name: name, address_hash: address_hash}
{:ok, hash} = Chain.string_to_address_hash(address_hash)

%{name: name, address_hash: Address.checksum(hash)}
end)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ defmodule BlockScoutWeb.API.V2.SmartContractControllerTest do
end

test "get smart-contract", %{conn: conn} do
lib_address_string = to_string(build(:address))
lib_address = build(:address)
lib_address_string = to_string(lib_address)

target_contract =
insert(:smart_contract,
Expand Down Expand Up @@ -95,7 +96,7 @@ defmodule BlockScoutWeb.API.V2.SmartContractControllerTest do
"file_path" => target_contract.file_path,
"additional_sources" => [],
"compiler_settings" => target_contract.compiler_settings,
"external_libraries" => [%{"name" => "ABC", "address_hash" => lib_address_string}],
"external_libraries" => [%{"name" => "ABC", "address_hash" => Address.checksum(lib_address)}],
"constructor_args" => target_contract.constructor_arguments,
"decoded_constructor_args" => nil,
"is_self_destructed" => false,
Expand All @@ -114,7 +115,8 @@ defmodule BlockScoutWeb.API.V2.SmartContractControllerTest do
end

test "get smart-contract with decoded constructor", %{conn: conn} do
lib_address_string = to_string(build(:address))
lib_address = build(:address)
lib_address_string = to_string(lib_address)

target_contract =
insert(:smart_contract,
Expand Down Expand Up @@ -181,7 +183,7 @@ defmodule BlockScoutWeb.API.V2.SmartContractControllerTest do
"file_path" => target_contract.file_path,
"additional_sources" => [],
"compiler_settings" => target_contract.compiler_settings,
"external_libraries" => [%{"name" => "ABC", "address_hash" => lib_address_string}],
"external_libraries" => [%{"name" => "ABC", "address_hash" => Address.checksum(lib_address)}],
"constructor_args" => target_contract.constructor_arguments,
"decoded_constructor_args" => [
["0x0000000000000000000000000000000000000000", %{"name" => "_proxyStorage", "type" => "address"}],
Expand All @@ -203,7 +205,8 @@ defmodule BlockScoutWeb.API.V2.SmartContractControllerTest do
end

test "get smart-contract data from twin without constructor args", %{conn: conn} do
lib_address_string = to_string(build(:address))
lib_address = build(:address)
lib_address_string = to_string(lib_address)

target_contract =
insert(:smart_contract,
Expand Down Expand Up @@ -276,7 +279,7 @@ defmodule BlockScoutWeb.API.V2.SmartContractControllerTest do
"file_path" => target_contract.file_path,
"additional_sources" => [],
"compiler_settings" => target_contract.compiler_settings,
"external_libraries" => [%{"name" => "ABC", "address_hash" => lib_address_string}],
"external_libraries" => [%{"name" => "ABC", "address_hash" => Address.checksum(lib_address)}],
"constructor_args" => nil,
"decoded_constructor_args" => nil,
"is_self_destructed" => false,
Expand Down

0 comments on commit 861517c

Please sign in to comment.