|
|
@ -266,6 +266,15 @@ defmodule ExW3 do |
|
|
|
) |
|
|
|
) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@spec encode_option(integer()) :: binary() |
|
|
|
|
|
|
|
@doc "Encodes options into Ethereum JSON RPC hex string" |
|
|
|
|
|
|
|
def encode_option(0), do: "0x0" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def encode_option(value) do |
|
|
|
|
|
|
|
"0x" <> (value |> :binary.encode_unsigned() |> Base.encode16(case: :lower) |> String.trim_leading("0")) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@spec encode_method_call(%{}, binary(), []) :: binary() |
|
|
|
@spec encode_method_call(%{}, binary(), []) :: binary() |
|
|
|
@doc "Encodes data and appends it to the encoded method id" |
|
|
|
@doc "Encodes data and appends it to the encoded method id" |
|
|
|
def encode_method_call(abi, name, input) do |
|
|
|
def encode_method_call(abi, name, input) do |
|
|
@ -505,12 +514,12 @@ defmodule ExW3 do |
|
|
|
bin |
|
|
|
bin |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
gas = ExW3.encode_data("(uint)", [args[:options][:gas]]) |> Base.encode16(case: :lower) |
|
|
|
gas = ExW3.encode_option(args[:options][:gas]) |
|
|
|
|
|
|
|
|
|
|
|
tx = %{ |
|
|
|
tx = %{ |
|
|
|
from: args[:options][:from], |
|
|
|
from: args[:options][:from], |
|
|
|
data: "0x#{constructor_arg_data}", |
|
|
|
data: "0x#{constructor_arg_data}", |
|
|
|
gas: "0x#{gas}" |
|
|
|
gas: gas |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
{:ok, tx_hash} = Ethereumex.HttpClient.eth_send_transaction(tx) |
|
|
|
{:ok, tx_hash} = Ethereumex.HttpClient.eth_send_transaction(tx) |
|
|
@ -534,14 +543,14 @@ 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_data("(uint)", [options[:gas]]) |> Base.encode16(case: :lower) |
|
|
|
gas = ExW3.encode_option(options[:gas]) |
|
|
|
Ethereumex.HttpClient.eth_send_transaction( |
|
|
|
Ethereumex.HttpClient.eth_send_transaction( |
|
|
|
Map.merge( |
|
|
|
Map.merge( |
|
|
|
%{ |
|
|
|
%{ |
|
|
|
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, "0x#{gas}") |
|
|
|
Map.put(options, :gas, gas) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
end |
|
|
|
end |
|
|
|