Make Contract Calls Great Again #35

Merged
zxq9 merged 37 commits from iface3 into master 2026-05-10 15:39:25 +09:00
4 changed files with 24 additions and 17 deletions
Showing only changes of commit d1ee4c6a24 - Show all commits
+1 -1
View File
@@ -1,5 +1,5 @@
% Widgets
-record(w,
{name = none :: atom() | {FunName :: binary(), call | dryr},
{name = none :: string() | atom() | {FunName :: binary(), call | dryr},
id = 0 :: integer(),
wx = none :: none | wx:wx_object()}).
+3 -2
View File
@@ -158,7 +158,7 @@ spend(TX) ->
when ID :: binary().
chain_id() ->
gen_server:cast(?MODULE, chain_id).
gen_server:call(?MODULE, chain_id).
-spec grids(string()) -> ok.
@@ -866,7 +866,8 @@ do_prompt_call(FunDef, ConID, Build, State = #s{tasks = Tasks, prefs = Prefs}) -
State;
false ->
CallPrefs = maps:get(gd_v_call, Prefs, #{}),
Win = gd_v_call:start_link({CallPrefs, FunDef, ConID, Build, Selected, KeyIDs}),
Args = {CallPrefs, FunDef, ConID, Build, Selected, KeyIDs},
Win = gd_v_call:start_link(Args),
PID = wx_object:get_pid(Win),
Mon = monitor(process, PID),
UI = #ui{name = Name, pid = PID, wx = Win, mon = Mon},
+15 -9
View File
@@ -71,7 +71,7 @@ start_link(Args) ->
wx_object:start_link({local, ?MODULE}, ?MODULE, Args, []).
init({Prefs, {FunName, FunType}, ConID, Build, Selected, Keys}) ->
init({Prefs, FunDef = {FunName, FunType}, ConID, Build, Selected, Keys}) ->
Lang = maps:get(lang, Prefs, en),
Trans = gd_jt:read_translations(?MODULE),
J = gd_jt:j(Lang, Trans),
@@ -91,7 +91,9 @@ init({Prefs, {FunName, FunType}, ConID, Build, Selected, Keys}) ->
KeySz = wxStaticBoxSizer:new(?wxVERTICAL, Frame, [{label, J("Signature Key")}]),
KeyPicker = wxChoice:new(Frame, ?wxID_ANY, [{choices, Keys}]),
ok = wxChoice:setSelection(KeyPicker, Selected),
KP = #w{name = key_picker, id = wxChoice:getId(KeyPicker), wx = KeyPicker},
ZeroBasedSelected = Selected - 1,
ok = wxChoice:setSelection(KeyPicker, ZeroBasedSelected),
_ = wxStaticBoxSizer:add(KeySz, KeyPicker, zxw:flags(wide)),
{ArgSz, Args, Dimensions} = call_arg_sizer(Frame, J, FunSpec),
@@ -129,8 +131,8 @@ init({Prefs, {FunName, FunType}, ConID, Build, Selected, Keys}) ->
true = wxFrame:show(Frame),
State =
#s{wx = Wx, frame = Frame, j = J, prefs = Prefs,
con_id = ConID, build = Build,
args = Args, kp = KeyPicker, params = Params,
fundef = FunDef, con_id = ConID, build = Build,
args = Args, kp = KP, params = Params,
action = Action,
tx_data = TX_Data, tx_hash = TX_Hash, tx_info = TX_Info,
out = Out, copy = Copy},
@@ -149,7 +151,7 @@ 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, 500}};
{CallSz, [], {500, 700}};
call_sizer(Frame, J, CallArgs) ->
ScrollWin = wxScrolledWindow:new(Frame),
ScrollSz = wxBoxSizer:new(?wxVERTICAL),
@@ -167,7 +169,7 @@ call_sizer(Frame, J, CallArgs) ->
C = wxTextCtrl:new(ScrollWin, ?wxID_ANY),
_ = wxFlexGridSizer:add(GridSz, L, zxw:flags({base, 5})),
_ = wxFlexGridSizer:add(GridSz, C, zxw:flags({wide, 5})),
{Name, C}
#w{name = Name, id = wxTextCtrl:getId(C), wx = C}
end,
Controls = lists:map(AddArg, CallArgs),
{CallSz, Controls, {500, 900}}.
@@ -215,7 +217,7 @@ call_param_sizer(Frame, J) ->
[{ "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("TX Amount"), fun gt_0/1, Amount_T}],
{J("TX Amount"), fun gte_0/1, Amount_T}],
{ParamSz, Params}.
@@ -272,18 +274,21 @@ engage(State) ->
end.
engage2(State, ChainID) ->
tell(info, "ChainID: ~p", [ChainID]),
case params(State) of
{ok, Params} -> engage3(State, ChainID, Params);
Error -> handle_troubling(State, Error)
end.
engage3(State, ChainID, Params) ->
tell(info, "Params: ~p", [Params]),
case args(State) of
{ok, Args} -> engage4(State, ChainID, Params, {sophia, Args});
Error -> handle_troubling(State, Error)
end.
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
{ok, CreateTX} -> deploy(State, ChainID, CallerID, CreateTX);
@@ -332,7 +337,7 @@ args(#s{args = ArgFields}) ->
deploy(State, ChainID, CallerID, CreateTX) ->
case gd_con:sign_tx(ChainID, CallerID, CreateTX) of
case gd_con:sign_call(ChainID, CallerID, CreateTX) of
{ok, SignedTX} -> deploy2(State, SignedTX);
Error -> handle_troubling(State, Error)
end.
@@ -378,7 +383,8 @@ check_tx(State = #s{tx_data = #{"tx_hash" := TXHash} = TXData, tx_info = none})
Error ->
handle_troubling(State, Error)
end;
check_tx(State) ->
check_tx(State = #s{tx_data = TXData}) ->
tell(info, "TXData: ~p", [TXData]),
ok = tell("Nothing to check"),
State.