Compare commits

..

No commits in common. "46345da283b17f53ecf90c5093cba638240d9edf" and "4ee1825b430b9e8630017f1e8ed01ad14a3c1440" have entirely different histories.

6 changed files with 17 additions and 140 deletions

View File

@ -21,6 +21,15 @@
-include("$zx_include/zx_logger.hrl").
%% for craig's autism
%-type grids_get_response() :: #{"grids" := 1,
% "chain" := "gajumaru",
% "network_id" := "groot.testnet",
% "type" := "tx",
% "public_id" := false,
% "payload" := string()}.
%
% semantic type for hex encoding of a random binary string
-type hex() :: binary().
-define(SEC, 1).
-define(MIN, 60*SEC).

View File

@ -1,84 +0,0 @@
% @doc hz helper functions
-module(fd_hz).
-export_type([
]).
-export([
txs_current/0,
txs_since_height/1,
txs_minus/1,
txs_from_to/2,
current_height/0,
txs_of_height/1,
mhs_of_height/1,
txs_of_mh/1,
filter_spends/1,
filter_spend/1,
spend_info/1,
test/0
]).
-spec test() -> no_return().
test() ->
io:format("~tp~n", [hz:gen_current()]),
io:format("~tp~n", [hz:kb_current()]),
ok.
txs_current() ->
H = current_height(),
txs_of_height(H).
txs_since_height(H) ->
txs_from_to(H, current_height()).
txs_minus(N) ->
H = current_height(),
L = H - N,
txs_from_to(L, H).
txs_from_to(Min, Max) when Min =< Max ->
lists:append([txs_of_height(H) || H <- lists:seq(Min, Max)]);
txs_from_to(Min, Max) when Min > Max ->
[].
current_height() ->
{ok, H} = hz:kb_current_height(),
H.
txs_of_height(Height) ->
lists:append([txs_of_mh(MH) || MH <- mhs_of_height(Height)]).
-spec mhs_of_height(Height :: pos_integer()) -> term().
mhs_of_height(Height) ->
{ok, #{"micro_blocks" := MHs}} = hz:gen_by_height(Height),
MHs.
txs_of_mh(MH) ->
{ok, TXs} = hz:mb_txs(MH),
TXs.
filter_spends(TXs) ->
lists:filtermap(fun filter_spend/1, TXs).
filter_spend(#{"tx" := TX = #{"type" := "SpendTx"}}) -> {true, spend_info(TX)};
filter_spend(_) -> false.
spend_info(#{"type" := "SpendTx",
"recipient_id" := Recipient,
"amount" := Amount,
"payload" := Payload}) ->
{sp, Recipient, Amount, Payload}.

View File

@ -35,8 +35,7 @@
-type search_pattern() :: #sp{}.
-record(s,
{last_height_seen = none :: none | integer(),
searching_for = [] :: [search_pattern()]}).
{searching_for = [] :: search_pattern()}).
-type state() :: #s{}.
@ -74,8 +73,6 @@ start_link() ->
init(none) ->
tell("starting fd_spy"),
hz:chain_nodes(fewd:chain_nodes()),
erlang:send_after(1000, self(), check_chain),
InitState = #s{},
{ok, InitState}.
@ -105,10 +102,6 @@ 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}.
@ -129,35 +122,6 @@ 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(),

View File

@ -60,5 +60,5 @@ init([]) ->
5000,
supervisor,
[fd_httpd]},
Children = [Spy, GridsD, WFCd, Httpd],
Children = [GridsD, WFCd, Httpd],
{ok, {RestartStrategy, Children}}.

View File

@ -9,19 +9,13 @@
-copyright("Peter Harpending <peterharpending@qpq.swiss>").
-license("BSD-2-Clause-FreeBSD").
-export([chain_nodes/0, url/0, host/0, network_id/0, pubkey/0, akstr/0]).
-export([url/0, host/0, network_id/0, pubkey/0, akstr/0]).
-export([listen/1, ignore/0]).
-export([start/2, stop/1]).
-include("$zx_include/zx_logger.hrl").
%% for testing: use mainnet
%chain_nodes() ->
% [{"tsuriai.jp", 3013}].
chain_nodes() ->
[{"tsuriai.jp", 4013}].
url() -> "http://" ++ host().
host() -> "localhost:8000".
network_id() -> "groot.testnet".

View File

@ -5,18 +5,12 @@
{prefix,"fd"}.
{desc,"Front End Web Dev in Erlang stuff"}.
{package_id,{"otpr","fewd",{0,2,0}}}.
{deps,[{"otpr","hakuzaru",{0,8,3}},
{"otpr","sophia",{9,0,0}},
{deps,[{"otpr","hakuzaru",{0,7,0}},
{"otpr","qr",{0,1,0}},
{"otpr","gmserialization",{0,1,3}},
{"otpr","eblake2",{1,0,1}},
{"otpr","base58",{0,1,1}},
{"otpr","gmbytecode",{3,4,1}},
{"otpr","base58",{0,1,1}},
{"otpr","eblake2",{1,0,1}},
{"otpr","ec_utils",{1,0,0}},
{"otpr","zj",{1,1,2}},
{"otpr","getopt",{1,0,2}},
{"otpr","qr",{0,1,0}}]}.
{"otpr","zj",{1,1,2}}]}.
{key_name,none}.
{a_email,"peterharpending@qpq.swiss"}.
{c_email,"peterharpending@qpq.swiss"}.