Contract interaction: array input type

pull/3259/head
Victor Baranov 4 years ago
parent ea694bfffd
commit 782b2f4a2d
  1. 1
      CHANGELOG.md
  2. 35
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/contract.ex

@ -3,6 +3,7 @@
### Features ### Features
### Fixes ### Fixes
- [#3259](https://github.com/poanetwork/blockscout/pull/3259) - Contract interaction: array input type parsing fix
- [#3256](https://github.com/poanetwork/blockscout/pull/3256) - Fix for invisible validator address at block page and wrong alert text color at xDai - [#3256](https://github.com/poanetwork/blockscout/pull/3256) - Fix for invisible validator address at block page and wrong alert text color at xDai
### Chore ### Chore

@ -44,8 +44,10 @@ defmodule EthereumJSONRPC.Contract do
func.function == function_name && Enum.count(func.input_names) == Enum.count(args) func.function == function_name && Enum.count(func.input_names) == Enum.count(args)
end) end)
formatted_args = format_args(function, args)
function function
|> Encoder.encode_function_call(args) |> Encoder.encode_function_call(formatted_args)
|> eth_call_request(contract_address, index, Map.get(request, :block_number), Map.get(request, :from)) |> eth_call_request(contract_address, index, Map.get(request, :block_number), Map.get(request, :from))
end) end)
|> json_rpc(json_rpc_named_arguments) |> json_rpc(json_rpc_named_arguments)
@ -75,6 +77,37 @@ defmodule EthereumJSONRPC.Contract do
Enum.map(requests, fn _ -> format_error(error) end) Enum.map(requests, fn _ -> format_error(error) end)
end end
defp format_args(function, args) do
args
|> Enum.with_index()
|> Enum.map(fn {arg, index} ->
types = function.types
case Enum.at(types, index) do
{:array, {:int, _size}} ->
convert_string_to_array(arg)
{:array, {:uint, _size}} ->
convert_string_to_array(arg)
{:array, _} ->
String.split(arg, ",")
_ ->
arg
end
end)
end
defp convert_string_to_array(arg) do
arg
|> String.split(",")
|> Enum.map(fn el ->
{int, _} = Integer.parse(el)
int
end)
end
def eth_call_request(data, contract_address, id, block_number, from) do def eth_call_request(data, contract_address, id, block_number, from) do
block = block =
case block_number do case block_number do

Loading…
Cancel
Save