we now spy keyblocks for spends, need to test but probably close to working

This commit is contained in:
Peter Harpending 2026-03-02 18:54:33 -08:00
parent bc870e5f2d
commit 46345da283
2 changed files with 40 additions and 3 deletions

View File

@ -13,6 +13,9 @@
txs_of_height/1,
mhs_of_height/1,
txs_of_mh/1,
filter_spends/1,
filter_spend/1,
spend_info/1,
test/0
]).
@ -64,7 +67,7 @@ mhs_of_height(Height) ->
txs_of_mh(MH) ->
{ok, TXs} = hz:mb_txs(MH),
filter_spends(TXs).
TXs.
filter_spends(TXs) ->

View File

@ -35,7 +35,8 @@
-type search_pattern() :: #sp{}.
-record(s,
{searching_for = [] :: search_pattern()}).
{last_height_seen = none :: none | integer(),
searching_for = [] :: [search_pattern()]}).
-type state() :: #s{}.
@ -74,7 +75,7 @@ start_link() ->
init(none) ->
tell("starting fd_spy"),
hz:chain_nodes(fewd:chain_nodes()),
hz:chain_nodes(fewd:chain_nodes()),
erlang:send_after(1000, self(), check_chain),
InitState = #s{},
{ok, InitState}.
@ -104,6 +105,10 @@ handle_cast(Unexpected, State) ->
handle_info(check_chain, State) ->
NewState = do_check_chain(State),
erlang:send_after(1000, self(), check_chain),
{noreply, NewState};
handle_info(Unexpected, State) ->
tell("~tp: unexpected info: ~tp", [?MODULE, Unexpected]),
{noreply, State}.
@ -124,6 +129,35 @@ terminate(_, _) ->
%% internals
%%-----------------------------------------------------------------------------
do_check_chain(State = #s{last_height_seen = none}) ->
case hz:kb_current_height() of
{ok, Max} ->
hh(Max-1, Max, State);
Error ->
tell("~tp hz error: ~tp", [?MODULE, Error]),
State
end;
do_check_chain(State = #s{last_height_seen = Min}) ->
case hz:kb_current_height() of
{ok, Max} ->
hh(Min, Max, State);
Error ->
tell("~tp hz error: ~tp", [?MODULE, Error]),
State
end.
% handle height
hh(PrevHeight, NewHeight, State) when PrevHeight < NewHeight ->
tell("~tp cool: PrevHeight=~tp, NewHeight=~tp", [?MODULE, PrevHeight, NewHeight]),
Spends = fd_hz:filter_spends(fd_hz:txs_from_to(PrevHeight + 1, NewHeight)),
tell("~tp spends: ~tp", [?MODULE, Spends]),
NewState = State#s{last_height_seen = NewHeight},
NewState;
hh(PrevHeight, NewHeight, State) when PrevHeight >= NewHeight ->
log(info, "~tp lame: PrevHeight=~tp, NewHeight=~tp", [?MODULE, PrevHeight, NewHeight]),
State.
-spec do_reg(Recipient, Amount, Payload, State) -> {Reply, NewState}
when Recipient :: pubkey32(),
Amount :: pos_integer(),