sbn contract

This commit is contained in:
Peter Harpending
2026-12-04 11:03:04 -08:00
parent 23ec148c18
commit 5997431690
7 changed files with 166 additions and 147 deletions
+6
View File
@@ -29,3 +29,9 @@ This repository lives at <https://git.harpending.org/pharpend/rbx>
- x05-rq:
- rq = Rubicon querier
- has hardcoded contract address
- x06-sbn:
- sbn = Sierra Bravo November
- has hardcoded contract address
- combines names/rubicon contract into one (no null pointer
dereference bullshit...)
-3
View File
@@ -1,3 +0,0 @@
# goal stack
- rq deploy
-15
View File
@@ -1,15 +0,0 @@
contract interface Rubicon =
entrypoint lookup: () => list(string * int * string * string * address * bytes)
contract Names =
type rbx_tuple = string * int * string * string * address * bytes
type state = map(string, Rubicon)
entrypoint init(): state =
{}
stateful entrypoint register(name: string, addr: Rubicon): unit =
put(state{[name] = addr})
stateful entrypoint lookup(name: string): list(rbx_tuple) =
Map.lookup(name, state)
+31
View File
@@ -0,0 +1,31 @@
contract Sbn =
record sp =
{ip : string,
port : int,
protocol : string, // "tcp", "udp", "sctp", etc
noise : string, // Noise_Foo_Bar_Baz_Quux
pubkey : address, // responder static pubkey (noise: rs field)
prologue : bytes} // noise prologue (empty = no prologue)
type state = map(string, list(sp))
entrypoint
init : () => state
init() = {}
stateful entrypoint
register : (string, list(sp)) => bool
register(name, roster) =
put(state{[name] = roster})
true
stateful entrypoint
lookup : (string) => option(list(rp))
lookup(name) =
Map.lookup(name, state)
stateful entrypoint
get_state : state
get_state() =
state
+1 -1
View File
@@ -1,4 +1,4 @@
{application,rq,
{application,sbn,
[{description,[]},
{registered,[]},
{included_applications,[]},
+125 -125
View File
@@ -1,6 +1,6 @@
%% @doc rq: Decentralized Identity Namespace Disambiguation Utility
-module(rq).
-vsn("0.1.0").
%% @doc sbn: Sierra Bravo November
-module(sbn).
-vsn("0.0.6").
-author("Peter Harpending").
-copyright("Peter Harpending").
@@ -11,7 +11,7 @@
% deploy opts
-record(rdo,
{deploy_file = "rq.deploy" :: file:filename(),
{deploy_file = "sbn.deploy" :: file:filename(),
op = deploy :: deploy | tx | signed_tx}).
-spec start(ArgV) -> ok
@@ -20,134 +20,134 @@
start(ArgV) ->
ok = hz(),
_ = application:ensure_all_started(ssl),
rq(ArgV).
sbn(ArgV).
help_screen() ->
"""
rq = Decentralized Identity Namespace Disambiguation Utility
version 0.0.0 + 0.0.1i
sbn = Sierra Bravo November
version 0.0.6
USAGE:
rq [-s | --shell] [ARGS]
equivalent to `rq ARGS`, but starts erlang shell with
rq&deps in context; with no args, simply starts erlang
sbn [-s | --shell] [ARGS]
equivalent to `sbn ARGS`, but starts erlang shell with
sbn&deps in context; with no args, simply starts erlang
shell.
rq [-h | --help]
sbn [-h | --help]
show this menu
rq debug
sbn debug
show variables
rq addr names
rq addr names.aes
rq ctstr names
rq ctstr names.aes deployed address of names
rq decode cb_... deep decode of api string but only the ones i use
rq decode tx_... deep decode of api string but only the ones i use
rq deploy
rq deploy --tx debug ContractCreateTx
rq deploy --tx-only
rq deploy --tx_only
rq deploy --signed debug SignedTx
rq deploy --signed-tx
rq deploy --signed_tx
rq grids URL only works with the faucet grids
rq my
rq my everything all
rq my akstr my akstr
rq my acc
rq my balance
rq my explorer
rq my explorer_link
rq my explorer_url
rq my url
rq my rbx_tuples
rq my tuples my rbx_tuples
rq query ak_... hz:acc("ak_...")
rq query ct_... hz:contract("ak_...")
rq query th_... hz:contract("ak_...")
rq lookup NAME
rq register NAME
rq src names.aes print contract source
rq src rubicon.aes print contract source
sbn addr names
sbn addr names.aes
sbn ctstr names
sbn ctstr names.aes deployed address of names
sbn decode cb_... deep decode of api string but only the ones i use
sbn decode tx_... deep decode of api string but only the ones i use
sbn deploy
sbn deploy --tx debug ContractCreateTx
sbn deploy --tx-only
sbn deploy --tx_only
sbn deploy --signed debug SignedTx
sbn deploy --signed-tx
sbn deploy --signed_tx
sbn grids URL only works with the faucet grids
sbn my
sbn my everything all
sbn my akstr my akstr
sbn my acc
sbn my balance
sbn my explorer
sbn my explorer_link
sbn my explorer_url
sbn my url
sbn my rbx_tuples
sbn my tuples my rbx_tuples
sbn query ak_... hz:acc("ak_...")
sbn query ct_... hz:contract("ak_...")
sbn query th_... hz:contract("ak_...")
sbn lookup NAME
sbn register NAME
sbn src names.aes print contract source
sbn 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).
sbn([]) -> sbn_shell([]);
sbn(["-s" | Rest]) -> sbn_shell(Rest);
sbn(["--shell" | Rest]) -> sbn_shell(Rest);
sbn(Rest) -> sbn_noshell(Rest).
rq_shell(Args) ->
sbn_shell(Args) ->
ok = shell:start_interactive(),
case Args of
[] -> ok;
More -> rq_II(More)
More -> sbn_II(More)
end.
rq_noshell(Args) ->
rq_II(Args),
sbn_noshell(Args) ->
sbn_II(Args),
zx:silent_stop().
%% @private
%% dispatch function
rq_II(Args) ->
sbn_II(Args) ->
case Args of
[Addr, Names] when ((Addr =:= "addr") orelse Addr =:= "ctstr") andalso
(Names =:= "names.aes" orelse Names =:= "names") ->
io:format("~ts~n", [nct_ctstr()]);
["debug" | Rest] ->
rq_debug(Rest);
["decode", ApiStr] -> rq_decode(ApiStr);
["deploy"] -> rq_deploy(#rdo{});
["deploy", "--signed"] -> rq_deploy(#rdo{op = signed_tx});
["deploy", "--signed-tx"] -> rq_deploy(#rdo{op = signed_tx});
["deploy", "--signed_tx"] -> rq_deploy(#rdo{op = signed_tx});
["deploy", "--tx"] -> rq_deploy(#rdo{op = tx});
["deploy", "--tx-only"] -> rq_deploy(#rdo{op = tx});
["deploy", "--tx_only"] -> rq_deploy(#rdo{op = tx});
["grids", URL] -> rq_grids(URL);
["my"] -> rq_my(everything);
["my", "everything"] -> rq_my(everything);
["my", "acc"] -> rq_my(acc);
["my", "addr"] -> rq_my(akstr);
["my", "akstr"] -> rq_my(akstr);
["my", "balance"] -> rq_my(balance);
["my", "explorer"] -> rq_my(url);
["my", "explorer_link"] -> rq_my(url);
["my", "explorer_url"] -> rq_my(url);
["my", "url"] -> rq_my(url);
["my", "rbx_tuples"] -> rq_my(rbx_tuples);
["my", "tuples"] -> rq_my(rbx_tuples);
["lookup", Name] -> rq_lookup(Name);
["register", Name] -> rq_register(Name);
["query" | Args2] -> rq_query(Args2);
["src" | Args2] -> rq_src(Args2);
["-h" | Args2] -> rq_help(Args2);
["--help" | Args2] -> rq_help(Args2);
sbn_debug(Rest);
["decode", ApiStr] -> sbn_decode(ApiStr);
["deploy"] -> sbn_deploy(#rdo{});
["deploy", "--signed"] -> sbn_deploy(#rdo{op = signed_tx});
["deploy", "--signed-tx"] -> sbn_deploy(#rdo{op = signed_tx});
["deploy", "--signed_tx"] -> sbn_deploy(#rdo{op = signed_tx});
["deploy", "--tx"] -> sbn_deploy(#rdo{op = tx});
["deploy", "--tx-only"] -> sbn_deploy(#rdo{op = tx});
["deploy", "--tx_only"] -> sbn_deploy(#rdo{op = tx});
["grids", URL] -> sbn_grids(URL);
["my"] -> sbn_my(everything);
["my", "everything"] -> sbn_my(everything);
["my", "acc"] -> sbn_my(acc);
["my", "addr"] -> sbn_my(akstr);
["my", "akstr"] -> sbn_my(akstr);
["my", "balance"] -> sbn_my(balance);
["my", "explorer"] -> sbn_my(url);
["my", "explorer_link"] -> sbn_my(url);
["my", "explorer_url"] -> sbn_my(url);
["my", "url"] -> sbn_my(url);
["my", "rbx_tuples"] -> sbn_my(rbx_tuples);
["my", "tuples"] -> sbn_my(rbx_tuples);
["lookup", Name] -> sbn_lookup(Name);
["register", Name] -> sbn_register(Name);
["query" | Args2] -> sbn_query(Args2);
["src" | Args2] -> sbn_src(Args2);
["-h" | Args2] -> sbn_help(Args2);
["--help" | Args2] -> sbn_help(Args2);
BadArgs -> badargs(BadArgs)
end.
rq_deploy(Opts = #rdo{deploy_file = F}) ->
sbn_deploy(Opts = #rdo{deploy_file = F}) ->
case file:read_file(F) of
{ok, B} ->
io:format("already deployed brother~n~ts~n", [B]),
error(low_iq);
_Error ->
rq_deploy_II(Opts)
sbn_deploy_II(Opts)
end.
rq_deploy_II(#rdo{op = Op}) ->
sbn_deploy_II(#rdo{op = Op}) ->
{ok, CreateTx} = hz:contract_create(my_akstr(), rct_filepath(), {erlang, [my_rbx_tuples()]}),
case Op of
deploy ->
sign_and_post(CreateTx);
tx ->
rq_decode(CreateTx);
sbn_decode(CreateTx);
signed_tx ->
Signed = hz:sign_tx(CreateTx, my_secret_key()),
rq_decode(Signed);
sbn_decode(Signed);
NYI ->
io:format("NYI: ~tp~n", [NYI]),
error(ur_mom_is_an_op)
@@ -160,7 +160,7 @@ sign_and_post(UnsignedTx) ->
{ok, PostResult} = hz:post_tx(SignedTx),
case PostResult of
#{"tx_hash" := ThStr} ->
rq_query([ThStr]);
sbn_query([ThStr]);
#{"reason" := NodeErr} ->
io:format("ERROR: node sent back the following extremely helpful error message~n", []),
io:format("~tp~n", [NodeErr]),
@@ -172,16 +172,16 @@ sign_and_post(UnsignedTx) ->
end.
rq_decode(TxStr = "tx_" ++ _) ->
rq_decode(unicode:characters_to_binary(TxStr));
rq_decode(TxBin = <<"tx_", _/binary>>) ->
sbn_decode(TxStr = "tx_" ++ _) ->
sbn_decode(unicode:characters_to_binary(TxStr));
sbn_decode(TxBin = <<"tx_", _/binary>>) ->
io:format("TxBin = ~tp~n", [TxBin]),
{transaction, Bytes} = gmser_api_encoder:decode(TxBin),
just_the_tip_decode(Bytes),
ok;
rq_decode(CbStr = "cb_" ++ _) ->
rq_decode(unicode:characters_to_binary(CbStr));
rq_decode(CbBin = <<"cb_", _/binary>>) ->
sbn_decode(CbStr = "cb_" ++ _) ->
sbn_decode(unicode:characters_to_binary(CbStr));
sbn_decode(CbBin = <<"cb_", _/binary>>) ->
io:format("CbBin = ~tp~n", [CbBin]),
{contract_bytearray, Bytes} = gmser_api_encoder:decode(CbBin),
io:format("Bytes = ~tp~n", [Bytes]),
@@ -192,7 +192,7 @@ rq_decode(CbBin = <<"cb_", _/binary>>) ->
ok.
% this is like rq_decode but in the case where the data at hand is
% this is like sbn_decode but in the case where the data at hand is
% NOT api-encoded; a typical example would be debugging a signed
% transaction; one of the fields is the signatee, which needs to be
% decomposed
@@ -240,11 +240,11 @@ sig_valid(Pk32, Sig, Tx) ->
ok.
% hacky to get fund via faucet to work
rq_grids(URL) ->
sbn_grids(URL) ->
{ok, {{sign, https}, URL_II}} = hz_grids:parse(URL),
case httpc:request(URL_II) of
{ok, {{_HttpVsn, 200, _Slogan}, _Hdrs, JSONBodyStr}} ->
rq_grids_ii00(URL_II, JSONBodyStr);
sbn_grids_ii00(URL_II, JSONBodyStr);
{ok, {{_HttpVsn, 404, _Slogan}, _Hdrs, _JSONBodyStr}} ->
io:format("BUTTER YOUR OWN BISCUIT FATASS~n", []),
io:format("(404... probably faucet copypasta expired)~n", []);
@@ -252,7 +252,7 @@ rq_grids(URL) ->
io:format("ERROR: ~tp~n", [Error])
end.
rq_grids_ii00(URL_II, JSONBodyStr) ->
sbn_grids_ii00(URL_II, JSONBodyStr) ->
{ok, Decoded} = zj:decode(JSONBodyStr),
io:format("Decoded = ~tp~n", [Decoded]),
case Decoded of
@@ -262,11 +262,11 @@ rq_grids_ii00(URL_II, JSONBodyStr) ->
"payload" := PayloadStr,
"public_id" := false,
"signature" := undefined,
"type" := "message"} -> rq_grids_iii(URL_II, Decoded, PayloadStr);
"type" := "message"} -> sbn_grids_iii(URL_II, Decoded, PayloadStr);
_Nah -> error(nah_brah)
end.
rq_grids_iii(URL_II, Decoded, PayloadStr) ->
sbn_grids_iii(URL_II, Decoded, PayloadStr) ->
io:format("PayloadStr = ~tp~n", [PayloadStr]),
Sig = base64:encode(hz:sign_message(unicode:characters_to_binary(PayloadStr), my_secret_key())),
Recoded = Decoded#{"signature" => Sig,
@@ -278,67 +278,67 @@ rq_grids_iii(URL_II, Decoded, PayloadStr) ->
io:format("Shit = ~tp~n", [Shit]).
% ok.
rq_my(everything) ->
rq_my(akstr),
rq_my(rbx_tuples);
rq_my(acc) ->
sbn_my(everything) ->
sbn_my(akstr),
sbn_my(rbx_tuples);
sbn_my(acc) ->
Ak = my_akstr(),
rq_query([Ak]);
rq_my(balance) ->
sbn_query([Ak]);
sbn_my(balance) ->
Ak = my_akstr(),
{ok, #{"balance" := B}} = hz:acc(Ak),
io:format("Balance = ~tp~n", [B]),
io:format("log10(Balance) = ~tp~n", [math:log10(B)]);
rq_my(akstr) ->
sbn_my(akstr) ->
io:format("~ts~n", [my_akstr()]);
rq_my(url) ->
sbn_my(url) ->
io:format("https://groot.testnet.gajumaru.io/account/~ts~n", [my_akstr()]);
rq_my(rbx_tuples) ->
sbn_my(rbx_tuples) ->
io:format("~tp~n", [my_rbx_tuples()]).
rq_query([Ak = "ak_" ++ _ | Rest]) ->
sbn_query([Ak = "ak_" ++ _ | Rest]) ->
{ok, X} = hz:acc(Ak),
io:format("~tp~n", [X]),
rq_query(Rest);
rq_query([Ct = "ct_" ++ _ | Rest]) ->
sbn_query(Rest);
sbn_query([Ct = "ct_" ++ _ | Rest]) ->
{ok, X} = hz:contract(Ct),
io:format("~tp~n", [X]),
rq_query(Rest);
rq_query([ThStr = "th" ++ _ | Rest]) ->
sbn_query(Rest);
sbn_query([ThStr = "th" ++ _ | Rest]) ->
io:format("ThStr = ~tp~n", [ThStr]),
io:format("ExplorerUrl = ~ts~n", [explorer_url(ThStr)]),
{ok, TxInfo} = hz:tx_info(ThStr),
#{"call_info" := #{"return_value" := CbStr}} = TxInfo,
rq_decode(CbStr),
rq_query(Rest);
rq_query([]) ->
sbn_decode(CbStr),
sbn_query(Rest);
sbn_query([]) ->
ok.
explorer_url(ThStr = "th" ++ _) ->
"https://groot.testnet.gajumaru.io/tx/" ++ ThStr.
rq_src(["names.aes"]) ->
sbn_src(["names.aes"]) ->
{ok, Bytes} = file:read_file(nct_filepath()),
io:format("~s", [Bytes]);
rq_src(["rubicon.aes"]) ->
sbn_src(["rubicon.aes"]) ->
{ok, Bytes} = file:read_file(nct_filepath()),
io:format("~s", [Bytes]);
rq_src(FailArgs) ->
sbn_src(FailArgs) ->
badargs(FailArgs).
badargs(FailArgs) ->
io:format("you are a failure: ~p~n", [FailArgs]),
rq_help([]),
sbn_help([]),
error(badargs).
rq_help(_) ->
sbn_help(_) ->
io:format("~ts~n", [help_screen()]).
rq_debug(_) ->
sbn_debug(_) ->
ok = dbg_hz(),
ok = dbg_my(),
ok = dbg_nct(),
@@ -387,13 +387,13 @@ dbg_rct() ->
io:format(Format, Args).
rq_register(Name) ->
sbn_register(Name) ->
ct_call(nct_aaci(), nct_ctstr(), "register", [Name, ctstr(<<0:(32 * 8)>>)]).
rq_lookup(Name) ->
sbn_lookup(Name) ->
ct_call(nct_aaci(), nct_ctstr(), "lookup", [Name]).
ct_call(AACI, CtStr, FunName, ErlArgs) ->
@@ -402,7 +402,7 @@ ct_call(AACI, CtStr, FunName, ErlArgs) ->
{ok, PostResult} = hz:post_tx(SignedTx),
case PostResult of
#{"tx_hash" := ThStr} ->
rq_query([ThStr]);
sbn_query([ThStr]);
#{"error" := NodeErr} ->
io:format("ERROR: node sent back the following extremely helpful error message~n", []),
io:format("NodeErr = ~tp~n", [NodeErr]),
+3 -3
View File
@@ -1,11 +1,11 @@
{name,"rq"}.
{name,"sbn"}.
{type,cli}.
{modules,[]}.
{mod,"rq"}.
{mod,"sbn"}.
{author,"Peter Harpending"}.
{prefix,none}.
{desc,[]}.
{package_id,{"otpr","rq",{0,1,0}}}.
{package_id,{"otpr","sbn",{0,1,0}}}.
{deps,[{"otpr","base58",{0,1,1}},
{"otpr","eblake2",{1,0,1}},
{"otpr","gmserialization",{0,1,3}},