This commit is contained in:
2026-09-23 19:35:27 -07:00
parent 3683c12b1b
commit 7538ac2299
2 changed files with 154 additions and 74 deletions
+153 -73
View File
@@ -5,53 +5,129 @@
-copyright("Peter Harpending").
-export([start/1]).
-compile([export_all,nowarn_export_all]).
-spec start(ArgV) -> ok
when ArgV :: [string()].
start(ArgV) ->
ok = hz(),
du(ArgV).
rq(ArgV).
du(["-s" | Rest]) -> rq(Rest);
du(["--shell" | Rest]) -> rq(Rest);
du(Rest) -> rq(Rest), zx:silent_stop().
rq(["nuffin"]) ->
ok = io:format("hz status: ~tp~n", [hz:status()]),
ok = io:format("rbx_tuples: ~tp~n", [rbx_tuples()]),
ok = io:format("my akstr:~n~ts~n~n", [my_akstr()]),
ok = io:format("names ct aaci:~n~tp~n~n", [nct_aaci()]),
ok = io:format("rubicon ct aaci:~n~tp~n~n", [rct_aaci()]),
ok;
rq(["src", "names.aes"]) ->
{ok, Bytes} = file:read_file(nct_filepath()),
io:format("~s", [Bytes]);
rq(["src", "rubicon.aes"]) ->
{ok, Bytes} = file:read_file(rct_filepath()),
io:format("~s", [Bytes]);
rq(["-h" | _]) -> rq_help();
rq(["--help" | _]) -> rq_help();
rq(["help" | _]) -> rq_help();
rq(BadArgs) ->
io:format("arguments are a failure: ~tp~n", [BadArgs]),
rq_help().
rq_help() ->
io:format("~ts~n", [help_screen()]).
help_screen() ->
"""
rq = Decentralized Identity Namespace Disambiguation Utility
version 0.0.0 + 0.0.1i
USAGE: rq [ARGS]
USAGE:
rq [-s | --shell] [ARGS]
equivalent to `rq ARGS`, but starts erlang shell with
rq&deps in context; with no args, simply starts erlang
shell.
rq [-h | --help]
show this menu
rq debug
show variables
rq src names.aes print contract source
rq src rubicon.aes print contract source
""".
rq([]) -> rq_shell([]);
rq(["-s" | Rest]) -> rq_shell(Rest);
rq(["--shell" | Rest]) -> rq_shell(Rest);
rq(Rest) -> rq_noshell(Rest).
rq_shell(Args) ->
ok = shell:start_interactive(),
case Args of
[] -> ok;
More -> rq_II(More)
end.
rq_noshell(Args) ->
rq_II(Args),
zx:silent_stop().
%% @private
%% dispatch function
rq_II(["debug" | Args]) -> rq_debug(Args);
rq_II(["src" | Args]) -> rq_src(Args);
rq_II(["-h" | Args]) -> rq_help(Args);
rq_II(["--help" | Args]) -> rq_help(Args);
rq_II(BadArgs) -> badargs(BadArgs).
rq_src(["names.aes"]) ->
{ok, Bytes} = file:read_file(nct_filepath()),
io:format("~s", [Bytes]);
rq_src(["rubicon.aes"]) ->
{ok, Bytes} = file:read_file(nct_filepath()),
io:format("~s", [Bytes]);
rq_src(FailArgs) ->
badargs(FailArgs).
badargs(FailArgs) ->
io:format("you are a failure: ~p~n", [FailArgs]),
rq_help([]),
error(badargs).
rq_help(_) ->
io:format("~ts~n", [help_screen()]).
rq_debug(_) ->
ok = dbg_hz(),
ok = dbg_my(),
ok = dbg_nct(),
ok = dbg_rct(),
ok.
dbg_hz() ->
io:format("hz status: ~tp~n", [hz:status()]).
dbg_my() ->
Format =
"""
MY:
akstr ~ts~n
""",
Args = [my_akstr()],
io:format(Format, Args).
dbg_nct() ->
Format =
"""
NAMES CT:
filepath ~tp
ctstr ~ts
aaci ~tp~n
""",
Args =
[ nct_filepath()
, nct_ctstr()
, nct_aaci()
],
io:format(Format, Args).
dbg_rct() ->
Format =
"""
RUBICON CT:
filepath ~tp
aaci ~tp~n
""",
Args =
[ rct_filepath()
, rct_aaci()
],
io:format(Format, Args).
%du_register(
%% name contract deployed address
@@ -59,18 +135,21 @@ nct_ctstr() ->
"ct_2CDom5hKimtKSsTykhBYBKMgGv7youakZPVgk5h9qgNL3P65oV".
nct_aaci() ->
hz:prepare_contract(nct_filepath()).
case hz:prepare_contract(nct_filepath()) of
{ok, AACI} -> AACI;
{error, E} -> error(E)
end.
nct_filepath() ->
ct_dir() ++ "/names.aes".
%% rubicon contract deployed address
rct_ctstr() ->
"".
rct_aaci() ->
hz:prepare_contract(rct_filepath()).
case hz:prepare_contract(rct_filepath()) of
{ok, AACI} -> AACI;
{error, E} -> error(E)
end.
rct_filepath() ->
ct_dir() ++ "/rubicon.aes".
@@ -99,7 +178,6 @@ my_seed() ->
crypto:hash(sha3_512, <<"p@ssw0rd">>).
%% hz setup
hz() ->
ok = application:ensure_started(hakuzaru),
@@ -111,41 +189,43 @@ hz_nodes() ->
].
rbx_tuples() ->
NoiseStr = "Noise_NK_25519_ChaChaPoly_BLAKE2b",
ServicePubkey = <<116, 159, 91, 248, 138, 250, 73, 40, 231, 50,
81, 110, 137, 163, 44, 76, 48, 130, 225, 95,
168, 121, 93, 44, 148, 42, 180, 103, 11, 40,
168, 96>>,
NoisePrologue = <<>>,
[{"127.0.0.1", 6969, "tcp", NoiseStr, ServicePubkey, NoisePrologue}].
%% deploying
deploy_rct_with(RbxTuples) ->
case hz:contract_create(my_akstr(), rct_filepath(), [RbxTuples]) of
{ok, CreateTx} ->
deploy_rct_II(CreateTx);
Error ->
io:format("you are a failure: ~tp~n", [Error]),
error(Error)
end.
deploy_rct_II(UnsignedCreateTx) ->
SecretKey = my_secret_key(),
case hz:sign_tx(UnsignedCreateTx, SecretKey) of
{ok, SignedTx} ->
deploy_rct_III(SignedTx);
Error ->
io:format("you are a failure II: ~tp~n", [Error]),
error(Error)
end.
%%% deploying
%deploy_rct_with(RbxTuples) ->
% case hz:contract_create(my_akstr(), rct_filepath(), [RbxTuples]) of
% {ok, CreateTx} ->
% deploy_rct_II(CreateTx);
% Error ->
% io:format("you are a failure: ~tp~n", [Error]),
% error(Error)
% end.
%
%deploy_rct_II(UnsignedCreateTx) ->
% SecretKey = my_secret_key(),
% case hz:sign_tx(UnsignedCreateTx, SecretKey) of
% {ok, SignedTx} ->
% deploy_rct_III(SignedTx);
% Error ->
% io:format("you are a failure II: ~tp~n", [Error]),
% error(Error)
% end.
%
%
%deploy_rct_III(SignedCreateTx) ->
% case hz:post_tx(SignedCreateTx) of
% {ok, Result_III} ->
% io:format("Result the third: ~tp~n", [Result_III]);
% Error ->
% io:format("you are a failure III: ~tp~n", [Error]),
% error(Error)
% end.
%my_rbx_tuples() ->
% NoiseStr = "Noise_NK_25519_ChaChaPoly_BLAKE2b",
% ServicePubkey = <<116, 159, 91, 248, 138, 250, 73, 40, 231, 50,
% 81, 110, 137, 163, 44, 76, 48, 130, 225, 95,
% 168, 121, 93, 44, 148, 42, 180, 103, 11, 40,
% 168, 96>>,
% NoisePrologue = <<>>,
% [{"127.0.0.1", 6969, "tcp", NoiseStr, ServicePubkey, NoisePrologue}].
deploy_rct_III(SignedCreateTx) ->
case hz:post_tx(SignedCreateTx) of
{ok, Result_III} ->
io:format("Result the third: ~tp~n", [Result_III]);
Error ->
io:format("you are a failure III: ~tp~n", [Error]),
error(Error)
end.