wip
This commit is contained in:
parent
4ee1825b43
commit
bc870e5f2d
@ -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).
|
||||
|
||||
81
src/fd_hz.erl
Normal file
81
src/fd_hz.erl
Normal file
@ -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}.
|
||||
@ -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}.
|
||||
|
||||
|
||||
@ -60,5 +60,5 @@ init([]) ->
|
||||
5000,
|
||||
supervisor,
|
||||
[fd_httpd]},
|
||||
Children = [GridsD, WFCd, Httpd],
|
||||
Children = [Spy, GridsD, WFCd, Httpd],
|
||||
{ok, {RestartStrategy, Children}}.
|
||||
|
||||
@ -9,13 +9,19 @@
|
||||
-copyright("Peter Harpending <peterharpending@qpq.swiss>").
|
||||
-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".
|
||||
|
||||
12
zomp.meta
12
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}},
|
||||
{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","zj",{1,1,2}}]}.
|
||||
{"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}}]}.
|
||||
{key_name,none}.
|
||||
{a_email,"peterharpending@qpq.swiss"}.
|
||||
{c_email,"peterharpending@qpq.swiss"}.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user