Refactoring: Handle empty array type input

pull/3269/head
Victor Baranov 4 years ago
parent 9437a198d2
commit ee142f597c
  1. 37
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/contract.ex

@ -82,28 +82,33 @@ defmodule EthereumJSONRPC.Contract do
|> Enum.with_index()
|> Enum.map(fn {arg, index} ->
types = function.types
type = Enum.at(types, index)
case Enum.at(types, index) do
{:array, {:int, _size}} ->
convert_string_to_array(arg)
convert_string_to_array(type, arg)
end)
end
{:array, {:uint, _size}} ->
convert_string_to_array(arg)
defp convert_string_to_array(type, arg) do
case type do
{:array, {:int, _size}} ->
convert_int_string_to_array(arg)
{:array, _} ->
if arg && arg !== "" do
String.split(arg, ",")
else
[]
end
{:array, {:uint, _size}} ->
convert_int_string_to_array(arg)
_ ->
arg
end
end)
{:array, _} ->
if arg && arg !== "" do
String.split(arg, ",")
else
[]
end
_ ->
arg
end
end
defp convert_string_to_array(arg) do
defp convert_int_string_to_array(arg) do
if arg && arg !== "" do
arg
|> String.split(",")

Loading…
Cancel
Save