From bc870e5f2dad62f66f6f05dcc8894fdfd724aa2a Mon Sep 17 00:00:00 2001 From: Peter Harpending Date: Mon, 2 Mar 2026 18:27:05 -0800 Subject: [PATCH] wip --- src/fd_gridsd.erl | 9 ------ src/fd_hz.erl | 81 +++++++++++++++++++++++++++++++++++++++++++++++ src/fd_spy.erl | 2 ++ src/fd_sup.erl | 2 +- src/fewd.erl | 8 ++++- zomp.meta | 16 +++++++--- 6 files changed, 102 insertions(+), 16 deletions(-) create mode 100644 src/fd_hz.erl diff --git a/src/fd_gridsd.erl b/src/fd_gridsd.erl index da1d8b3..e010ee4 100644 --- a/src/fd_gridsd.erl +++ b/src/fd_gridsd.erl @@ -21,15 +21,6 @@ -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). diff --git a/src/fd_hz.erl b/src/fd_hz.erl new file mode 100644 index 0000000..5ab6872 --- /dev/null +++ b/src/fd_hz.erl @@ -0,0 +1,81 @@ +% @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, + 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), + filter_spends(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}. diff --git a/src/fd_spy.erl b/src/fd_spy.erl index 24b2e9d..b2a97e1 100644 --- a/src/fd_spy.erl +++ b/src/fd_spy.erl @@ -73,6 +73,8 @@ start_link() -> init(none) -> tell("starting fd_spy"), + hz:chain_nodes(fewd:chain_nodes()), + hz:chain_nodes(fewd:chain_nodes()), InitState = #s{}, {ok, InitState}. diff --git a/src/fd_sup.erl b/src/fd_sup.erl index e8804c8..0067aa9 100644 --- a/src/fd_sup.erl +++ b/src/fd_sup.erl @@ -60,5 +60,5 @@ init([]) -> 5000, supervisor, [fd_httpd]}, - Children = [GridsD, WFCd, Httpd], + Children = [Spy, GridsD, WFCd, Httpd], {ok, {RestartStrategy, Children}}. diff --git a/src/fewd.erl b/src/fewd.erl index 4ac3d53..72f3390 100644 --- a/src/fewd.erl +++ b/src/fewd.erl @@ -9,13 +9,19 @@ -copyright("Peter Harpending "). -license("BSD-2-Clause-FreeBSD"). --export([url/0, host/0, network_id/0, pubkey/0, akstr/0]). +-export([chain_nodes/0, 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". diff --git a/zomp.meta b/zomp.meta index e87c40b..2d8588f 100644 --- a/zomp.meta +++ b/zomp.meta @@ -5,12 +5,18 @@ {prefix,"fd"}. {desc,"Front End Web Dev in Erlang stuff"}. {package_id,{"otpr","fewd",{0,2,0}}}. -{deps,[{"otpr","hakuzaru",{0,7,0}}, - {"otpr","qr",{0,1,0}}, - {"otpr","gmserialization",{0,1,3}}, - {"otpr","eblake2",{1,0,1}}, +{deps,[{"otpr","hakuzaru",{0,8,3}}, + {"otpr","sophia",{9,0,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","zj",{1,1,2}}]}. + {"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}}]}. {key_name,none}. {a_email,"peterharpending@qpq.swiss"}. {c_email,"peterharpending@qpq.swiss"}.