Packages

Ethereum blockchain client for Gleam

Current section

Files

Jump to
glethers src glethers@rpc@methods.erl
Raw

src/glethers@rpc@methods.erl

-module(glethers@rpc@methods).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([convert_to_body/1]).
-export_type([rpc_method/0]).
-type rpc_method() :: block_number |
chain_id |
gas_price |
{get_account, glethers@address:address(), glethers@block:block()} |
{get_balance, glethers@address:address(), glethers@block:block()}.
-spec convert_to_body(rpc_method()) -> binary().
convert_to_body(Method) ->
{Call, Params} = case Method of
block_number ->
{<<"eth_blockNumber"/utf8>>, []};
chain_id ->
{<<"eth_chainId"/utf8>>, []};
gas_price ->
{<<"eth_gasPrice"/utf8>>, []};
{get_account, Address, Block} ->
{<<"eth_getAccount"/utf8>>,
[begin
_pipe = Address,
glethers@address:to_string(_pipe)
end,
begin
_pipe@1 = Block,
glethers@block:to_string(_pipe@1)
end]};
{get_balance, Address@1, Block@1} ->
{<<"eth_getBalance"/utf8>>,
[begin
_pipe@2 = Address@1,
glethers@address:to_string(_pipe@2)
end,
begin
_pipe@3 = Block@1,
glethers@block:to_string(_pipe@3)
end]}
end,
_pipe@4 = {rpc_request, Call, Params, 1, <<"2.0"/utf8>>},
_pipe@5 = glethers@rpc@calls:encode_rpc_call(_pipe@4),
gleam@json:to_string(_pipe@5).