Current section
Files
Jump to
Current section
Files
src/gleeth@commands@code.erl
-module(gleeth@commands@code).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/gleeth/commands/code.gleam").
-export([execute/2]).
-file("src/gleeth/commands/code.gleam", 20).
-spec print_code(binary(), binary()) -> nil.
print_code(Address, Code) ->
gleam_stdlib:println(<<"Address: "/utf8, Address/binary>>),
case Code of
<<"0x"/utf8>> ->
gleam_stdlib:println(<<"Type: No bytecode found"/utf8>>),
gleam_stdlib:println(<<"This could be:"/utf8>>),
gleam_stdlib:println(
<<" • EOA (Externally Owned Account/wallet)"/utf8>>
),
gleam_stdlib:println(
<<" • Uninitialized address (contract could be deployed later)"/utf8>>
),
gleam_stdlib:println(
<<" • Empty contract (deployed with no runtime code)"/utf8>>
);
_ ->
gleam_stdlib:println(<<"Type: Contract"/utf8>>),
gleam_stdlib:println(
<<<<"Code Length: "/utf8,
(gleam@string:inspect(string:length(Code)))/binary>>/binary,
" characters"/utf8>>
),
Preview_length = 100,
case string:length(Code) > Preview_length of
true ->
gleam_stdlib:println(
<<<<"Code Preview: "/utf8,
(gleam@string:slice(Code, 0, Preview_length))/binary>>/binary,
"..."/utf8>>
),
gleam_stdlib:println(<<"Full Code: "/utf8, Code/binary>>);
false ->
gleam_stdlib:println(<<"Full Code: "/utf8, Code/binary>>)
end
end,
gleam_stdlib:println(<<""/utf8>>).
-file("src/gleeth/commands/code.gleam", 10).
-spec execute(gleeth@provider:provider(), binary()) -> {ok, nil} |
{error, gleeth@rpc@types:gleeth_error()}.
execute(Provider, Address) ->
gleam@result:'try'(
gleeth@rpc@methods:get_code(Provider, Address),
fun(Code) ->
print_code(Address, Code),
{ok, nil}
end
).