Compare commits
2 Commits
4ee1825b43
...
46345da283
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
46345da283 | ||
|
|
bc870e5f2d |
@ -21,15 +21,6 @@
|
|||||||
|
|
||||||
-include("$zx_include/zx_logger.hrl").
|
-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().
|
-type hex() :: binary().
|
||||||
-define(SEC, 1).
|
-define(SEC, 1).
|
||||||
-define(MIN, 60*SEC).
|
-define(MIN, 60*SEC).
|
||||||
|
|||||||
84
src/fd_hz.erl
Normal file
84
src/fd_hz.erl
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
% @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}.
|
||||||
@ -35,7 +35,8 @@
|
|||||||
-type search_pattern() :: #sp{}.
|
-type search_pattern() :: #sp{}.
|
||||||
|
|
||||||
-record(s,
|
-record(s,
|
||||||
{searching_for = [] :: search_pattern()}).
|
{last_height_seen = none :: none | integer(),
|
||||||
|
searching_for = [] :: [search_pattern()]}).
|
||||||
|
|
||||||
-type state() :: #s{}.
|
-type state() :: #s{}.
|
||||||
|
|
||||||
@ -73,6 +74,8 @@ start_link() ->
|
|||||||
|
|
||||||
init(none) ->
|
init(none) ->
|
||||||
tell("starting fd_spy"),
|
tell("starting fd_spy"),
|
||||||
|
hz:chain_nodes(fewd:chain_nodes()),
|
||||||
|
erlang:send_after(1000, self(), check_chain),
|
||||||
InitState = #s{},
|
InitState = #s{},
|
||||||
{ok, InitState}.
|
{ok, InitState}.
|
||||||
|
|
||||||
@ -102,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) ->
|
handle_info(Unexpected, State) ->
|
||||||
tell("~tp: unexpected info: ~tp", [?MODULE, Unexpected]),
|
tell("~tp: unexpected info: ~tp", [?MODULE, Unexpected]),
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
@ -122,6 +129,35 @@ terminate(_, _) ->
|
|||||||
%% internals
|
%% 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}
|
-spec do_reg(Recipient, Amount, Payload, State) -> {Reply, NewState}
|
||||||
when Recipient :: pubkey32(),
|
when Recipient :: pubkey32(),
|
||||||
Amount :: pos_integer(),
|
Amount :: pos_integer(),
|
||||||
|
|||||||
@ -60,5 +60,5 @@ init([]) ->
|
|||||||
5000,
|
5000,
|
||||||
supervisor,
|
supervisor,
|
||||||
[fd_httpd]},
|
[fd_httpd]},
|
||||||
Children = [GridsD, WFCd, Httpd],
|
Children = [Spy, GridsD, WFCd, Httpd],
|
||||||
{ok, {RestartStrategy, Children}}.
|
{ok, {RestartStrategy, Children}}.
|
||||||
|
|||||||
@ -9,13 +9,19 @@
|
|||||||
-copyright("Peter Harpending <peterharpending@qpq.swiss>").
|
-copyright("Peter Harpending <peterharpending@qpq.swiss>").
|
||||||
-license("BSD-2-Clause-FreeBSD").
|
-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([listen/1, ignore/0]).
|
||||||
-export([start/2, stop/1]).
|
-export([start/2, stop/1]).
|
||||||
|
|
||||||
-include("$zx_include/zx_logger.hrl").
|
-include("$zx_include/zx_logger.hrl").
|
||||||
|
|
||||||
|
|
||||||
|
%% for testing: use mainnet
|
||||||
|
%chain_nodes() ->
|
||||||
|
% [{"tsuriai.jp", 3013}].
|
||||||
|
chain_nodes() ->
|
||||||
|
[{"tsuriai.jp", 4013}].
|
||||||
|
|
||||||
url() -> "http://" ++ host().
|
url() -> "http://" ++ host().
|
||||||
host() -> "localhost:8000".
|
host() -> "localhost:8000".
|
||||||
network_id() -> "groot.testnet".
|
network_id() -> "groot.testnet".
|
||||||
|
|||||||
16
zomp.meta
16
zomp.meta
@ -5,12 +5,18 @@
|
|||||||
{prefix,"fd"}.
|
{prefix,"fd"}.
|
||||||
{desc,"Front End Web Dev in Erlang stuff"}.
|
{desc,"Front End Web Dev in Erlang stuff"}.
|
||||||
{package_id,{"otpr","fewd",{0,2,0}}}.
|
{package_id,{"otpr","fewd",{0,2,0}}}.
|
||||||
{deps,[{"otpr","hakuzaru",{0,7,0}},
|
{deps,[{"otpr","hakuzaru",{0,8,3}},
|
||||||
{"otpr","qr",{0,1,0}},
|
{"otpr","sophia",{9,0,0}},
|
||||||
{"otpr","gmserialization",{0,1,3}},
|
{"otpr","gmserialization",{0,1,3}},
|
||||||
{"otpr","eblake2",{1,0,1}},
|
{"otpr","eblake2",{1,0,1}},
|
||||||
|
{"otpr","base58",{0,1,1}},
|
||||||
|
{"otpr","gmbytecode",{3,4,1}},
|
||||||
{"otpr","base58",{0,1,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}.
|
{key_name,none}.
|
||||||
{a_email,"peterharpending@qpq.swiss"}.
|
{a_email,"peterharpending@qpq.swiss"}.
|
||||||
{c_email,"peterharpending@qpq.swiss"}.
|
{c_email,"peterharpending@qpq.swiss"}.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user