diff --git a/.dialyzer-ignore b/.dialyzer-ignore index c8f456f2b9..85c9cd35cd 100644 --- a/.dialyzer-ignore +++ b/.dialyzer-ignore @@ -18,7 +18,7 @@ lib/block_scout_web/views/layout_view.ex:145: The call 'Elixir.Poison.Parser':'p lib/block_scout_web/views/layout_view.ex:237: The call 'Elixir.Poison.Parser':'parse!' lib/block_scout_web/controllers/api/rpc/transaction_controller.ex:21 lib/block_scout_web/controllers/api/rpc/transaction_controller.ex:22 -lib/explorer/smart_contract/reader.ex:413 +lib/explorer/smart_contract/reader.ex:440 lib/indexer/fetcher/token_total_supply_on_demand.ex:16 lib/explorer/exchange_rates/source.ex:110 lib/explorer/exchange_rates/source.ex:113 diff --git a/apps/explorer/lib/explorer/smart_contract/helper.ex b/apps/explorer/lib/explorer/smart_contract/helper.ex index 5505e60cc4..59e7013bfd 100644 --- a/apps/explorer/lib/explorer/smart_contract/helper.ex +++ b/apps/explorer/lib/explorer/smart_contract/helper.ex @@ -13,10 +13,14 @@ defmodule Explorer.SmartContract.Helper do def error?(function), do: function["type"] == "error" + @doc """ + Checks whether the function which is not queriable can be consider as read function or not. + """ + @spec read_with_wallet_method?(%{}) :: true | false def read_with_wallet_method?(function), do: !error?(function) && !event?(function) && !constructor?(function) && nonpayable?(function) && - empty_inputs?(function) && !empty_outputs?(function) + !empty_outputs?(function) def empty_inputs?(function), do: function["inputs"] == [] diff --git a/apps/explorer/lib/explorer/smart_contract/reader.ex b/apps/explorer/lib/explorer/smart_contract/reader.ex index 7d376062ad..dce7165d28 100644 --- a/apps/explorer/lib/explorer/smart_contract/reader.ex +++ b/apps/explorer/lib/explorer/smart_contract/reader.ex @@ -236,6 +236,10 @@ defmodule Explorer.SmartContract.Reader do end end + @doc """ + Returns abi for not queriable functions of proxy's implementation which can be considered as read-only + """ + @spec read_functions_required_wallet_proxy(String.t()) :: [%{}] def read_functions_required_wallet_proxy(implementation_address_hash_string) do implementation_abi = Chain.get_implementation_abi(implementation_address_hash_string) @@ -251,6 +255,9 @@ defmodule Explorer.SmartContract.Reader do end end + @doc """ + Returns abi for not queriable functions of the smart contract which can be considered as read-only + """ @spec read_functions_required_wallet(Hash.t()) :: [%{}] def read_functions_required_wallet(contract_address_hash) do abi = @@ -362,12 +369,32 @@ defmodule Explorer.SmartContract.Reader do Map.replace!(function, "outputs", values) end + @doc """ + Method performs query of read functions of a smart contract. + `type` could be :proxy or :reqular + """ + @spec query_function_with_names(Hash.t(), %{method_id: String.t(), args: [term()] | nil}, atom(), String.t()) :: %{ + :names => [any()], + :output => [%{}] + } def query_function_with_names(contract_address_hash, %{method_id: method_id, args: args}, type, function_name) do outputs = query_function(contract_address_hash, %{method_id: method_id, args: args}, type) names = parse_names_from_abi(get_abi(contract_address_hash, type), function_name) %{output: outputs, names: names} end + @doc """ + Method performs query of read functions of a smart contract. + `type` could be :proxy or :reqular + `from` is a address of a function caller + """ + @spec query_function_with_names( + Hash.t(), + %{method_id: String.t(), args: [term()] | nil}, + atom(), + String.t(), + String.t() + ) :: %{:names => [any()], :output => [%{}]} def query_function_with_names(contract_address_hash, %{method_id: method_id, args: args}, type, function_name, from) do outputs = query_function(contract_address_hash, %{method_id: method_id, args: args}, type, from) names = parse_names_from_abi(get_abi(contract_address_hash, type), function_name)