Packages

Ethereum blockchain client for Gleam

Current section

Files

Jump to
glethers src glethers@provider.erl
Raw

src/glethers@provider.erl

-module(glethers@provider).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([to_request/2, decode_response/1]).
-export_type([provider/0, provider_error/0]).
-type provider() :: {rpc, binary()}.
-type provider_error() :: {decode_error, gleam@json:decode_error()}.
-spec to_request(provider(), glethers@rpc@methods:rpc_method()) -> gleam@http@request:request(binary()).
to_request(Provider, Method) ->
_pipe = gleam@http@request:new(),
_pipe@1 = gleam@http@request:set_method(_pipe, post),
_pipe@2 = gleam@http@request:set_host(_pipe@1, erlang:element(2, Provider)),
_pipe@3 = gleam@http@request:set_body(_pipe@2, Method),
_pipe@4 = gleam@http@request:set_path(_pipe@3, <<"/"/utf8>>),
_pipe@5 = gleam@http@request:prepend_header(
_pipe@4,
<<"Content-Type"/utf8>>,
<<"application/json"/utf8>>
),
gleam@http@request:map(_pipe@5, fun glethers@rpc@methods:convert_to_body/1).
-spec decode_response(gleam@http@response:response(binary())) -> {ok,
glethers@rpc@calls:json_rpc_response()} |
{error, gleam@json:decode_error()}.
decode_response(Body) ->
_pipe = erlang:element(4, Body),
glethers@rpc@calls:decode(_pipe).