Make Contract Calls Great Again #35

Merged
zxq9 merged 37 commits from iface3 into master 2026-05-10 15:39:25 +09:00
3 changed files with 81 additions and 26 deletions
Showing only changes of commit b4dbf21c41 - Show all commits
+60 -16
View File
@@ -16,7 +16,8 @@
refresh/0,
nonce/1, spend/1, chain_id/0, grids/1,
sign_mess/1, sign_binary/1, sign_tx/1, sign_call/3,
deploy/1, prompt_call/3, list_calls/0, open_contract/1, show_call/2,
deploy/1, prompt_call/3, list_calls/0,
open_contract/1, open_contract/2, show_call/2, show_call/3,
make_key/6, recover_key/1, mnemonic/1, rename_key/2, drop_key/1, list_keys/0,
add_node/1, set_sole_node/1]).
-export([tic/1, update_balance/2]).
@@ -26,7 +27,6 @@
-export([init/1, terminate/2, code_change/3,
handle_call/3, handle_cast/2, handle_info/2]).
-include("$zx_include/zx_logger.hrl").
-include("gd.hrl").
@@ -232,23 +232,48 @@ list_calls() ->
-spec open_contract(ConID) -> ok
when ConID :: string().
%% @doc
%% @equiv open_contract(ConID, true).
open_contract(ConID) ->
open_contract(ConID, true).
-spec open_contract(ConID, DevmanToFront) -> ok
when ConID :: string(),
DevmanToFront :: boolean().
%% @doc
%% Ask the controller to tell the devman interface to open a deployed contract.
%% The controller will start the devman if it isn't already on.
open_contract(ConID) ->
gen_server:cast(?MODULE, {open_contract, ConID}).
open_contract(ConID, DevmanToFront) when is_binary(ConID) ->
gen_server:cast(?MODULE, {open_contract, ConID, DevmanToFront});
open_contract(ConID, DevmanToFront) when is_list(ConID) ->
open_contract(list_to_binary(ConID), DevmanToFront).
-spec show_call(ConID, Info) -> ok
when ConID :: string(),
Info :: map().
%% @doc
%% @equiv show_call(ConID, Info, true).
show_call(ConID, Info) ->
show_call(ConID, Info, true).
-spec show_call(ConID, Info, DevmanToFront) -> ok
when ConID :: string(),
Info :: map(),
DevmanToFront :: boolean().
%% @doc
%% Ask the controller to tell the devman interface to dislpay the result of a call
%% to the indicated contract. Opens the contract in question if it isn't alread open.
%% Starts the devman if it isn't already running.
show_call(ConID, Info) ->
gen_server:cast(?MODULE, {show_call, ConID, Info}).
show_call(ConID, Info, DevmanToFront) when is_binary(ConID) ->
gen_server:cast(?MODULE, {show_call, ConID, Info, DevmanToFront});
show_call(ConID, Info, DevmanToFront) when is_list(ConID) ->
show_call(list_to_binary(ConID), Info, DevmanToFront).
-spec make_key(Type, Size, Name, Seed, Encoding, Transform) -> ok
@@ -521,11 +546,11 @@ handle_cast({rename_key, ID, NewName}, State) ->
handle_cast({drop_key, ID}, State) ->
NewState = do_drop_key(ID, State),
{noreply, NewState};
handle_cast({open_contract, ConID}, State) ->
NewState = do_open_contract(ConID, State),
handle_cast({open_contract, ConID, ToFront}, State) ->
NewState = do_open_contract(ConID, ToFront, State),
{noreply, NewState};
handle_cast({show_call, ConID, Info}, State) ->
NewState = do_show_call(ConID, Info, State),
handle_cast({show_call, ConID, Info, ToFront}, State) ->
NewState = do_show_call(ConID, Info, ToFront, State),
{noreply, NewState};
handle_cast({add_node, New}, State) ->
NewState = do_add_node(New, State),
@@ -594,11 +619,29 @@ terminate(Reason, _) ->
%%% GUI doers
-spec do_show_ui(Name, State) -> NewState
when Name :: ui_name() | term(),
State :: state(),
NewState :: state().
do_show_ui(Name, State = #s{tasks = Tasks, prefs = Prefs}) ->
do_show_ui(Name, State) ->
do_show_ui(Name, true, State).
-spec do_show_ui(Name, ToFront, State) -> NewState
when Name :: ui_name() | term(),
ToFront :: boolean(),
State :: state(),
NewState :: state().
do_show_ui(Name, ToFront, State = #s{tasks = Tasks, prefs = Prefs}) ->
case lists:keyfind(Name, #ui.name, Tasks) of
#ui{wx = Win} ->
ok = Name:to_front(Win),
ok =
case ToFront of
true -> Name:to_front(Win);
false -> ok
end,
State;
false ->
TaskPrefs = maps:get(Name, Prefs, #{}),
@@ -1019,14 +1062,15 @@ do_drop_key(ID, State = #s{wallet = W, wallets = Wallets, pass = Pass}) ->
State#s{wallet = NewWallet}.
do_open_contract(ConID, State) ->
NewState = do_show_ui(gd_v_devman, State),
do_open_contract(ConID, ToFront, State) ->
NewState = do_show_ui(gd_v_devman, ToFront, State),
ok = gd_v_devman:open_contract(ConID),
NewState.
do_show_call(ConID, Info, State) ->
NewState = do_show_ui(gd_v_devman, State),
do_show_call(ConID, Info, ToFront, State) ->
NewState = do_show_ui(gd_v_devman, ToFront, State),
ok = gd_v_devman:open_contract(ConID),
ok = gd_v_devman:call_result(ConID, Info),
NewState.
+10 -7
View File
@@ -501,6 +501,7 @@ check_tx(State = #s{frame = Frame,
State
end;
check_tx(State = #s{j = J,
funret = ReturnType,
con_id = ConID,
tx_data = #{"tx_hash" := TXHash},
tx_info = none,
@@ -512,21 +513,23 @@ check_tx(State = #s{j = J,
case hz:tx_info(TXHash) of
{ok, Info = #{"call_info" := #{"return_type" := "ok",
"contract_id" := ConID,
"return_value" := Value}}} ->
FormattedInfo = io_lib:fomat("~tp", [Info]),
"return_value" := ReturnCB}}} ->
FormattedInfo = io_lib:format("~tp", [Info]),
_ = wxButton:enable(CopyB),
_ = wxButton:disable(ActionB),
ok = wxTextCtrl:setValue(ReturnT, Value),
ReturnV = hz:decode_bytearray(ReturnCB, {sophia, ReturnType}),
ok = wxTextCtrl:setValue(ReturnT, ReturnV),
ok = wxTextCtrl:setValue(InfoT, FormattedInfo),
ok = gd_con:show_call(ConID, Info),
ok = gd_con:show_call(ConID, Info, false),
State#s{status = included, tx_info = Info};
{ok, Reason = #{"call_info" := #{"return_type" := "revert"}}} ->
{ok, Reason = #{"call_info" := #{"return_type" := "revert", "return_value" := ReturnCB}}} ->
_ = wxButton:enable(CopyB),
_ = wxButton:disable(ActionB),
ReturnV = io_lib:format("Revert: ~ts", [hz:decode_bytearray(ReturnCB, sophia)]),
ok = wxTextCtrl:setValue(ReturnT, ReturnV),
FormattedInfo = io_lib:format("~tp", [Reason]),
ok = wxTextCtrl:setValue(ReturnT, FormattedInfo), % FIXME
ok = wxTextCtrl:setValue(InfoT, FormattedInfo),
ok = gd_con:show_call(ConID, Reason),
ok = gd_con:show_call(ConID, Reason, false),
State#s{status = rejected, tx_info = Reason};
{error, "Tx not mined"} ->
ok = wxTextCtrl:setValue(InfoT, J("[Transaction not yet mined.]")),
+11 -3
View File
@@ -733,15 +733,23 @@ load_from_tx(State, Address) ->
handle_troubling(State, Error)
end.
load2(State, Address) ->
load2(State = #s{cons = {_, Pages}}, Address) when is_binary(Address) ->
case lists:keyfind(Address, #c.id, Pages) of
false -> load3(State, Address);
#c{} -> State
end;
load2(State, Address) when is_list(Address) ->
load2(State, list_to_binary(Address)).
load3(State, Address) ->
case hz:contract_source(Address) of
{ok, Source} ->
load3(State, Address, Source);
load4(State, Address, Source);
Error ->
handle_troubling(State, Error)
end.
load3(State = #s{tabs = TopBook, cons = {Consbook, Pages}, buttons = Buttons, j = J},
load4(State = #s{tabs = TopBook, cons = {Consbook, Pages}, buttons = Buttons, j = J},
Address,
Source) ->
Window = wxWindow:new(Consbook, ?wxID_ANY),