WIP: Add gd_con:list_calls/0 and gd_v_call:tx_*/1
This commit is contained in:
+53
-27
@@ -7,7 +7,7 @@
|
||||
-behavior(wx_object).
|
||||
%-behavior(gd_v).
|
||||
-include_lib("wx/include/wx.hrl").
|
||||
-export([to_front/1, result/2]).
|
||||
-export([to_front/1, tx_hash/1, tx_data/1, tx_info/1]).
|
||||
-export([start_link/1]).
|
||||
-export([init/1, terminate/2, code_change/3,
|
||||
handle_call/3, handle_cast/2, handle_info/2, handle_event/2]).
|
||||
@@ -36,8 +36,9 @@
|
||||
status = none :: status(),
|
||||
action = #w{} :: #w{},
|
||||
tx_data = none :: none | map(),
|
||||
tx_hash = #w{} :: #w{}, % wxTextCtrl, single-line
|
||||
tx_info = none :: #w{}, % wxTextCtrl, multi-line
|
||||
tx_info = none :: none | map(),
|
||||
hash = #w{} :: #w{}, % wxTextCtrl, single-line
|
||||
info = #w{} :: #w{}, % wxTextCtrl, multi-line
|
||||
out = #w{} :: #w{},
|
||||
copy = #w{} :: #w{}}).
|
||||
|
||||
@@ -47,9 +48,9 @@
|
||||
-type fun_def() :: {fun_name(), fun_type()}.
|
||||
-type param() :: {Label :: string(), Check :: fun(), #w{}}.
|
||||
-type status() :: none
|
||||
| {submitted, TX_Hash :: string()}
|
||||
| {rejected, Reason :: string()}
|
||||
| {included, TX_Info :: map()}.
|
||||
| submitted
|
||||
| rejected
|
||||
| included.
|
||||
|
||||
|
||||
%%% Interface
|
||||
@@ -61,12 +62,28 @@ to_front(Win) ->
|
||||
wx_object:cast(Win, to_front).
|
||||
|
||||
|
||||
-spec result(Win, Outcome) -> ok
|
||||
when Win :: wx:wx_object(),
|
||||
Outcome :: term().
|
||||
-spec tx_hash(Win) -> Result
|
||||
when Win :: pid() | wx:wx_object(),
|
||||
Result :: none | string().
|
||||
|
||||
result(Win, Outcome) ->
|
||||
wx_object:cast(Win, {result, Outcome}).
|
||||
tx_hash(Win) ->
|
||||
wx_object:call(Win, tx_hash).
|
||||
|
||||
|
||||
-spec tx_data(Win) -> Result
|
||||
when Win :: pid() | wx:wx_object(),
|
||||
Result :: none | map().
|
||||
|
||||
tx_hash(Win) ->
|
||||
wx_object:call(Win, tx_data).
|
||||
|
||||
|
||||
-spec tx_info(Win) -> Result
|
||||
when Win :: pid() | wx:wx_object(),
|
||||
Result :: none | map().
|
||||
|
||||
tx_hash(Win) ->
|
||||
wx_object:call(Win, tx_info).
|
||||
|
||||
|
||||
|
||||
@@ -146,7 +163,7 @@ init({Prefs, FunDef = {FunName, FunType}, ConID, Build, Selected, Keys}) ->
|
||||
#s{wx = Wx, frame = Frame, j = J, prefs = Prefs,
|
||||
fundef = FunDef, con_id = ConID, build = Build,
|
||||
args = Args, kp = KP, params = Params,
|
||||
action = Action,
|
||||
action = Action, status = none,
|
||||
tx_data = TX_Data, tx_hash = TX_Hash, tx_info = TX_Info,
|
||||
out = Out, copy = Copy},
|
||||
{Frame, State}.
|
||||
@@ -234,6 +251,12 @@ call_param_sizer(Frame, J) ->
|
||||
{ParamSz, Params}.
|
||||
|
||||
|
||||
handle_call(tx_hash, _, State = #s{tx_hash = TXHash}) ->
|
||||
{reply, TXHash, State};
|
||||
handle_call(tx_data, _, State = #s{tx_data = TXData}) ->
|
||||
{reply, TXData, State};
|
||||
handle_call(tx_info, _, State = #s{tx_info = TXInfo}) ->
|
||||
{reply, TXInfo, State};
|
||||
handle_call(Unexpected, From, State) ->
|
||||
ok = log(warning, "Unexpected call from ~tp: ~tp~n", [From, Unexpected]),
|
||||
{noreply, State}.
|
||||
@@ -249,9 +272,13 @@ handle_info(Unexpected, State) ->
|
||||
{noreply, State}.
|
||||
|
||||
|
||||
handle_event(#wx{event = #wxCommand{type = command_button_clicked}, id = ID},
|
||||
State = #s{action = #w{id = ID}, status = none}) ->
|
||||
NewState = prep_call(State),
|
||||
{noreply, NewState};
|
||||
handle_event(#wx{event = #wxCommand{type = command_button_clicked}, id = ID},
|
||||
State = #s{action = #w{id = ID}}) ->
|
||||
NewState = engage(State),
|
||||
NewState = check_tx(State),
|
||||
{noreply, NewState};
|
||||
handle_event(#wx{event = #wxCommand{type = command_button_clicked}, id = ID},
|
||||
State = #s{copy = #w{id = ID}}) ->
|
||||
@@ -280,34 +307,33 @@ handle_troubling(State = #s{frame = Frame}, Info) ->
|
||||
State.
|
||||
|
||||
|
||||
engage(State) ->
|
||||
prep_call(State) ->
|
||||
case gd_con:chain_id() of
|
||||
{ok, ChainID} -> engage2(State, ChainID);
|
||||
{ok, ChainID} -> prep_call2(State, ChainID);
|
||||
Error -> handle_troubling(State, Error)
|
||||
end.
|
||||
|
||||
engage2(State, ChainID) ->
|
||||
prep_call2(State, ChainID) ->
|
||||
tell(info, "ChainID: ~p", [ChainID]),
|
||||
case params(State) of
|
||||
{ok, Params} -> engage3(State, ChainID, Params);
|
||||
{ok, Params} -> prep_call3(State, ChainID, Params);
|
||||
Error -> handle_troubling(State, Error)
|
||||
end.
|
||||
|
||||
engage3(State, ChainID, Params) ->
|
||||
prep_call3(State, ChainID, Params) ->
|
||||
tell(info, "Params: ~p", [Params]),
|
||||
case args(State) of
|
||||
{ok, Args} -> engage4(State, ChainID, Params, {sophia, Args});
|
||||
{ok, Args} -> prep_call4(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]),
|
||||
prep_call4(State = #s{fundef = {"init", init}, build = Build}, ChainID, Params, Args) ->
|
||||
{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) ->
|
||||
prep_call4(State = #s{fundef = {Name, Type}, con_id = ConID, build = Build}, ChainID, Params, Args) ->
|
||||
{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
|
||||
@@ -357,11 +383,11 @@ deploy(State, ChainID, CallerID, CreateTX) ->
|
||||
|
||||
deploy2(State, SignedTX) ->
|
||||
case hz:post_tx(SignedTX) of
|
||||
{ok, Data} ->
|
||||
case maps:is_key("reason", Data) of
|
||||
false -> check_tx(State#s{tx_data = Data});
|
||||
true -> handle_troubling(State, {error, Data})
|
||||
end;
|
||||
{ok, Data = #{"tx_hash" := TXHash}} ->
|
||||
ok = log(info, "Submitted transaction ~s", [TXHash]),
|
||||
check_tx(State#s{tx_data = Data, status = submitted});
|
||||
{ok, #{"reason" := Reason}} ->
|
||||
handle_troubling(State, {error, Reason});
|
||||
Error ->
|
||||
handle_troubling(State, Error)
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user