WIP: De-kajiggering
This commit is contained in:
+40
-28
@@ -96,18 +96,21 @@ init({Prefs, FunDef = {FunName, FunType}, ConID, Build, Selected, Keys}) ->
|
||||
ok = wxChoice:setSelection(KeyPicker, ZeroBasedSelected),
|
||||
_ = wxStaticBoxSizer:add(KeySz, KeyPicker, zxw:flags(wide)),
|
||||
|
||||
{ArgSz, Args, Dimensions} = call_arg_sizer(Frame, J, FunSpec),
|
||||
{ArgSz, Args, HasArgs} = call_arg_sizer(Frame, J, FunSpec),
|
||||
{ParamSz, Params} = call_param_sizer(Frame, J),
|
||||
|
||||
Action = #w{wx = ActionBn} = gd_lib:button(Frame, ActionLabel),
|
||||
|
||||
TX_Sz = wxStaticBoxSizer:new(?wxVERTICAL, Frame, [{label, J("Transaction Info")}]),
|
||||
TX_Sz_Box = wxStaticBoxSizer:getStaticBox(TX_Sz),
|
||||
TX_Data = #w{wx = DataT} = gd_lib:mono_text(TX_Sz_Box, tx_hash),
|
||||
TX_Hash = #w{wx = HashT} = gd_lib:mono_text(TX_Sz_Box, tx_hash),
|
||||
TX_Info = #w{wx = InfoT} = gd_lib:mono_text(TX_Sz_Box, tx_hash),
|
||||
TxStyle = [{style, ?wxTE_READONLY}],
|
||||
TX_Data = #w{wx = DataT} = gd_lib:mono_text(TX_Sz_Box, tx_data, "", TxStyle),
|
||||
TX_Hash = #w{wx = HashT} = gd_lib:mono_text(TX_Sz_Box, tx_hash, "", TxStyle),
|
||||
TX_Info = #w{wx = InfoT} = gd_lib:mono_text(TX_Sz_Box, tx_info, "", TxStyle),
|
||||
|
||||
Line = wxStaticLine:new(TX_Sz_Box, [{style, ?wxLI_HORIZONTAL}]),
|
||||
Out = #w{wx = OutTxt} = gd_lib:mono_text(TX_Sz_Box, out),
|
||||
OutStyle = [{style, ?wxTE_MULTILINE bor ?wxTE_READONLY}],
|
||||
Out = #w{wx = OutTxt} = gd_lib:mono_text(TX_Sz_Box, out, "", OutStyle),
|
||||
Copy = #w{wx = CopyBn} = gd_lib:button(TX_Sz_Box, J("Copy")),
|
||||
|
||||
_ = wxStaticBoxSizer:add(TX_Sz, DataT, zxw:flags({base, 5})),
|
||||
@@ -117,14 +120,19 @@ init({Prefs, FunDef = {FunName, FunType}, ConID, Build, Selected, Keys}) ->
|
||||
_ = wxStaticBoxSizer:add(TX_Sz, OutTxt, zxw:flags({wide, 5})),
|
||||
_ = wxStaticBoxSizer:add(TX_Sz, CopyBn, zxw:flags({base, 5})),
|
||||
|
||||
_ = wxSizer:add(MainSz, ArgSz, zxw:flags({wide, 5})),
|
||||
ArgSzArgs =
|
||||
case HasArgs of
|
||||
true -> {wide, 5};
|
||||
false -> {base, 5}
|
||||
end,
|
||||
_ = wxSizer:add(MainSz, ArgSz, zxw:flags(ArgSzArgs)),
|
||||
_ = wxSizer:add(MainSz, KeySz, zxw:flags({base, 5})),
|
||||
_ = wxSizer:add(MainSz, ParamSz, zxw:flags({base, 5})),
|
||||
_ = wxSizer:add(MainSz, ActionBn, zxw:flags({base, 5})),
|
||||
_ = wxSizer:add(MainSz, TX_Sz, zxw:flags({base, 5})),
|
||||
_ = wxSizer:add(MainSz, TX_Sz, zxw:flags({wide, 5})),
|
||||
|
||||
_ = wxFrame:setSizer(Frame, MainSz),
|
||||
_ = wxFrame:setSize(Frame, Dimensions),
|
||||
_ = wxFrame:setSize(Frame, {900, 900}),
|
||||
_ = wxSizer:layout(MainSz),
|
||||
ok = wxFrame:connect(Frame, close_window),
|
||||
ok = wxFrame:connect(Frame, command_button_clicked),
|
||||
@@ -141,17 +149,17 @@ init({Prefs, FunDef = {FunName, FunType}, ConID, Build, Selected, Keys}) ->
|
||||
|
||||
call_arg_sizer(Frame, J, {CallArgs, ReturnType}) ->
|
||||
SpecSz = wxStaticBoxSizer:new(?wxVERTICAL, Frame, [{label, J("Function Spec")}]),
|
||||
{CallSz, CallControls, Dimensions} = call_sizer(Frame, J, CallArgs),
|
||||
{CallSz, CallControls, HasArgs} = call_sizer(Frame, J, CallArgs),
|
||||
ReturnSz = return_sizer(Frame, J, ReturnType),
|
||||
_ = wxStaticBoxSizer:add(SpecSz, CallSz, zxw:flags({wide, 5})),
|
||||
_ = wxStaticBoxSizer:add(SpecSz, ReturnSz, zxw:flags({base, 5})),
|
||||
{SpecSz, CallControls, Dimensions}.
|
||||
{SpecSz, CallControls, HasArgs}.
|
||||
|
||||
call_sizer(Frame, J, []) ->
|
||||
CallSz = wxStaticBoxSizer:new(?wxVERTICAL, Frame, [{label, J("Call Args")}]),
|
||||
Args = wxStaticText:new(Frame, ?wxID_ANY, ["[", J("No Args"), "]"]),
|
||||
_ = wxStaticBoxSizer:add(CallSz, Args, zxw:flags({wide, 5})),
|
||||
{CallSz, [], {500, 700}};
|
||||
{CallSz, [], false};
|
||||
call_sizer(Frame, J, CallArgs) ->
|
||||
ScrollWin = wxScrolledWindow:new(Frame),
|
||||
ScrollSz = wxBoxSizer:new(?wxVERTICAL),
|
||||
@@ -172,7 +180,7 @@ call_sizer(Frame, J, CallArgs) ->
|
||||
#w{name = Name, id = wxTextCtrl:getId(C), wx = C}
|
||||
end,
|
||||
Controls = lists:map(AddArg, CallArgs),
|
||||
{CallSz, Controls, {500, 900}}.
|
||||
{CallSz, Controls, true}.
|
||||
|
||||
return_sizer(Frame, J, ReturnType) ->
|
||||
ReturnSz = wxStaticBoxSizer:new(?wxVERTICAL, Frame, [{label, J("Return Type")}]),
|
||||
@@ -195,28 +203,28 @@ call_param_sizer(Frame, J) ->
|
||||
TTL_L = wxStaticText:new(Frame, ?wxID_ANY, "TTL"),
|
||||
TTL_T = wxTextCtrl:new(Frame, ?wxID_ANY),
|
||||
ok = wxTextCtrl:setValue(TTL_T, integer_to_list(DefTTL)),
|
||||
GasP_L = wxStaticText:new(Frame, ?wxID_ANY, J("Gas Price")),
|
||||
GasP_T = wxTextCtrl:new(Frame, ?wxID_ANY),
|
||||
ok = wxTextCtrl:setValue(GasP_T, integer_to_list(DefGasP)),
|
||||
Gas_L = wxStaticText:new(Frame, ?wxID_ANY, J("Gas")),
|
||||
Gas_T = wxTextCtrl:new(Frame, ?wxID_ANY),
|
||||
ok = wxTextCtrl:setValue(Gas_T, integer_to_list(DefGas)),
|
||||
GasP_L = wxStaticText:new(Frame, ?wxID_ANY, J("Gas Price")),
|
||||
GasP_T = wxTextCtrl:new(Frame, ?wxID_ANY),
|
||||
ok = wxTextCtrl:setValue(GasP_T, integer_to_list(DefGasP)),
|
||||
Amount_L = wxStaticText:new(Frame, ?wxID_ANY, J("TX Amount")),
|
||||
Amount_T = wxTextCtrl:new(Frame, ?wxID_ANY),
|
||||
ok = wxTextCtrl:setValue(Amount_T, integer_to_list(DefAmount)),
|
||||
_ = wxFlexGridSizer:add(GridSz, TTL_L, zxw:flags({base, 5})),
|
||||
_ = wxFlexGridSizer:add(GridSz, TTL_T, zxw:flags({wide, 5})),
|
||||
_ = wxFlexGridSizer:add(GridSz, GasP_L, zxw:flags({base, 5})),
|
||||
_ = wxFlexGridSizer:add(GridSz, GasP_T, zxw:flags({wide, 5})),
|
||||
_ = wxFlexGridSizer:add(GridSz, Gas_L, zxw:flags({base, 5})),
|
||||
_ = wxFlexGridSizer:add(GridSz, Gas_T, zxw:flags({wide, 5})),
|
||||
_ = wxFlexGridSizer:add(GridSz, GasP_L, zxw:flags({base, 5})),
|
||||
_ = wxFlexGridSizer:add(GridSz, GasP_T, zxw:flags({wide, 5})),
|
||||
_ = wxFlexGridSizer:add(GridSz, Amount_L, zxw:flags({base, 5})),
|
||||
_ = wxFlexGridSizer:add(GridSz, Amount_T, zxw:flags({wide, 5})),
|
||||
_ = wxSizer:add(ParamSz, GridSz, zxw:flags(wide)),
|
||||
Params =
|
||||
[{ "TTL", fun gte_0/1, TTL_T},
|
||||
{J("Gas Price"), fun gt_0/1, GasP_T},
|
||||
{J("Gas") , fun gt_0/1, Gas_T},
|
||||
{J("Gas Price"), fun gt_0/1, GasP_T},
|
||||
{J("TX Amount"), fun gte_0/1, Amount_T}],
|
||||
{ParamSz, Params}.
|
||||
|
||||
@@ -289,13 +297,13 @@ engage3(State, ChainID, Params) ->
|
||||
|
||||
engage4(State = #s{fundef = {"init", init}, build = Build}, ChainID, Params, Args) ->
|
||||
tell(info, "Args: ~p", [Args]),
|
||||
{CallerID, Nonce, TTL, GP, Gas, Amount} = Params,
|
||||
case hz:contract_create_built(CallerID, Nonce, Gas, GP, Amount, TTL, Build, Args) of
|
||||
{CallerID, Nonce, TTL, Gas, GP, Amount} = Params,
|
||||
case hz:contract_create_built(CallerID, Nonce, Amount, TTL, Gas, GP, Build, Args) of
|
||||
{ok, CreateTX} -> deploy(State, ChainID, CallerID, CreateTX);
|
||||
Error -> handle_troubling(State, Error)
|
||||
end;
|
||||
engage4(State = #s{fundef = {Name, Type}, con_id = ConID, build = Build}, ChainID, Params, Args) ->
|
||||
{CallerID, Nonce, TTL, GP, Gas, Amount} = Params,
|
||||
{CallerID, Nonce, TTL, Gas, GP, Amount} = Params,
|
||||
AACI = maps:get(aaci, Build),
|
||||
case hz:contract_call(CallerID, Nonce, Gas, GP, Amount, TTL, AACI, ConID, Name, Args) of
|
||||
{ok, UnsignedTX} ->
|
||||
@@ -317,7 +325,7 @@ params(State = #s{kp = #w{wx = KeyPicker}}) ->
|
||||
|
||||
params2(#s{params = Params}, PK, Nonce) ->
|
||||
case lists:foldl(fun extract/2, {ok, []}, Params) of
|
||||
{ok, [TTL, GP, Gas, Amount]} -> {ok, {PK, Nonce, TTL, GP, Gas, Amount}};
|
||||
{ok, [Amount, GP, Gas, TTL]} -> {ok, {PK, Nonce, TTL, Gas, GP, Amount}};
|
||||
Error -> Error
|
||||
end.
|
||||
|
||||
@@ -344,9 +352,13 @@ deploy(State, ChainID, CallerID, CreateTX) ->
|
||||
|
||||
deploy2(State, SignedTX) ->
|
||||
case hz:post_tx(SignedTX) of
|
||||
{ok, Data} -> check_tx(State#s{tx_data = Data});
|
||||
% {ok, WTF} -> handle_troubling(State, {error, WTF});
|
||||
Error -> handle_troubling(State, Error)
|
||||
{ok, Data} ->
|
||||
case maps:is_key("reason", Data) of
|
||||
false -> check_tx(State#s{tx_data = Data});
|
||||
true -> handle_troubling(State, {error, Data})
|
||||
end;
|
||||
Error ->
|
||||
handle_troubling(State, Error)
|
||||
end.
|
||||
|
||||
|
||||
@@ -358,7 +370,7 @@ do_call(State, ChainID, CallerID, UnsignedTX) ->
|
||||
|
||||
do_call2(State, SignedTX) ->
|
||||
case hz:post_tx(SignedTX) of
|
||||
{ok, Data} -> check_tx(State = #s{tx_data = Data});
|
||||
{ok, Data} -> check_tx(State#s{tx_data = Data});
|
||||
Error -> handle_troubling(State, Error)
|
||||
end.
|
||||
|
||||
@@ -391,14 +403,14 @@ check_tx(State = #s{tx_data = TXData}) ->
|
||||
|
||||
update_info(State = #s{tx_info = TXInfo, out = #w{wx = Out}}) ->
|
||||
Formatted = io_lib:format("TXInfo: ~p~n", [TXInfo]),
|
||||
ok = wxStaticText:setLabel(Out, Formatted),
|
||||
ok = wxTextCtrl:setValue(Out, Formatted),
|
||||
State.
|
||||
|
||||
|
||||
copy(#s{tx_info = none}) ->
|
||||
ok;
|
||||
copy(#s{out = #w{wx = Out}}) ->
|
||||
Output = wxStaticText:getLabel(Out),
|
||||
Output = wxTextCtrl:getValue(Out),
|
||||
gd_lib:copy_to_clipboard(Output).
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user