alright progress, need to get to bytecode decoding

This commit is contained in:
2026-10-06 13:57:09 -07:00
parent 88a1e7f420
commit b3de45e162
+146 -21
View File
@@ -7,6 +7,8 @@
-export([start/1]).
-compile([export_all,nowarn_export_all]).
% TODO: rename "decode" to either "decompose", "compost" or "debug"
% deploy opts
-record(rdo,
{deploy_file = "rq.deploy" :: file:filename(),
@@ -42,8 +44,12 @@ help_screen() ->
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 show ContractCreateTx
rq deploy --signed show SignedTx
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
@@ -94,7 +100,11 @@ rq_II(Args) ->
["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);
@@ -167,21 +177,7 @@ rq_decode(TxStr = "tx_" ++ _) ->
rq_decode(TxBin = <<"tx_", _/binary>>) ->
io:format("TxBin = ~tp~n", [TxBin]),
{transaction, Bytes} = gmser_api_encoder:decode(TxBin),
io:format("Bytes = ~tp~n", [Bytes]),
RLP = gmser_rlp:decode(Bytes),
io:format("RLP = ~tp~n", [RLP]),
[TagBin, VsnBin | RLP_II] = RLP,
Tag = binary:decode_unsigned(TagBin),
Gat = rev_tag(Tag),
Vsn = binary:decode_unsigned(VsnBin),
io:format("Tag = ~tp~n", [Tag]),
io:format("Gat = ~tp~n", [Gat]),
io:format("Vsn = ~tp~n", [Vsn]),
Tpl = template(Gat, Vsn),
io:format("Template = ~tp~n", [Tpl]),
Deser = gmser_chain_objects:deserialize(Gat, Vsn, Tpl, Bytes),
io:format("Deserialized = ~tp~n", [Deser]),
%Fmt = gmb_fate_data:format(Deser),
just_the_tip_decode(Bytes),
ok;
rq_decode(CbStr = "cb_" ++ _) ->
rq_decode(unicode:characters_to_binary(CbStr));
@@ -196,6 +192,53 @@ rq_decode(CbBin = <<"cb_", _/binary>>) ->
ok.
% this is like rq_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
just_the_tip_decode(Bytes) ->
io:format("Bytes = ~tp~n", [Bytes]),
RLP = gmser_rlp:decode(Bytes),
io:format("RLP = ~tp~n", [RLP]),
[TagBin, VsnBin | Fields] = RLP,
Tag = binary:decode_unsigned(TagBin),
RevTag = rev_tag(Tag),
Vsn = binary:decode_unsigned(VsnBin),
io:format("Tag = ~tp~n", [Tag]),
io:format("RevTag = ~tp~n", [RevTag]),
io:format("Vsn = ~tp~n", [Vsn]),
io:format("Fields = ~tp~n", [Fields]),
Tpl = template(RevTag, Vsn),
io:format("Template = ~tp~n", [Tpl]),
NFields = gmser_chain_objects:deserialize(RevTag, Vsn, Tpl, Bytes),
io:format("NamedFields = ~tp~n", [NFields]),
deep_decode(RevTag, Vsn, Fields).
deep_decode(signed_tx, 1, [Sigs, Tx]) ->
[sig_valid(my_pubkey32(), Sig, Tx) || Sig <- Sigs],
just_the_tip_decode(Tx),
ok;
deep_decode(contract_create_tx, 1, _) ->
error(nyi);
deep_decode(_, _, _) ->
error(nyi).
sig_valid(Pk32, Sig, Tx) ->
io:format("Pk32 = ~tp~n", [Pk32]),
io:format("Sig = ~tp~n", [Sig]),
io:format("Tx = ~tp~n", [Tx]),
NetworkId = <<"groot.testnet">>,
{ok, Hash} = eblake2:blake2b(32, Tx),
Signatee = <<NetworkId/binary, Hash/binary>>,
io:format("NetworkId = ~tp~n", [NetworkId]),
io:format("Hash = ~tp~n", [Hash]),
io:format("Signatee = ~tp~n", [Signatee]),
SigValid = ecu_eddsa:sign_verify_detached(Sig, Signatee, Pk32),
io:format("SigValid = ~tp~n", [SigValid]),
ok.
% hacky to get fund via faucet to work
rq_grids(URL) ->
{ok, {{sign, https}, URL_II}} = hz_grids:parse(URL),
@@ -219,10 +262,8 @@ rq_grids_ii00(URL_II, JSONBodyStr) ->
"payload" := PayloadStr,
"public_id" := false,
"signature" := undefined,
"type" := "message"} ->
rq_grids_iii(URL_II, Decoded, PayloadStr);
_Nah ->
error(nah_brah)
"type" := "message"} -> rq_grids_iii(URL_II, Decoded, PayloadStr);
_Nah -> error(nah_brah)
end.
rq_grids_iii(URL_II, Decoded, PayloadStr) ->
@@ -550,6 +591,90 @@ rev_tag(142) -> entry_transfer_tx;
rev_tag(143) -> entry_destroy_tx;
rev_tag(200) -> pof.
tag(account) -> 10;
tag(signed_tx) -> 11;
tag(spend_tx) -> 12;
tag(data_extend_tx) -> 13;
tag(name) -> 30;
tag(name_commitment) -> 31;
tag(name_claim_tx) -> 32;
tag(name_preclaim_tx) -> 33;
tag(name_update_tx) -> 34;
tag(name_revoke_tx) -> 35;
tag(name_transfer_tx) -> 36;
tag(name_auction) -> 37;
tag(contract) -> 40;
tag(contract_call) -> 41;
tag(contract_create_tx) -> 42;
tag(contract_call_tx) -> 43;
tag(contract_source) -> 44;
tag(channel_create_tx) -> 50;
tag(channel_set_delegates_tx) -> 501;
tag(channel_delegates) -> 502;
tag(channel_deposit_tx) -> 51;
tag(channel_withdraw_tx) -> 52;
tag(channel_force_progress_tx) -> 521;
tag(channel_close_mutual_tx) -> 53;
tag(channel_close_solo_tx) -> 54;
tag(channel_slash_tx) -> 55;
tag(channel_settle_tx) -> 56;
tag(channel_offchain_tx) -> 57;
tag(channel_offchain_update_transfer) -> 570;
tag(channel_offchain_update_deposit) -> 571;
tag(channel_offchain_update_withdraw) -> 572;
tag(channel_offchain_update_create_contract) -> 573;
tag(channel_offchain_update_call_contract) -> 574;
tag(channel_offchain_update_meta) -> 576;
tag(channel_client_reconnect_tx) -> 575;
tag(channel) -> 58;
tag(channel_snapshot_solo_tx) -> 59;
tag(trees_poi) -> 60;
tag(trees_db) -> 61;
tag(state_trees) -> 62;
tag(mtree) -> 63;
tag(mtree_value) -> 64;
tag(contracts_mtree) -> 621;
tag(calls_mtree) -> 622;
tag(channels_mtree) -> 623;
tag(nameservice_mtree) -> 624;
tag(accounts_mtree) -> 626;
tag(acs_mtree) -> 627;
tag(entries_mtree) -> 628;
tag(compiler_sophia) -> 70;
tag(ga_attach_tx) -> 80;
tag(ga_meta_tx) -> 81;
tag(paying_for_tx) -> 82;
tag(ga_meta_tx_auth_data) -> 810;
tag(associate_chain) -> 90;
tag(ac_state) -> 91;
tag(ac_burn) -> 92;
tag(ac_create_tx) -> 93;
tag(ac_deposit_tx) -> 94;
tag(ac_update_cops_tx) -> 95;
tag(ac_rollup_tx) -> 96;
tag(ac_proposal_tx) -> 97;
tag(key_block) -> 100;
tag(micro_block) -> 101;
tag(light_micro_block) -> 102;
tag(testimony) -> 110;
tag(testimony_tx) -> 111;
tag(nt_native_token) -> 120;
tag(nt_create_tx) -> 121;
tag(nt_mint_tx) -> 122;
tag(nt_finalize_tx) -> 123;
tag(nt_trade_tx) -> 124;
tag(nt_burn_tx) -> 125;
tag(entry) -> 140;
tag(entry_create_tx) -> 141;
tag(entry_transfer_tx) -> 142;
tag(entry_destroy_tx) -> 143;
tag(pof) -> 200.
template(signed_tx, 1) ->
[{sigs, [binary]},
{tx, binary}];
template(contract_create_tx, 1) ->
[{owner_id, id},
{nonce, int},