|
|
@ -542,6 +542,21 @@ defmodule ExW3 do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Options' checkers |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defp check_option(nil, error_atom), do: {:error, error_atom} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defp check_option([], error_atom), do: {:error, error_atom} |
|
|
|
|
|
|
|
defp check_option([head | tail], atom) do |
|
|
|
|
|
|
|
if head do |
|
|
|
|
|
|
|
{:ok, head} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
check_option(tail, atom) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defp check_option(value, _atom), do: {:ok, value} |
|
|
|
|
|
|
|
|
|
|
|
# Casts |
|
|
|
# Casts |
|
|
|
|
|
|
|
|
|
|
|
def handle_cast({:at, address}, state) do |
|
|
|
def handle_cast({:at, address}, state) do |
|
|
@ -563,16 +578,14 @@ defmodule ExW3 do |
|
|
|
# Calls |
|
|
|
# Calls |
|
|
|
|
|
|
|
|
|
|
|
def handle_call({:deploy, args}, _from, state) do |
|
|
|
def handle_call({:deploy, args}, _from, state) do |
|
|
|
case {args[:options][:from], args[:options][:gas]} do |
|
|
|
with {:ok, _} <- check_option(args[:options][:from], :missing_sender), |
|
|
|
{nil, _} -> {:reply, {:error, :missing_sender}, state} |
|
|
|
{:ok,_} <- check_option(args[:options][:gas], :missing_gas), |
|
|
|
{_, nil} -> {:reply, {:error, :missing_gas}, state} |
|
|
|
{:ok, bin} <- check_option([state[:bin], args[:bin]], :missing_binary) |
|
|
|
{_, _} -> |
|
|
|
do |
|
|
|
case {args[:bin], state[:bin]} do |
|
|
|
{:reply, {:ok, deploy_helper(bin, state[:abi], args)}, state} |
|
|
|
{nil, nil} -> {:reply, {:error, :missing_binary}, state} |
|
|
|
else |
|
|
|
{bin, nil} -> {:reply, {:ok, deploy_helper(bin, state[:abi], args)}, state} |
|
|
|
err -> {:reply, err, state} |
|
|
|
{nil, bin} -> {:reply, {:ok, deploy_helper(bin, state[:abi], args)}, state} |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def handle_call(:address, _from, state) do |
|
|
|
def handle_call(:address, _from, state) do |
|
|
@ -580,30 +593,22 @@ defmodule ExW3 do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def handle_call({:call, {method_name, args}}, _from, state) do |
|
|
|
def handle_call({:call, {method_name, args}}, _from, state) do |
|
|
|
address = state[:address] |
|
|
|
with {:ok, address} <- check_option(state[:address], :missing_address) |
|
|
|
|
|
|
|
do |
|
|
|
if address do |
|
|
|
{:reply, eth_call_helper(address, state[:abi], Atom.to_string(method_name), args), state} |
|
|
|
result = eth_call_helper(address, state[:abi], Atom.to_string(method_name), args) |
|
|
|
else |
|
|
|
{:reply, result, state} |
|
|
|
err -> {:reply, err, state} |
|
|
|
else |
|
|
|
|
|
|
|
{:reply, {:error, :missing_address}, state} |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def handle_call({:send, {method_name, args, options}}, _from, state) do |
|
|
|
def handle_call({:send, {method_name, args, options}}, _from, state) do |
|
|
|
case {state[:address], options[:from], options[:gas]} do |
|
|
|
with {:ok, address} <- check_option(state[:address], :missing_address), |
|
|
|
{nil, _, _} -> |
|
|
|
{:ok, _} <- check_option(options[:from], :missing_sender), |
|
|
|
{:reply, {:error, :missing_address}, state} |
|
|
|
{:ok, _} <- check_option(options[:gas], :missing_gas) |
|
|
|
{_, nil, _} -> |
|
|
|
do |
|
|
|
{:reply, {:error, :missing_sender}, state} |
|
|
|
{:reply, eth_send_helper(address, state[:abi], Atom.to_string(method_name), args, options), state} |
|
|
|
{_, _, nil} -> |
|
|
|
else |
|
|
|
{:reply, {:error, :missing_gas}, state} |
|
|
|
err -> {:reply, err, state} |
|
|
|
{address, _, _} -> |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
:reply, |
|
|
|
|
|
|
|
eth_send_helper(address, state[:abi], Atom.to_string(method_name), args, options), |
|
|
|
|
|
|
|
state |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|