Packages

Ethereum library for Gleam - JSON-RPC client, transaction signing, ABI encoding, and wallet management on the BEAM

Current section

Files

Jump to
gleeth src gleeth.erl
Raw

src/gleeth.erl

-module(gleeth).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/gleeth.gleam").
-export([main/0]).
-file("src/gleeth.gleam", 40).
-spec execute_wallet_command(list(binary())) -> nil.
execute_wallet_command(Wallet_args) ->
case gleeth@commands@wallet:parse_args(Wallet_args) of
{ok, Operation} ->
case gleeth@commands@wallet:run(Operation) of
{ok, _} ->
nil;
{error, Msg} ->
gleeth@ethereum@formatting:print_error(
<<"Wallet error: "/utf8, Msg/binary>>
)
end;
{error, Msg@1} ->
gleeth@ethereum@formatting:print_error(
<<"Invalid wallet command: "/utf8, Msg@1/binary>>
),
gleeth@commands@wallet:print_usage()
end.
-file("src/gleeth.gleam", 91).
-spec print_error(gleeth@rpc@types:gleeth_error()) -> nil.
print_error(Error) ->
gleeth@ethereum@formatting:print_error(
gleeth@rpc@types:error_to_string(Error)
).
-file("src/gleeth.gleam", 55).
-spec execute_command(gleeth@cli:command(), gleeth@provider:provider()) -> nil.
execute_command(Command, P) ->
Result = case Command of
block_number ->
gleeth@commands@block_number:execute(P);
{balance, Addresses, File} ->
gleeth@commands@balance:execute(P, Addresses, File);
{call, Contract, Function, Parameters, Abi_file} ->
gleeth@commands@call:execute(
P,
Contract,
Function,
Parameters,
Abi_file
);
{transaction, Hash} ->
gleeth@commands@transaction:execute(P, Hash);
{code, Address} ->
gleeth@commands@code:execute(P, Address);
{estimate_gas, From, To, Value, Data} ->
gleeth@commands@estimate_gas:execute(P, From, To, Value, Data);
{storage_at, Address@1, Slot, Block} ->
gleeth@commands@storage_at:execute(P, Address@1, Slot, Block);
{get_logs, From_block, To_block, Address@2, Topics} ->
gleeth@commands@get_logs:execute(
P,
From_block,
To_block,
Address@2,
Topics
);
{send, To@1, Value@1, Private_key, Gas_limit, Data@1, Legacy} ->
gleeth@commands@send:execute(
P,
{send_args,
To@1,
Value@1,
Private_key,
Gas_limit,
Data@1,
Legacy}
);
{wallet, _} ->
gleeth@ethereum@formatting:print_error(
<<"Wallet command should be handled separately"/utf8>>
),
{ok, nil};
help ->
gleeth@cli:show_help(),
{ok, nil}
end,
case Result of
{ok, _} ->
nil;
{error, Err} ->
print_error(Err)
end.
-file("src/gleeth.gleam", 17).
-spec main() -> nil.
main() ->
case erlang:element(4, argv:load()) of
[] ->
gleeth@cli:show_help();
Args ->
case gleeth@cli:parse_args(Args) of
{ok, Parsed_args} ->
case erlang:element(2, Parsed_args) of
help ->
gleeth@cli:show_help();
{wallet, Wallet_args} ->
execute_wallet_command(Wallet_args);
_ ->
case gleeth@provider:new(
erlang:element(3, Parsed_args)
) of
{ok, P} ->
execute_command(
erlang:element(2, Parsed_args),
P
);
{error, Err} ->
print_error(Err)
end
end;
{error, Err@1} ->
print_error(Err@1)
end
end.