Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(app), ignore byte code change for configured addresses #9

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion apps/explorer/lib/explorer/chain.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ defmodule Explorer.Chain do
Withdrawal
}

alias Explorer.Chain.Hash.Address, as: AddressHash

alias Explorer.Chain.Block.{EmissionReward, Reward}

alias Explorer.Chain.Cache.{
Expand Down Expand Up @@ -1913,7 +1915,7 @@ defmodule Explorer.Chain do
if smart_contract do
CheckBytecodeMatchingOnDemand.trigger_check(address_result, smart_contract)
LookUpSmartContractSourcesOnDemand.trigger_fetch(address_result, smart_contract)
address_result
ignore_bytecode_change_if_amazon(address_result)
else
LookUpSmartContractSourcesOnDemand.trigger_fetch(address_result, nil)

Expand All @@ -1936,6 +1938,59 @@ defmodule Explorer.Chain do
end
end


def ignore_bytecode_change_if_amazon(%{hash: hash, smart_contract: smart_contract} = contract) do

# read the list of addresses from the environment variable "KCC_AMAZON_ADDRESS"
# The format of the list is "address0,address1,address2..." (without quotes)
# We ignore the change of bytecodes for these addresses.

# Example:
#
# suppose we have the env: KCC_AMAZON_ADDRESS="0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed"
#
# c = %{
# hash: %Explorer.Chain.Hash{
# byte_count: 20,
# bytes: <<90, 174, 182, 5, 63, 62, 148, 201, 185, 160, 159, 51, 102, 148, 53,
# 231, 239, 27, 234, 237>>
# },
# smart_contract: %{is_changed_bytecode: true}
# }
#
# Explorer.Chain.ignore_bytecode_change_if_amazon(c) returns:
#
# %{
# hash: %Explorer.Chain.Hash{
# byte_count: 20,
# bytes: <<90, 174, 182, 5, 63, 62, 148, 201, 185, 160, 159, 51, 102, 148, 53,
# 231, 239, 27, 234, 237>>
# },
# smart_contract: %{is_changed_bytecode: false}
# }
#


amazon_addresses = if System.get_env("KCC_AMAZON_ADDRESS") == nil do
[]
else
String.split(System.get_env("KCC_AMAZON_ADDRESS"),",")
|> Enum.map(fn x -> elem(AddressHash.cast(x),1) end )
end

# is hash in amazon_addresses?
if Enum.member?(amazon_addresses, hash) do
Logger.info("Ignoring bytecode change for contract #{hash}")
contract
|> Map.put(:smart_contract, Map.put(smart_contract, :is_changed_bytecode, false))
else
contract
end



end

defp add_twin_info_to_contract(address_result, address_verified_twin_contract, _hash)
when is_nil(address_verified_twin_contract),
do: address_result
Expand Down