Current section
Files
Jump to
Current section
Files
src/gleeth@commands@storage_at.erl
-module(gleeth@commands@storage_at).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/gleeth/commands/storage_at.gleam").
-export([execute/4]).
-file("src/gleeth/commands/storage_at.gleam", 55).
-spec interpret_storage_value(binary()) -> nil.
interpret_storage_value(Value) ->
Is_zero = case Value of
<<"0x0"/utf8>> ->
true;
<<"0x0000000000000000000000000000000000000000000000000000000000000000"/utf8>> ->
true;
_ ->
gleam@string:replace(Value, <<"0"/utf8>>, <<""/utf8>>) =:= <<"0x"/utf8>>
end,
case Is_zero of
true ->
gleam_stdlib:println(
<<" Interpretation: Uninitialized storage (all zeros)"/utf8>>
);
false ->
case gleeth@utils@hex:hex_to_int(Value) of
{ok, Decimal_val} ->
gleam_stdlib:println(
<<" As integer: "/utf8,
(erlang:integer_to_binary(Decimal_val))/binary>>
);
{error, _} ->
nil
end,
case string:length(Value) >= 42 of
true ->
Potential_address = <<"0x"/utf8,
(gleam@string:slice(
Value,
string:length(Value) - 40,
40
))/binary>>,
case gleam_stdlib:string_starts_with(
Potential_address,
<<"0x000000"/utf8>>
) of
false ->
gleam_stdlib:println(
<<" Potential address: "/utf8,
Potential_address/binary>>
);
true ->
nil
end;
false ->
nil
end,
case Value of
<<"0x0000000000000000000000000000000000000000000000000000000000000001"/utf8>> ->
gleam_stdlib:println(<<" Possible boolean: true"/utf8>>);
_ ->
nil
end
end.
-file("src/gleeth/commands/storage_at.gleam", 28).
-spec print_storage_info(binary(), binary(), binary(), binary()) -> nil.
print_storage_info(Address, Slot, Block, Value) ->
gleam_stdlib:println(<<"Storage Query:"/utf8>>),
gleam_stdlib:println(<<" Contract: "/utf8, Address/binary>>),
gleam_stdlib:println(<<" Slot: "/utf8, Slot/binary>>),
Block_display = case Block of
<<""/utf8>> ->
<<"latest"/utf8>>;
_ ->
Block
end,
gleam_stdlib:println(<<" Block: "/utf8, Block_display/binary>>),
gleam_stdlib:println(<<""/utf8>>),
gleam_stdlib:println(<<"Storage Value:"/utf8>>),
gleam_stdlib:println(<<" Raw (hex): "/utf8, Value/binary>>),
interpret_storage_value(Value),
gleam_stdlib:println(<<""/utf8>>).
-file("src/gleeth/commands/storage_at.gleam", 11).
-spec execute(gleeth@provider:provider(), binary(), binary(), binary()) -> {ok,
nil} |
{error, gleeth@rpc@types:gleeth_error()}.
execute(Provider, Address, Slot, Block) ->
gleam@result:'try'(
gleeth@rpc@methods:get_storage_at(Provider, Address, Slot, Block),
fun(Storage_value) ->
print_storage_info(Address, Slot, Block, Storage_value),
{ok, nil}
end
).