From a84b8bfbae8433ed9e4550c4c944b91bc486ac85 Mon Sep 17 00:00:00 2001 From: hswick Date: Thu, 18 Oct 2018 13:17:10 -0500 Subject: [PATCH] Contract send encodes extra default options --- lib/exw3.ex | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/exw3.ex b/lib/exw3.ex index f4b7bcd..cbfea36 100644 --- a/lib/exw3.ex +++ b/lib/exw3.ex @@ -404,10 +404,25 @@ defmodule ExW3 do ) end + @spec encode_options(%{}, []) :: %{} + @doc "Encodes list of options and returns them as a map" + def encode_options(options, keys) do + keys + |> Enum.filter(fn option -> + Map.has_key?(options, option) + end) + |> Enum.map(fn option -> + {option, encode_option(options[option])} + end) + |> Enum.into(%{}) + end + @spec encode_option(integer()) :: binary() @doc "Encodes options into Ethereum JSON RPC hex string" def encode_option(0), do: "0x0" + def encode_option(nil), do: nil + def encode_option(value) do "0x" <> (value @@ -682,7 +697,10 @@ defmodule ExW3 do end def eth_send_helper(address, abi, method_name, args, options) do - gas = ExW3.encode_option(options[:gas]) + encoded_options = ExW3.encode_options( + options, + [:gas, :gasPrice, :value, :nonce] + ) ExW3.eth_send([ Map.merge( @@ -690,7 +708,7 @@ defmodule ExW3 do to: address, data: "0x#{ExW3.encode_method_call(abi, method_name, args)}" }, - Map.put(options, :gas, gas) + Map.merge(options, encoded_options) ) ]) end