4
0
Fork 0

Add tx_hash to returning tuple at contract's deployment

pull/12/head^2
Piotr Żelazko 7 years ago
parent 25e33df5ee
commit f2555c5fb9
No known key found for this signature in database
GPG Key ID: 27E11A19853A7913
  1. 28
      lib/exw3.ex
  2. 12
      test/exw3_test.exs

@ -493,11 +493,11 @@ defmodule ExW3 do
gas: "0x#{gas}"
}
{:ok, tx_receipt_id} = Ethereumex.HttpClient.eth_send_transaction(tx)
{:ok, tx_hash} = Ethereumex.HttpClient.eth_send_transaction(tx)
{:ok, tx_receipt} = Ethereumex.HttpClient.eth_get_transaction_receipt(tx_receipt_id)
{:ok, tx_receipt} = Ethereumex.HttpClient.eth_get_transaction_receipt(tx_hash)
tx_receipt["contractAddress"]
{tx_receipt["contractAddress"], tx_hash}
end
def eth_call_helper(address, abi, method_name, args) do
@ -526,6 +526,15 @@ defmodule ExW3 do
)
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) when head != nil, do: {:ok, head}
defp check_option([_head | tail], atom), do: check_option(tail, atom)
defp check_option(value, _atom), do: {:ok, value}
# Casts
def handle_cast({:at, address}, state) do
@ -547,11 +556,14 @@ defmodule ExW3 do
# Calls
def handle_call({:deploy, args}, _from, state) do
case {args[:bin], state[:bin]} do
{nil, nil} -> {:reply, {:error, "contract binary was never provided"}, state}
{bin, nil} -> {:reply, {:ok, deploy_helper(bin, state[:abi], args)}, state}
{nil, bin} -> {:reply, {:ok, deploy_helper(bin, state[:abi], args)}, state}
end
with {:ok, bin} <- check_option([state[:bin], args[:bin]], :missing_binary)
do
{contract_addr, tx_hash} = deploy_helper(bin, state[:abi], args)
result = {:ok, contract_addr, tx_hash}
{:reply, result , state}
else
err -> {:reply, err, state}
end
end
def handle_call(:address, _from, state) do

@ -60,7 +60,7 @@ defmodule EXW3Test do
test "starts a Contract GenServer for simple storage contract", context do
ExW3.Contract.start_link(SimpleStorage, abi: context[:simple_storage_abi])
{:ok, address} =
{:ok, address, _} =
ExW3.Contract.deploy(
SimpleStorage,
bin: ExW3.load_bin("test/examples/build/SimpleStorage.bin"),
@ -89,7 +89,7 @@ defmodule EXW3Test do
test "starts a Contract GenServer for array tester contract", context do
ExW3.Contract.start_link(ArrayTester, abi: context[:array_tester_abi])
{:ok, address} =
{:ok, address, _} =
ExW3.Contract.deploy(
ArrayTester,
bin: ExW3.load_bin("test/examples/build/ArrayTester.bin"),
@ -117,7 +117,7 @@ defmodule EXW3Test do
test "starts a Contract GenServer for event tester contract", context do
ExW3.Contract.start_link(EventTester, abi: context[:event_tester_abi])
{:ok, address} =
{:ok, address, _} =
ExW3.Contract.deploy(
EventTester,
bin: ExW3.load_bin("test/examples/build/EventTester.bin"),
@ -153,7 +153,7 @@ defmodule EXW3Test do
test "starts a Contract GenServer and uses the event listener", context do
ExW3.Contract.start_link(EventTester, abi: context[:event_tester_abi])
{:ok, address} =
{:ok, address, _} =
ExW3.Contract.deploy(
EventTester,
bin: ExW3.load_bin("test/examples/build/EventTester.bin"),
@ -200,7 +200,7 @@ defmodule EXW3Test do
test "starts a Contract GenServer for Complex contract", context do
ExW3.Contract.start_link(Complex, abi: context[:complex_abi])
{:ok, address} =
{:ok, address, _} =
ExW3.Contract.deploy(
Complex,
bin: ExW3.load_bin("test/examples/build/Complex.bin"),
@ -225,7 +225,7 @@ defmodule EXW3Test do
test "starts a Contract GenServer for AddressTester contract", context do
ExW3.Contract.start_link(AddressTester, abi: context[:address_tester_abi])
{:ok, address} =
{:ok, address, _} =
ExW3.Contract.deploy(
AddressTester,
bin: ExW3.load_bin("test/examples/build/AddressTester.bin"),

Loading…
Cancel
Save