This commit is contained in:
2026-04-06 10:59:45 +09:00
parent 713650f88b
commit 9fa365e83f
8 changed files with 439 additions and 424 deletions
+15 -182
View File
@@ -14,14 +14,9 @@
handle_call/3, handle_cast/2, handle_info/2, handle_event/2]).
-include("$zx_include/zx_logger.hrl").
-include("gd.hrl").
-include("gdl.hrl").
% Widgets
-record(w,
{name = none :: atom() | {FunName :: binary(), call | dryr},
id = 0 :: integer(),
wx = none :: none | wx:wx_object()}).
% Contract functions in an ACI
-record(f,
{name = <<"">> :: binary(),
@@ -316,108 +311,16 @@ style(#s{code = {_, Pages}}, Win, Event) ->
tell("Received bogus style event.~nWin: ~p~nEvent: ~p", [Win, Event])
end.
clicked(State = #s{cons = {Consbook, Contracts}}, Name) ->
case wxNotebook:getSelection(Consbook) of
?wxNOT_FOUND ->
ok = tell(warning, "Inconcievable! No notebook page is selected!"),
State;
Index ->
#c{id = ConID, build = #{aaci := AACI}} = lists:nth(Index + 1, Contracts),
clicked2(State, Contract, Name)
end.
clicked2(State, Contract, Name) ->
case gd_con:list_keys() of
{ok, 0, []} ->
handle_troubling(State, "No keys exist in the current wallet.");
{ok, Selected, Keys} ->
clicked3(State, Contract, Name, Selected, Keys);
error ->
handle_troubling(State, "No wallet is selected!")
end.
clicked3(State = #s{frame = Frame, j = J}, Contract, FunDef, Selected, Keys) ->
#c{id = ConID, build = #{aaci := AACI}} = Contract,
ok = gd_con:make_call(FunDef, ConID, AACI),
State.
Dialog = wxDialog:new(Frame, ?wxID_ANY, Label),
Sizer = wxBoxSizer:new(?wxVERTICAL),
KeySz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("Signature Key")}]),
KeyPicker = wxChoice:new(Dialog, ?wxID_ANY, [{choices, Keys}]),
_ = wxStaticBoxSizer:add(KeySz, KeyPicker, zxw:flags(wide)),
ok = wxChoice:setSelection(KeyPicker, Selected - 1),
{ArgSz, ArgControls, Dimensions} = call_arg_sizer(Dialog, J, FunSpec),
{ParamSz, TTL_Tx, GasP_Tx, Gas_Tx, Amount_Tx} = call_param_sizer(Dialog, J),
ButtSz = wxBoxSizer:new(?wxHORIZONTAL),
Affirm = wxButton:new(Dialog, ?wxID_OK),
Cancel = wxButton:new(Dialog, ?wxID_CANCEL),
_ = wxBoxSizer:add(ButtSz, Affirm, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(ButtSz, Cancel, zxw:flags({wide, 5})),
_ = wxSizer:add(Sizer, KeySz, zxw:flags({base, 5})),
_ = wxSizer:add(Sizer, ArgSz, zxw:flags({wide, 5})),
_ = wxSizer:add(Sizer, ParamSz, zxw:flags({base, 5})),
_ = wxSizer:add(Sizer, ButtSz, zxw:flags({base, 5})),
ok = wxDialog:setSizer(Dialog, Sizer),
ok = wxBoxSizer:layout(Sizer),
ok = wxDialog:setSize(Dialog, Dimensions),
ok = wxDialog:center(Dialog),
Outcome =
case wxDialog:showModal(Dialog) of
?wxID_OK ->
ID = wxChoice:getString(KeyPicker, wxChoice:getSelection(KeyPicker)),
PK = unicode:characters_to_binary(ID),
Controls =
[{{"TTL", fun gt_0/1}, TTL_Tx},
{{"Gas Price", fun gt_0/1}, GasP_Tx},
{{"Gas", fun gt_0/1}, Gas_Tx},
{{"Amount", fun gte_0/1}, Amount_Tx}],
case call_params(Controls) of
{ok, [TTL, GasP, Gas, Amount]} ->
{Message, CArgs} = extract_args(ArgControls),
ok = gd_v_devman:write_console(ConID, Message),
{ok, Nonce} = hz:next_nonce(PK),
CallParams = {PK, Nonce, TTL, GasP, Gas, Amount},
{ok, CallParams, CArgs};
E ->
E
end;
?wxID_CANCEL ->
cancel
clicked(State = #s{cons = {Consbook, Contracts}}, FunDef) ->
ok =
case wxNotebook:getSelection(Consbook) of
?wxNOT_FOUND ->
tell(warning, "Inconcievable! No deployed contract page is selected!");
Index ->
#c{id = ConID, build = Build} = lists:nth(Index + 1, Contracts),
gd_con:prompt_call(FunDef, ConID, Build)
end,
ok = wxDialog:destroy(Dialog),
case Outcome of
{ok, Params, Args} -> clicked4(State, Contract, Name, Params, Args);
cancel -> State;
Error -> handle_troubling(State, Error)
end.
clicked4(State,
#c{id = ConID, build = #{aaci := AACI}},
{Name, Type},
{PK, Nonce, TTL, GasP, Gas, Amt},
Args) ->
case hz:contract_call(PK, Nonce, Gas, GasP, Amt, TTL, AACI, ConID, Name, Args) of
{ok, UnsignedTX} ->
case Type of
call -> do_call(State, ConID, PK, UnsignedTX);
dryr -> do_dry_run(State, ConID, UnsignedTX)
end;
Error ->
handle_troubling(State, Error),
State
end.
do_call(State, ConID, CallerID, UnsignedTX) ->
ok = gd_con:sign_call(ConID, CallerID, UnsignedTX),
State.
do_dry_run(State, ConID, TX) ->
ok = gd_con:dry_run(ConID, TX),
State.
@@ -562,82 +465,11 @@ deploy(State = #s{code = {Codebook, Pages}}) ->
end.
deploy2(State, Source) ->
case compile(Source) of
% TODO: Make hz accept either the aaci or the aci, preferring the aaci if present
{ok, Build} ->
{aaci, ContractName, Funs, _} = maps:get(aaci, Build),
ok = tell(info, "Deploying Contract: ~p", [ContractName]),
InitSpec = maps:get("init", Funs),
deploy3(State, InitSpec, Build);
Other ->
ok = tell(info, "Compilation Failed!~n~tp", [Other]),
State
end.
deploy3(State, InitSpec, Build) ->
case gd_con:list_keys() of
{ok, 0, []} ->
handle_troubling(State, "No keys exist in the current wallet.");
{ok, Selected, Keys} ->
deploy4(State, InitSpec, Build, Selected, Keys);
error ->
handle_troubling(State, "No wallet is selected!")
end.
deploy4(State = #s{frame = Frame, j = J}, InitSpec, Build, Selected, Keys) ->
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("Deploy Contract")),
Sizer = wxBoxSizer:new(?wxVERTICAL),
KeySz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("Signature Key")}]),
KeyPicker = wxChoice:new(Dialog, ?wxID_ANY, [{choices, Keys}]),
_ = wxStaticBoxSizer:add(KeySz, KeyPicker, zxw:flags(wide)),
ok = wxChoice:setSelection(KeyPicker, Selected - 1),
{ArgSz, ArgControls, Dimensions} = call_arg_sizer(Dialog, J, InitSpec),
{ParamSz, TTL_Tx, GasP_Tx, Gas_Tx, Amount_Tx} = call_param_sizer(Dialog, J),
ButtSz = wxBoxSizer:new(?wxHORIZONTAL),
Affirm = wxButton:new(Dialog, ?wxID_OK),
Cancel = wxButton:new(Dialog, ?wxID_CANCEL),
_ = wxBoxSizer:add(ButtSz, Affirm, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(ButtSz, Cancel, zxw:flags({wide, 5})),
_ = wxSizer:add(Sizer, KeySz, zxw:flags({base, 5})),
_ = wxSizer:add(Sizer, ArgSz, zxw:flags({wide, 5})),
_ = wxSizer:add(Sizer, ParamSz, zxw:flags({base, 5})),
_ = wxSizer:add(Sizer, ButtSz, zxw:flags({base, 5})),
ok = wxDialog:setSizer(Dialog, Sizer),
ok = wxBoxSizer:layout(Sizer),
ok = wxDialog:setSize(Dialog, Dimensions),
ok = wxDialog:center(Dialog),
Outcome =
case wxDialog:showModal(Dialog) of
?wxID_OK ->
ID = wxChoice:getString(KeyPicker, wxChoice:getSelection(KeyPicker)),
PK = unicode:characters_to_binary(ID),
Controls =
[{{"TTL", fun gt_0/1}, TTL_Tx},
{{"Gas Price", fun gt_0/1}, GasP_Tx},
{{"Gas", fun gt_0/1}, Gas_Tx},
{{"Amount", fun gte_0/1}, Amount_Tx}],
case call_params(Controls) of
{ok, [TTL, GasP, Gas, Amount]} ->
{Message, CArgs} = extract_args(ArgControls),
ok = tell(Message),
{ok, Nonce} = hz:next_nonce(PK),
DeployParams = {PK, Nonce, TTL, GasP, Gas, Amount},
{ok, DeployParams, CArgs};
E ->
E
end;
?wxID_CANCEL ->
cancel
ok =
case compile(Source) of
{ok, Build} -> gd_con:prompt_call({"init", init}, init, Build);
Other -> tell(info, "Compilation Failed!~n~tp", [Other])
end,
ok = wxDialog:destroy(Dialog),
case Outcome of
{ok, Params, Args} -> deploy5(State, Build, Params, Args);
cancel -> State;
Error -> handle_troubling(State, Error)
end.
deploy5(State, Build, Params, Args) ->
ok = gd_con:deploy(Build, Params, Args),
State.
@@ -669,7 +501,8 @@ open(State = #s{frame = Frame, j = J}) ->
1 -> hash;
?wxNOT_FOUND -> none
end;
?wxID_CANCEL -> cancel
?wxID_CANCEL ->
cancel
end,
ok = wxDialog:destroy(Dialog),
case Choice of