Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle errors when gas_limit is calculated #110

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/eth/query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,21 @@ defmodule ETH.Query do
{:ok, hex_gas_estimate} ->
{:ok, hex_gas_estimate |> convert_to_number |> convert(denomination) |> round}

error ->
error
{:error, error} ->
{:error, error}
end
end

def estimate_gas!(transaction \\ %{data: ""}, denomaination \\ :wei)

def estimate_gas!(transaction = %{to: _to, data: _data}, denomination) do
{:ok, hex_gas_estimate} = HttpClient.eth_estimate_gas(transaction)
case HttpClient.eth_estimate_gas(transaction) do
{:ok, hex_gas_estimate} ->
hex_gas_estimate |> convert_to_number |> convert(denomination) |> round

hex_gas_estimate |> convert_to_number |> convert(denomination) |> round
{:error, error} ->
{:error, error}
end
end

def convert_transaction_log(log) do
Expand Down
9 changes: 6 additions & 3 deletions lib/eth/transaction.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ defmodule ETH.Transaction do
def send_transaction(params, private_key) do
set_default_from(params, private_key)
|> build
|> sign_transaction(private_key)
|> Base.encode16()
|> send
|> case do
%{gas_limit: {:error, error}} -> {:error, error}
build -> sign_transaction(build, private_key)
|> Base.encode16()
|> send
end
end

def send_transaction(sender_wallet, receiver_wallet, value) when is_number(value) do
Expand Down