4
0
Fork 0

Change deploy_helper

If it had not found a proper constructor it would fail either on encoding or a transaction would fail. Now it prints a warnings indicating what may be happening.
pull/11/head
Piotr Żelazko 6 years ago
parent c24b82f6ca
commit 57595fd877
No known key found for this signature in database
GPG Key ID: 27E11A19853A7913
  1. 10
      lib/exw3.ex

@ -476,7 +476,7 @@ defmodule ExW3 do
def deploy_helper(bin, abi, args) do
constructor_arg_data =
if args[:args] do
if arguments = args[:args] do
constructor_abi =
Enum.find(abi, fn {_, v} ->
v["type"] == "constructor"
@ -486,8 +486,14 @@ defmodule ExW3 do
{_, constructor} = constructor_abi
input_types = Enum.map(constructor["inputs"], fn x -> x["type"] end)
types_signature = Enum.join(["(", Enum.join(input_types, ","), ")"])
bin <> (ExW3.encode_data(types_signature, args[:args]) |> Base.encode16(case: :lower))
if Enum.count(input_types) != Enum.count(arguments) do
IO.warn("Number of provided arguments is invalid")
end
bin <> (ExW3.encode_data(types_signature, arguments) |> Base.encode16(case: :lower))
else
IO.warn("Could not find a constructor")
bin
end
else

Loading…
Cancel
Save