Merge pull request #5232 from blockscout/np-support-functions-overloading

Add functions overloading support
pull/5248/head
Victor Baranov 3 years ago committed by GitHub
commit 36ced6f6f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .dialyzer-ignore
  2. 1
      CHANGELOG.md
  3. 4
      apps/block_scout_web/lib/block_scout_web/controllers/smart_contract_controller.ex
  4. 13
      apps/block_scout_web/lib/block_scout_web/templates/smart_contract/_functions.html.eex
  5. 10
      apps/block_scout_web/priv/gettext/default.pot
  6. 10
      apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
  7. 17
      apps/explorer/lib/explorer/smart_contract/reader.ex

@ -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

@ -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

@ -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

@ -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"] %>' />

@ -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 ""
@ -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 ""
@ -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 ""
@ -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 ""

@ -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 ""
@ -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 ""
@ -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 ""
@ -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 ""

@ -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
@ -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
@ -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

Loading…
Cancel
Save