|
|
|
@ -292,14 +292,64 @@ defmodule Explorer.Chain.SmartContract.Proxy do |
|
|
|
|
proxy_type: atom() |
|
|
|
|
} |
|
|
|
|
def get_implementation_address_hash_string_eip1822(proxy_address_hash, proxy_abi, go_to_fallback?) do |
|
|
|
|
get_implementation_address_hash_string_by_module(EIP1822, :eip1822, [proxy_address_hash, proxy_abi, go_to_fallback?]) |
|
|
|
|
get_implementation_address_hash_string_by_module( |
|
|
|
|
EIP1822, |
|
|
|
|
:eip1822, |
|
|
|
|
[ |
|
|
|
|
proxy_address_hash, |
|
|
|
|
proxy_abi, |
|
|
|
|
go_to_fallback? |
|
|
|
|
], |
|
|
|
|
:get_implementation_address_hash_string_eip2535 |
|
|
|
|
) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
|
Returns EIP-2535 implementation address or tries next proxy pattern |
|
|
|
|
""" |
|
|
|
|
@spec get_implementation_address_hash_string_eip2535(Hash.Address.t(), any(), bool()) :: %{ |
|
|
|
|
implementation_address_hash_strings: [String.t() | :error | nil], |
|
|
|
|
proxy_type: atom() |
|
|
|
|
} |
|
|
|
|
def get_implementation_address_hash_string_eip2535(proxy_address_hash, proxy_abi, go_to_fallback?) do |
|
|
|
|
get_implementation_address_hash_string_by_module(EIP2535, :eip2535, [proxy_address_hash, proxy_abi, go_to_fallback?]) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defp get_implementation_address_hash_string_by_module( |
|
|
|
|
module, |
|
|
|
|
proxy_type, |
|
|
|
|
[proxy_address_hash, proxy_abi, go_to_fallback?] = args, |
|
|
|
|
args, |
|
|
|
|
next_func \\ :fallback_proxy_detection |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
defp get_implementation_address_hash_string_by_module( |
|
|
|
|
EIP2535 = module, |
|
|
|
|
:eip2535 = proxy_type, |
|
|
|
|
[proxy_address_hash, proxy_abi, go_to_fallback?] = args, |
|
|
|
|
next_func |
|
|
|
|
) do |
|
|
|
|
implementation_address_hash_strings = module.get_implementation_address_hash_strings(proxy_address_hash) |
|
|
|
|
|
|
|
|
|
if !is_nil(implementation_address_hash_strings) && implementation_address_hash_strings !== [] && |
|
|
|
|
implementation_address_hash_strings !== :error do |
|
|
|
|
%{implementation_address_hash_strings: implementation_address_hash_strings, proxy_type: proxy_type} |
|
|
|
|
else |
|
|
|
|
do_get_implementation_address_hash_string_by_module( |
|
|
|
|
implementation_address_hash_strings, |
|
|
|
|
proxy_address_hash, |
|
|
|
|
proxy_abi, |
|
|
|
|
go_to_fallback?, |
|
|
|
|
next_func, |
|
|
|
|
args |
|
|
|
|
) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defp get_implementation_address_hash_string_by_module( |
|
|
|
|
module, |
|
|
|
|
proxy_type, |
|
|
|
|
[proxy_address_hash, proxy_abi, go_to_fallback?] = args, |
|
|
|
|
next_func |
|
|
|
|
) do |
|
|
|
|
implementation_address_hash_string = module.get_implementation_address_hash_string(proxy_address_hash) |
|
|
|
|
|
|
|
|
@ -307,23 +357,41 @@ defmodule Explorer.Chain.SmartContract.Proxy do |
|
|
|
|
implementation_address_hash_string !== :error do |
|
|
|
|
%{implementation_address_hash_strings: [implementation_address_hash_string], proxy_type: proxy_type} |
|
|
|
|
else |
|
|
|
|
cond do |
|
|
|
|
next_func !== :fallback_proxy_detection -> |
|
|
|
|
apply(__MODULE__, next_func, args) |
|
|
|
|
do_get_implementation_address_hash_string_by_module( |
|
|
|
|
implementation_address_hash_string, |
|
|
|
|
proxy_address_hash, |
|
|
|
|
proxy_abi, |
|
|
|
|
go_to_fallback?, |
|
|
|
|
next_func, |
|
|
|
|
args |
|
|
|
|
) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
go_to_fallback? && next_func == :fallback_proxy_detection -> |
|
|
|
|
fallback_value = implementation_fallback_value(implementation_address_hash_string) |
|
|
|
|
defp do_get_implementation_address_hash_string_by_module( |
|
|
|
|
implementation_value, |
|
|
|
|
proxy_address_hash, |
|
|
|
|
proxy_abi, |
|
|
|
|
go_to_fallback?, |
|
|
|
|
next_func, |
|
|
|
|
args |
|
|
|
|
) do |
|
|
|
|
cond do |
|
|
|
|
next_func !== :fallback_proxy_detection -> |
|
|
|
|
apply(__MODULE__, next_func, args) |
|
|
|
|
|
|
|
|
|
apply(__MODULE__, :fallback_proxy_detection, [proxy_address_hash, proxy_abi, fallback_value]) |
|
|
|
|
go_to_fallback? && next_func == :fallback_proxy_detection -> |
|
|
|
|
fallback_value = implementation_fallback_value(implementation_value) |
|
|
|
|
|
|
|
|
|
true -> |
|
|
|
|
implementation_fallback_value(implementation_address_hash_string) |
|
|
|
|
end |
|
|
|
|
apply(__MODULE__, :fallback_proxy_detection, [proxy_address_hash, proxy_abi, fallback_value]) |
|
|
|
|
|
|
|
|
|
true -> |
|
|
|
|
implementation_fallback_value(implementation_value) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defp implementation_fallback_value(implementation_address_hash_string) do |
|
|
|
|
value = if implementation_address_hash_string == :error, do: :error, else: [] |
|
|
|
|
defp implementation_fallback_value(implementation_value) do |
|
|
|
|
value = if implementation_value == :error, do: :error, else: [] |
|
|
|
|
|
|
|
|
|
%{implementation_address_hash_strings: value, proxy_type: :unknown} |
|
|
|
|
end |
|
|
|
|