stuff
This commit is contained in:
+184
-15
@@ -7,6 +7,11 @@
|
||||
-export([start/1]).
|
||||
-compile([export_all,nowarn_export_all]).
|
||||
|
||||
% deploy opts
|
||||
-record(rdo,
|
||||
{deploy_file = "rq.deploy" :: file:filename(),
|
||||
op = deploy :: deploy | tx | signed_tx}).
|
||||
|
||||
-spec start(ArgV) -> ok
|
||||
when ArgV :: [string()].
|
||||
|
||||
@@ -34,7 +39,11 @@ help_screen() ->
|
||||
rq addr names.aes
|
||||
rq ctstr names
|
||||
rq ctstr names.aes deployed address of names
|
||||
rq decode xy_... only on the ones i use
|
||||
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 grids URL only works with the faucet grids
|
||||
rq my
|
||||
rq my everything all
|
||||
@@ -83,6 +92,9 @@ rq_II(Args) ->
|
||||
["debug" | Rest] ->
|
||||
rq_debug(Rest);
|
||||
["decode", ApiStr] -> rq_decode(ApiStr);
|
||||
["deploy"] -> rq_deploy(#rdo{});
|
||||
["deploy", "--signed"] -> rq_deploy(#rdo{op = signed_tx});
|
||||
["deploy", "--tx"] -> rq_deploy(#rdo{op = tx});
|
||||
["grids", URL] -> rq_grids(URL);
|
||||
["my"] -> rq_my(everything);
|
||||
["my", "everything"] -> rq_my(everything);
|
||||
@@ -106,8 +118,74 @@ rq_II(Args) ->
|
||||
end.
|
||||
|
||||
|
||||
|
||||
rq_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)
|
||||
end.
|
||||
|
||||
rq_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);
|
||||
signed_tx ->
|
||||
Signed = hz:sign_tx(CreateTx, my_secret_key()),
|
||||
rq_decode(Signed);
|
||||
NYI ->
|
||||
io:format("NYI: ~tp~n", [NYI]),
|
||||
error(ur_mom_is_an_op)
|
||||
end.
|
||||
|
||||
|
||||
|
||||
sign_and_post(UnsignedTx) ->
|
||||
SignedTx = hz:sign_tx(UnsignedTx, my_secret_key()),
|
||||
{ok, PostResult} = hz:post_tx(SignedTx),
|
||||
case PostResult of
|
||||
#{"tx_hash" := ThStr} ->
|
||||
rq_query([ThStr]);
|
||||
#{"reason" := NodeErr} ->
|
||||
io:format("ERROR: node sent back the following extremely helpful error message~n", []),
|
||||
io:format("~tp~n", [NodeErr]),
|
||||
error(NodeErr);
|
||||
_ ->
|
||||
io:format("ERROR (nyi) node sent back voodoo:~n", []),
|
||||
io:format("PostResult = ~tp~n", [PostResult]),
|
||||
error(nyi)
|
||||
end.
|
||||
|
||||
|
||||
rq_decode(TxStr = "tx_" ++ _) ->
|
||||
rq_decode(unicode:characters_to_binary(TxStr));
|
||||
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),
|
||||
ok;
|
||||
rq_decode(CbStr = "cb_" ++ _) ->
|
||||
CbBin = unicode:characters_to_binary(CbStr),
|
||||
rq_decode(unicode:characters_to_binary(CbStr));
|
||||
rq_decode(CbBin = <<"cb_", _/binary>>) ->
|
||||
io:format("CbBin = ~tp~n", [CbBin]),
|
||||
{contract_bytearray, Bytes} = gmser_api_encoder:decode(CbBin),
|
||||
io:format("Bytes = ~tp~n", [Bytes]),
|
||||
@@ -182,15 +260,16 @@ rq_query([Ak = "ak_" ++ _ | Rest]) ->
|
||||
{ok, X} = hz:acc(Ak),
|
||||
io:format("~tp~n", [X]),
|
||||
rq_query(Rest);
|
||||
rq_query([Cb = "cb_" ++ _ | Rest]) ->
|
||||
rq_decode(Cb),
|
||||
rq_query(Rest);
|
||||
rq_query([Ct = "ct_" ++ _ | Rest]) ->
|
||||
{ok, X} = hz:contract(Ct),
|
||||
io:format("~tp~n", [X]),
|
||||
rq_query(Rest);
|
||||
rq_query([Th = "th" ++ _ | Rest]) ->
|
||||
await_thstr(Th),
|
||||
rq_query([ThStr = "th" ++ _ | Rest]) ->
|
||||
io:format("ThStr = ~tp~n", [ThStr]),
|
||||
io:format("ExplorerUrl = ~tp~n", ["null"]),
|
||||
{ok, TxInfo} = hz:tx_info(ThStr),
|
||||
#{"call_info" := #{"return_value" := CbStr}} = TxInfo,
|
||||
rq_decode(CbStr),
|
||||
rq_query(Rest);
|
||||
rq_query([]) ->
|
||||
ok.
|
||||
@@ -277,7 +356,7 @@ ct_call(AACI, CtStr, FunName, ErlArgs) ->
|
||||
{ok, PostResult} = hz:post_tx(SignedTx),
|
||||
case PostResult of
|
||||
#{"tx_hash" := ThStr} ->
|
||||
await_thstr(ThStr);
|
||||
rq_query(ThStr);
|
||||
#{"error" := NodeErr} ->
|
||||
io:format("ERROR: node sent back the following extremely helpful error message~n", []),
|
||||
io:format("NodeErr = ~tp~n", [NodeErr]),
|
||||
@@ -288,12 +367,6 @@ ct_call(AACI, CtStr, FunName, ErlArgs) ->
|
||||
error(nyi)
|
||||
end.
|
||||
|
||||
await_thstr(ThStr) ->
|
||||
{ok, Tx} = hz:tx(ThStr),
|
||||
{ok, TxInfo} = hz:tx_info(ThStr),
|
||||
io:format("Tx = ~tp~n", [Tx]),
|
||||
io:format("TxInfo = ~tp~n", [TxInfo]),
|
||||
ok.
|
||||
|
||||
|
||||
%% name contract deployed address
|
||||
@@ -349,8 +422,9 @@ my_rbx_tuples() ->
|
||||
81, 110, 137, 163, 44, 76, 48, 130, 225, 95,
|
||||
168, 121, 93, 44, 148, 42, 180, 103, 11, 40,
|
||||
168, 96>>,
|
||||
ServiceAkStr = gmser_api_encoder:encode(account_pubkey, ServicePubkey),
|
||||
NoisePrologue = <<>>,
|
||||
[{"127.0.0.1", 6969, "tcp", NoiseStr, ServicePubkey, NoisePrologue}].
|
||||
[{"127.0.0.1", 6969, "tcp", NoiseStr, ServiceAkStr, NoisePrologue}].
|
||||
|
||||
|
||||
%% hz setup
|
||||
@@ -395,3 +469,98 @@ deploy_rct_III(SignedCreateTx) ->
|
||||
io:format("you are a failure III: ~tp~n", [Error]),
|
||||
error(Error)
|
||||
end.
|
||||
|
||||
%% totally not copypasted from gmser_chain_objects.erl
|
||||
rev_tag(10) -> account;
|
||||
rev_tag(11) -> signed_tx;
|
||||
rev_tag(12) -> spend_tx;
|
||||
rev_tag(13) -> data_extend_tx;
|
||||
rev_tag(30) -> name;
|
||||
rev_tag(31) -> name_commitment;
|
||||
rev_tag(32) -> name_claim_tx;
|
||||
rev_tag(33) -> name_preclaim_tx;
|
||||
rev_tag(34) -> name_update_tx;
|
||||
rev_tag(35) -> name_revoke_tx;
|
||||
rev_tag(36) -> name_transfer_tx;
|
||||
rev_tag(37) -> name_auction;
|
||||
rev_tag(40) -> contract;
|
||||
rev_tag(41) -> contract_call;
|
||||
rev_tag(42) -> contract_create_tx;
|
||||
rev_tag(43) -> contract_call_tx;
|
||||
rev_tag(44) -> contract_source;
|
||||
rev_tag(50) -> channel_create_tx;
|
||||
rev_tag(501) -> channel_set_delegates_tx;
|
||||
rev_tag(502) -> channel_delegates;
|
||||
rev_tag(51) -> channel_deposit_tx;
|
||||
rev_tag(52) -> channel_withdraw_tx;
|
||||
rev_tag(521) -> channel_force_progress_tx;
|
||||
rev_tag(53) -> channel_close_mutual_tx;
|
||||
rev_tag(54) -> channel_close_solo_tx;
|
||||
rev_tag(55) -> channel_slash_tx;
|
||||
rev_tag(56) -> channel_settle_tx;
|
||||
rev_tag(57) -> channel_offchain_tx;
|
||||
rev_tag(570) -> channel_offchain_update_transfer;
|
||||
rev_tag(571) -> channel_offchain_update_deposit;
|
||||
rev_tag(572) -> channel_offchain_update_withdraw;
|
||||
rev_tag(573) -> channel_offchain_update_create_contract;
|
||||
rev_tag(574) -> channel_offchain_update_call_contract;
|
||||
rev_tag(576) -> channel_offchain_update_meta;
|
||||
rev_tag(575) -> channel_client_reconnect_tx;
|
||||
rev_tag(58) -> channel;
|
||||
rev_tag(59) -> channel_snapshot_solo_tx;
|
||||
rev_tag(60) -> trees_poi;
|
||||
rev_tag(61) -> trees_db;
|
||||
rev_tag(62) -> state_trees;
|
||||
rev_tag(63) -> mtree;
|
||||
rev_tag(64) -> mtree_value;
|
||||
rev_tag(621) -> contracts_mtree;
|
||||
rev_tag(622) -> calls_mtree;
|
||||
rev_tag(623) -> channels_mtree;
|
||||
rev_tag(624) -> nameservice_mtree;
|
||||
rev_tag(626) -> accounts_mtree;
|
||||
rev_tag(627) -> acs_mtree;
|
||||
rev_tag(628) -> entries_mtree;
|
||||
rev_tag(70) -> compiler_sophia;
|
||||
rev_tag(80) -> ga_attach_tx;
|
||||
rev_tag(81) -> ga_meta_tx;
|
||||
rev_tag(82) -> paying_for_tx;
|
||||
rev_tag(810) -> ga_meta_tx_auth_data;
|
||||
rev_tag(90) -> associate_chain;
|
||||
rev_tag(91) -> ac_state;
|
||||
rev_tag(92) -> ac_burn;
|
||||
rev_tag(93) -> ac_create_tx;
|
||||
rev_tag(94) -> ac_deposit_tx;
|
||||
rev_tag(95) -> ac_update_cops_tx;
|
||||
rev_tag(96) -> ac_rollup_tx;
|
||||
rev_tag(97) -> ac_proposal_tx;
|
||||
rev_tag(100) -> key_block;
|
||||
rev_tag(101) -> micro_block;
|
||||
rev_tag(102) -> light_micro_block;
|
||||
rev_tag(110) -> testimony;
|
||||
rev_tag(111) -> testimony_tx;
|
||||
rev_tag(120) -> nt_native_token;
|
||||
rev_tag(121) -> nt_create_tx;
|
||||
rev_tag(122) -> nt_mint_tx;
|
||||
rev_tag(123) -> nt_finalize_tx;
|
||||
rev_tag(124) -> nt_trade_tx;
|
||||
rev_tag(125) -> nt_burn_tx;
|
||||
rev_tag(140) -> entry;
|
||||
rev_tag(141) -> entry_create_tx;
|
||||
rev_tag(142) -> entry_transfer_tx;
|
||||
rev_tag(143) -> entry_destroy_tx;
|
||||
rev_tag(200) -> pof.
|
||||
|
||||
template(contract_create_tx, 1) ->
|
||||
[{owner_id, id},
|
||||
{nonce, int},
|
||||
{code, binary},
|
||||
{source, binary},
|
||||
{ct_version, int},
|
||||
{ttl, int},
|
||||
{deposit, int},
|
||||
{amount, int},
|
||||
{gas_price, int},
|
||||
{gas, int},
|
||||
{call_data, binary}];
|
||||
template(_, _) ->
|
||||
error(nyi).
|
||||
|
||||
Reference in New Issue
Block a user