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@utils@file.erl
Raw

src/gleeth@utils@file.erl

-module(gleeth@utils@file).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/gleeth/utils/file.gleam").
-export([read_addresses_from_file/1]).
-file("src/gleeth/utils/file.gleam", 28).
-spec validate_addresses_from_lines(list(binary())) -> {ok, list(binary())} |
{error, gleeth@rpc@types:gleeth_error()}.
validate_addresses_from_lines(Lines) ->
case Lines of
[] ->
{error, {config_error, <<"No valid addresses found in file"/utf8>>}};
_ ->
gleam@list:try_map(
Lines,
fun gleeth@utils@validation:validate_address/1
)
end.
-file("src/gleeth/utils/file.gleam", 9).
-spec read_addresses_from_file(binary()) -> {ok, list(binary())} |
{error, gleeth@rpc@types:gleeth_error()}.
read_addresses_from_file(Filename) ->
case simplifile:read(Filename) of
{ok, Content} ->
Lines = gleam@string:split(Content, <<"\n"/utf8>>),
Trimmed_lines = gleam@list:map(Lines, fun gleam@string:trim/1),
Non_empty_lines = gleam@list:filter(
Trimmed_lines,
fun(Line) ->
not gleam@string:is_empty(Line) andalso not gleam_stdlib:string_starts_with(
Line,
<<"#"/utf8>>
)
end
),
validate_addresses_from_lines(Non_empty_lines);
{error, _} ->
{error,
{config_error,
<<"Could not read file: "/utf8, Filename/binary>>}}
end.