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

Add functions overloading support #5232

Merged
merged 1 commit into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .dialyzer-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ lib/phoenix/router.ex:402
lib/block_scout_web/views/layout_view.ex:145: The call 'Elixir.Poison.Parser':'parse!'
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:22
lib/explorer/smart_contract/reader.ex:436
lib/explorer/smart_contract/reader.ex:435
lib/indexer/fetcher/token_total_supply_on_demand.ex:16
lib/explorer/exchange_rates/source.ex:110
lib/explorer/exchange_rates/source.ex:113
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Current

### Features
- [#5232](https://github.com/blockscout/blockscout/pull/5232) - Contract Read Page: Add functions overloading support
- [#5220](https://github.com/blockscout/blockscout/pull/5220) - Add info about proxy contracts to api methods response
- [#5200](https://github.com/blockscout/blockscout/pull/5200) - Docker-compose configuration
- [#5105](https://github.com/blockscout/blockscout/pull/5105) - Redesign token page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,13 @@ defmodule BlockScoutWeb.SmartContractController do
address_hash,
%{method_id: params["method_id"], args: args},
contract_type,
params["function_name"],
params["from"]
)
else
Reader.query_function_with_names(
address_hash,
%{method_id: params["method_id"], args: args},
contract_type,
params["function_name"]
contract_type
)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,18 @@
end
%>
<%= render BlockScoutWeb.SmartContractView, "_pending_contract_write.html" %>
<form class="form-inline" data-function-form data-action="<%= if @action == "write", do: :write, else: :read %>" data-type="<%= @contract_type %>" data-url="<%= smart_contract_path(@conn, :show, Address.checksum(@address.hash)) %>" data-contract-address="<%= @address.hash %>" data-contract-abi="<%= @contract_abi %>" data-implementation-abi="<%= @implementation_abi %>" data-chain-id="<%= Explorer.Chain.Cache.NetVersion.get_version() %>">
<% function_abi =
case Jason.encode([function]) do
{:ok, abi_string} ->
abi_string
_ ->
if @contract_type == "proxy" do
@implementation_abi
else
@contract_abi
end
end %>
<form class="form-inline" data-function-form data-action="<%= if @action == "write", do: :write, else: :read %>" data-type="<%= @contract_type %>" data-url="<%= smart_contract_path(@conn, :show, Address.checksum(@address.hash)) %>" data-contract-address="<%= @address.hash %>" data-contract-abi="<%= function_abi %>" data-implementation-abi="<%= function_abi %>" data-chain-id="<%= Explorer.Chain.Cache.NetVersion.get_version() %>">
<input type="hidden" name="function_name" value='<%= function["name"] %>' />
<input type="hidden" name="method_id" value='<%= function["method_id"] %>' />

Expand Down
10 changes: 5 additions & 5 deletions apps/block_scout_web/priv/gettext/default.pot
Original file line number Diff line number Diff line change
Expand Up @@ -1028,8 +1028,8 @@ msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_token/overview.html.eex:1
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:93 lib/block_scout_web/templates/smart_contract/_functions.html.eex:93
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:135
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:104 lib/block_scout_web/templates/smart_contract/_functions.html.eex:104
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:146
msgid "ETH"
msgstr ""

Expand Down Expand Up @@ -1926,7 +1926,7 @@ msgid "QR Code"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:98
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:109
msgid "Query"
msgstr ""

Expand Down Expand Up @@ -3093,7 +3093,7 @@ msgid "Vyper contract"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:134
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:145
msgid "WEI"
msgstr ""

Expand Down Expand Up @@ -3148,7 +3148,7 @@ msgid "Working Stake Amount"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:98
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:109
msgid "Write"
msgstr ""

Expand Down
10 changes: 5 additions & 5 deletions apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -1028,8 +1028,8 @@ msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_token/overview.html.eex:1
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:93 lib/block_scout_web/templates/smart_contract/_functions.html.eex:93
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:135
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:104 lib/block_scout_web/templates/smart_contract/_functions.html.eex:104
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:146
msgid "ETH"
msgstr ""

Expand Down Expand Up @@ -1926,7 +1926,7 @@ msgid "QR Code"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:98
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:109
msgid "Query"
msgstr ""

Expand Down Expand Up @@ -3093,7 +3093,7 @@ msgid "Vyper contract"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:134
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:145
msgid "WEI"
msgstr ""

Expand Down Expand Up @@ -3148,7 +3148,7 @@ msgid "Working Stake Amount"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:98
#: lib/block_scout_web/templates/smart_contract/_functions.html.eex:109
msgid "Write"
msgstr ""

Expand Down
17 changes: 9 additions & 8 deletions apps/explorer/lib/explorer/smart_contract/reader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,13 @@ defmodule Explorer.SmartContract.Reader do
`type` could be :proxy or :reqular
if ethereumJSONRPC will return some errors it will represented as map
"""
@spec query_function_with_names(Hash.t(), %{method_id: String.t(), args: [term()] | nil}, atom(), String.t()) :: %{
@spec query_function_with_names(Hash.t(), %{method_id: String.t(), args: [term()] | nil}, atom()) :: %{
:names => [any()],
:output => [%{}]
}
def query_function_with_names(contract_address_hash, %{method_id: method_id, args: args}, type, function_name) do
def query_function_with_names(contract_address_hash, %{method_id: method_id, args: args}, type) do
outputs = query_function(contract_address_hash, %{method_id: method_id, args: args}, type, true)
names = parse_names_from_abi(get_abi(contract_address_hash, type), function_name)
names = parse_names_from_abi(get_abi(contract_address_hash, type), method_id)
%{output: outputs, names: names}
end

Expand All @@ -386,12 +386,11 @@ defmodule Explorer.SmartContract.Reader do
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
def query_function_with_names(contract_address_hash, %{method_id: method_id, args: args}, type, from) do
outputs = query_function(contract_address_hash, %{method_id: method_id, args: args}, type, from, true)
names = parse_names_from_abi(get_abi(contract_address_hash, type), function_name)
names = parse_names_from_abi(get_abi(contract_address_hash, type), method_id)
%{output: outputs, names: names}
end

Expand Down Expand Up @@ -462,8 +461,10 @@ defmodule Explorer.SmartContract.Reader do
end
end

defp parse_names_from_abi(abi, function_name) do
function = Enum.find(abi, fn el -> el["type"] == "function" and el["name"] == function_name end)
defp parse_names_from_abi(abi, method_id) do
function =
Enum.find(get_abi_with_method_id(abi), fn el -> el["type"] == "function" and el["method_id"] == method_id end)

outputs_to_list(function["outputs"])
end

Expand Down