4
0
Fork 0

Contract send encodes extra default options

travis-fix
hswick 6 years ago
parent d53482def9
commit a84b8bfbae
  1. 22
      lib/exw3.ex

@ -404,10 +404,25 @@ defmodule ExW3 do
) )
end 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() @spec encode_option(integer()) :: binary()
@doc "Encodes options into Ethereum JSON RPC hex string" @doc "Encodes options into Ethereum JSON RPC hex string"
def encode_option(0), do: "0x0" def encode_option(0), do: "0x0"
def encode_option(nil), do: nil
def encode_option(value) do def encode_option(value) do
"0x" <> "0x" <>
(value (value
@ -682,7 +697,10 @@ defmodule ExW3 do
end end
def eth_send_helper(address, abi, method_name, args, options) do 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([ ExW3.eth_send([
Map.merge( Map.merge(
@ -690,7 +708,7 @@ defmodule ExW3 do
to: address, to: address,
data: "0x#{ExW3.encode_method_call(abi, method_name, args)}" data: "0x#{ExW3.encode_method_call(abi, method_name, args)}"
}, },
Map.put(options, :gas, gas) Map.merge(options, encoded_options)
) )
]) ])
end end

Loading…
Cancel
Save