-module(gleeth@commands@get_logs). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/gleeth/commands/get_logs.gleam"). -export([execute/5]). -file("src/gleeth/commands/get_logs.gleam", 122). -spec print_single_log(gleeth@ethereum@types:log(), integer()) -> nil. print_single_log(Log, Index) -> gleam_stdlib:println( <<<<"Log #"/utf8, (erlang:integer_to_binary(Index))/binary>>/binary, ":"/utf8>> ), gleam_stdlib:println( <<" Contract: "/utf8, (erlang:element(2, Log))/binary>> ), gleam_stdlib:println( <<<<<<<<" Block: "/utf8, (erlang:element(5, Log))/binary>>/binary, " | Transaction: "/utf8>>/binary, (gleam@string:slice(erlang:element(6, Log), 0, 10))/binary>>/binary, "..."/utf8>> ), case erlang:element(3, Log) of [] -> gleam_stdlib:println(<<" Topics: (none)"/utf8>>); [Topic] -> gleam_stdlib:println( <<<<" Topics: ["/utf8, (gleam@string:slice(Topic, 0, 10))/binary>>/binary, "...]"/utf8>> ); _ -> gleam_stdlib:println( <<<<<<<<" Topics: "/utf8, (erlang:integer_to_binary( erlang:length(erlang:element(3, Log)) ))/binary>>/binary, " topics ["/utf8>>/binary, (gleam@string:slice( begin _pipe = gleam@list:first(erlang:element(3, Log)), gleam@result:unwrap(_pipe, <<""/utf8>>) end, 0, 10 ))/binary>>/binary, "...]"/utf8>> ) end, Data_preview = case string:length(erlang:element(4, Log)) > 20 of true -> <<(gleam@string:slice(erlang:element(4, Log), 0, 20))/binary, "..."/utf8>>; false -> erlang:element(4, Log) end, gleam_stdlib:println(<<" Data: "/utf8, Data_preview/binary>>), gleam_stdlib:println(<<" Status: "/utf8, (case erlang:element(10, Log) of true -> <<"Removed"/utf8>>; false -> <<"Active"/utf8>> end)/binary>>), gleam_stdlib:println(<<""/utf8>>). -file("src/gleeth/commands/get_logs.gleam", 31). -spec print_logs_info( binary(), binary(), binary(), list(binary()), list(gleeth@ethereum@types:log()) ) -> nil. print_logs_info(From_block, To_block, Address, Topics, Logs) -> gleam_stdlib:println(<<"Event Logs Query:"/utf8>>), From_display = case From_block of <<""/utf8>> -> <<"latest"/utf8>>; _ -> From_block end, gleam_stdlib:println(<<" From Block: "/utf8, From_display/binary>>), To_display = case To_block of <<""/utf8>> -> <<"latest"/utf8>>; _ -> To_block end, gleam_stdlib:println(<<" To Block: "/utf8, To_display/binary>>), case Address of <<""/utf8>> -> gleam_stdlib:println(<<" Contract: All contracts"/utf8>>); _ -> gleam_stdlib:println(<<" Contract: "/utf8, Address/binary>>) end, case Topics of [] -> gleam_stdlib:println(<<" Topics: All topics"/utf8>>); _ -> gleam_stdlib:println(<<" Topics:"/utf8>>), gleam@list:each( Topics, fun(Topic) -> gleam_stdlib:println(<<" "/utf8, Topic/binary>>) end ) end, gleam_stdlib:println(<<""/utf8>>), Log_count = erlang:length(Logs), gleam_stdlib:println( <<<<"Found "/utf8, (erlang:integer_to_binary(Log_count))/binary>>/binary, " log(s)"/utf8>> ), case Log_count > 0 of true -> gleam_stdlib:println(<<""/utf8>>), Display_limit = 10, Logs_to_show = case Log_count > Display_limit of true -> gleam_stdlib:println( <<<<"Showing first "/utf8, (erlang:integer_to_binary(Display_limit))/binary>>/binary, " logs (use filters to narrow results):"/utf8>> ), gleam_stdlib:println(<<""/utf8>>), gleam@list:take(Logs, Display_limit); false -> Logs end, gleam@list:each( gleam@list:index_map( Logs_to_show, fun(Log, Index) -> {Log, Index + 1} end ), fun(Log_with_index) -> {Log@1, Index@1} = Log_with_index, print_single_log(Log@1, Index@1) end ), case Log_count > Display_limit of true -> gleam_stdlib:println(<<""/utf8>>), gleam_stdlib:println( <<<<"... and "/utf8, (erlang:integer_to_binary( Log_count - Display_limit ))/binary>>/binary, " more logs"/utf8>> ), gleam_stdlib:println( <<"Use more specific filters (--address, --topic, smaller block range) to see fewer results"/utf8>> ); false -> nil end; false -> gleam_stdlib:println( <<"No logs found matching the specified criteria."/utf8>> ) end, gleam_stdlib:println(<<""/utf8>>). -file("src/gleeth/commands/get_logs.gleam", 12). -spec execute( gleeth@provider:provider(), binary(), binary(), binary(), list(binary()) ) -> {ok, nil} | {error, gleeth@rpc@types:gleeth_error()}. execute(Provider, From_block, To_block, Address, Topics) -> gleam@result:'try'( gleeth@rpc@methods:get_logs( Provider, From_block, To_block, Address, Topics ), fun(Logs) -> print_logs_info(From_block, To_block, Address, Topics, Logs), {ok, nil} end ).