|
|
|
@ -95,6 +95,7 @@ defmodule Explorer.Chain.SmartContract do |
|
|
|
|
|
|
|
|
|
use Explorer.Schema |
|
|
|
|
|
|
|
|
|
alias ABI.FunctionSelector |
|
|
|
|
alias Ecto.{Changeset, Multi} |
|
|
|
|
alias Explorer.{Chain, Repo, SortingHelper} |
|
|
|
|
|
|
|
|
@ -137,6 +138,31 @@ defmodule Explorer.Chain.SmartContract do |
|
|
|
|
~w()a |
|
|
|
|
end) |
|
|
|
|
|
|
|
|
|
@create_zksync_abi [ |
|
|
|
|
%{ |
|
|
|
|
"inputs" => [ |
|
|
|
|
%{"internalType" => "bytes32", "name" => "_salt", "type" => "bytes32"}, |
|
|
|
|
%{"internalType" => "bytes32", "name" => "_bytecodeHash", "type" => "bytes32"}, |
|
|
|
|
%{"internalType" => "bytes", "name" => "_input", "type" => "bytes"} |
|
|
|
|
], |
|
|
|
|
"name" => "create2", |
|
|
|
|
"outputs" => [%{"internalType" => "address", "name" => "", "type" => "address"}], |
|
|
|
|
"stateMutability" => "payable", |
|
|
|
|
"type" => "function" |
|
|
|
|
}, |
|
|
|
|
%{ |
|
|
|
|
"inputs" => [ |
|
|
|
|
%{"internalType" => "bytes32", "name" => "_salt", "type" => "bytes32"}, |
|
|
|
|
%{"internalType" => "bytes32", "name" => "_bytecodeHash", "type" => "bytes32"}, |
|
|
|
|
%{"internalType" => "bytes", "name" => "_input", "type" => "bytes"} |
|
|
|
|
], |
|
|
|
|
"name" => "create", |
|
|
|
|
"outputs" => [%{"internalType" => "address", "name" => "", "type" => "address"}], |
|
|
|
|
"stateMutability" => "payable", |
|
|
|
|
"type" => "function" |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
|
Returns burn address hash |
|
|
|
|
""" |
|
|
|
@ -1310,4 +1336,28 @@ defmodule Explorer.Chain.SmartContract do |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defp filter_contracts(basic_query, _), do: basic_query |
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
|
Retrieves the constructor arguments for a zkSync smart contract. |
|
|
|
|
Using @create_zksync_abi function decodes transaction input of contract creation |
|
|
|
|
|
|
|
|
|
## Parameters |
|
|
|
|
- `binary()`: The binary data representing the smart contract. |
|
|
|
|
|
|
|
|
|
## Returns |
|
|
|
|
- `nil`: If the constructor arguments cannot be retrieved. |
|
|
|
|
- `binary()`: The constructor arguments in binary format. |
|
|
|
|
""" |
|
|
|
|
@spec zksync_get_constructor_arguments(binary()) :: nil | binary() |
|
|
|
|
def zksync_get_constructor_arguments(address_hash_string) do |
|
|
|
|
creation_input = Chain.contract_creation_input_data_from_transaction(address_hash_string) |
|
|
|
|
|
|
|
|
|
case @create_zksync_abi |> ABI.parse_specification() |> ABI.find_and_decode(creation_input) do |
|
|
|
|
{%FunctionSelector{}, [_, _, constructor_args]} -> |
|
|
|
|
Base.encode16(constructor_args, case: :lower) |
|
|
|
|
|
|
|
|
|
_ -> |
|
|
|
|
nil |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|