4
0
Fork 0

Add error messages in case user does not provide either gas or transaction sender

pull/11/head
Piotr Żelazko 6 years ago
parent 57595fd877
commit fcb8717837
No known key found for this signature in database
GPG Key ID: 27E11A19853A7913
  1. 24
      lib/exw3.ex

@ -541,6 +541,7 @@ defmodule ExW3 do
) )
end end
# Casts # Casts
def handle_cast({:at, address}, state) do def handle_cast({:at, address}, state) do
@ -562,12 +563,17 @@ 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
{nil, _} -> {:reply, {:error, "transaction sender not provided"}, state}
{_, nil} -> {:reply, {:error, "gas amount not provided"}, state}
{_, _} ->
case {args[:bin], state[:bin]} do case {args[:bin], state[:bin]} do
{nil, nil} -> {:reply, {:error, "contract binary was never provided"}, state} {nil, nil} -> {:reply, {:error, "contract binary was never provided"}, state}
{bin, nil} -> {:reply, {:ok, deploy_helper(bin, state[:abi], args)}, state} {bin, nil} -> {:reply, {:ok, deploy_helper(bin, state[:abi], args)}, state}
{nil, bin} -> {:reply, {:ok, deploy_helper(bin, state[:abi], args)}, 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
{:reply, state[:address], state} {:reply, state[:address], state}
@ -585,13 +591,19 @@ defmodule ExW3 do
end end
def handle_call({:send, {method_name, args, options}}, _from, state) do def handle_call({:send, {method_name, args, options}}, _from, state) do
address = state[:address] case {state[:address], options[:from], options[:gas]} do
{nil, _, _} ->
if address do
result = eth_send_helper(address, state[:abi], Atom.to_string(method_name), args, options)
{:reply, result, state}
else
{:reply, {:error, "contract address not available"}, state} {:reply, {:error, "contract address not available"}, state}
{_, nil, _} ->
{:reply, {:error, "transaction sender not provided"}, state}
{_, _, nil} ->
{:reply, {:error, "gas amount not provided"}, state}
{address, _, _} ->
{
:reply,
eth_send_helper(address, state[:abi], Atom.to_string(method_name), args, options),
state
}
end end
end end

Loading…
Cancel
Save