Make Contract Calls Great Again #35
+13
-1
@@ -16,7 +16,7 @@
|
|||||||
refresh/0,
|
refresh/0,
|
||||||
nonce/1, spend/1, chain_id/0, grids/1,
|
nonce/1, spend/1, chain_id/0, grids/1,
|
||||||
sign_mess/1, sign_binary/1, sign_tx/1, sign_call/3,
|
sign_mess/1, sign_binary/1, sign_tx/1, sign_call/3,
|
||||||
deploy/1, prompt_call/3,
|
deploy/1, prompt_call/3, list_calls/0,
|
||||||
make_key/6, recover_key/1, mnemonic/1, rename_key/2, drop_key/1, list_keys/0,
|
make_key/6, recover_key/1, mnemonic/1, rename_key/2, drop_key/1, list_keys/0,
|
||||||
add_node/1, set_sole_node/1]).
|
add_node/1, set_sole_node/1]).
|
||||||
-export([tic/1, update_balance/2]).
|
-export([tic/1, update_balance/2]).
|
||||||
@@ -217,6 +217,18 @@ prompt_call(FunDef, ConID, Build) ->
|
|||||||
gen_server:cast(?MODULE, {prompt_call, FunDef, ConID, Build}).
|
gen_server:cast(?MODULE, {prompt_call, FunDef, ConID, Build}).
|
||||||
|
|
||||||
|
|
||||||
|
-spec list_calls() -> Calls
|
||||||
|
when Calls :: [{Name, Process}],
|
||||||
|
Name :: term(),
|
||||||
|
Process :: wx:wx_object() | pid().
|
||||||
|
|
||||||
|
%% @doc
|
||||||
|
%% List any active contract call tasks.
|
||||||
|
|
||||||
|
list_calls() ->
|
||||||
|
gen_server:call(?MODULE, list_calls).
|
||||||
|
|
||||||
|
|
||||||
-spec make_key(Type, Size, Name, Seed, Encoding, Transform) -> ok
|
-spec make_key(Type, Size, Name, Seed, Encoding, Transform) -> ok
|
||||||
when Type :: {eddsa, ed25519},
|
when Type :: {eddsa, ed25519},
|
||||||
Size :: 256,
|
Size :: 256,
|
||||||
|
|||||||
+53
-27
@@ -7,7 +7,7 @@
|
|||||||
-behavior(wx_object).
|
-behavior(wx_object).
|
||||||
%-behavior(gd_v).
|
%-behavior(gd_v).
|
||||||
-include_lib("wx/include/wx.hrl").
|
-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([start_link/1]).
|
||||||
-export([init/1, terminate/2, code_change/3,
|
-export([init/1, terminate/2, code_change/3,
|
||||||
handle_call/3, handle_cast/2, handle_info/2, handle_event/2]).
|
handle_call/3, handle_cast/2, handle_info/2, handle_event/2]).
|
||||||
@@ -36,8 +36,9 @@
|
|||||||
status = none :: status(),
|
status = none :: status(),
|
||||||
action = #w{} :: #w{},
|
action = #w{} :: #w{},
|
||||||
tx_data = none :: none | map(),
|
tx_data = none :: none | map(),
|
||||||
tx_hash = #w{} :: #w{}, % wxTextCtrl, single-line
|
tx_info = none :: none | map(),
|
||||||
tx_info = none :: #w{}, % wxTextCtrl, multi-line
|
hash = #w{} :: #w{}, % wxTextCtrl, single-line
|
||||||
|
info = #w{} :: #w{}, % wxTextCtrl, multi-line
|
||||||
out = #w{} :: #w{},
|
out = #w{} :: #w{},
|
||||||
copy = #w{} :: #w{}}).
|
copy = #w{} :: #w{}}).
|
||||||
|
|
||||||
@@ -47,9 +48,9 @@
|
|||||||
-type fun_def() :: {fun_name(), fun_type()}.
|
-type fun_def() :: {fun_name(), fun_type()}.
|
||||||
-type param() :: {Label :: string(), Check :: fun(), #w{}}.
|
-type param() :: {Label :: string(), Check :: fun(), #w{}}.
|
||||||
-type status() :: none
|
-type status() :: none
|
||||||
| {submitted, TX_Hash :: string()}
|
| submitted
|
||||||
| {rejected, Reason :: string()}
|
| rejected
|
||||||
| {included, TX_Info :: map()}.
|
| included.
|
||||||
|
|
||||||
|
|
||||||
%%% Interface
|
%%% Interface
|
||||||
@@ -61,12 +62,28 @@ to_front(Win) ->
|
|||||||
wx_object:cast(Win, to_front).
|
wx_object:cast(Win, to_front).
|
||||||
|
|
||||||
|
|
||||||
-spec result(Win, Outcome) -> ok
|
-spec tx_hash(Win) -> Result
|
||||||
when Win :: wx:wx_object(),
|
when Win :: pid() | wx:wx_object(),
|
||||||
Outcome :: term().
|
Result :: none | string().
|
||||||
|
|
||||||
result(Win, Outcome) ->
|
tx_hash(Win) ->
|
||||||
wx_object:cast(Win, {result, Outcome}).
|
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,
|
#s{wx = Wx, frame = Frame, j = J, prefs = Prefs,
|
||||||
fundef = FunDef, con_id = ConID, build = Build,
|
fundef = FunDef, con_id = ConID, build = Build,
|
||||||
args = Args, kp = KP, params = Params,
|
args = Args, kp = KP, params = Params,
|
||||||
action = Action,
|
action = Action, status = none,
|
||||||
tx_data = TX_Data, tx_hash = TX_Hash, tx_info = TX_Info,
|
tx_data = TX_Data, tx_hash = TX_Hash, tx_info = TX_Info,
|
||||||
out = Out, copy = Copy},
|
out = Out, copy = Copy},
|
||||||
{Frame, State}.
|
{Frame, State}.
|
||||||
@@ -234,6 +251,12 @@ call_param_sizer(Frame, J) ->
|
|||||||
{ParamSz, Params}.
|
{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) ->
|
handle_call(Unexpected, From, State) ->
|
||||||
ok = log(warning, "Unexpected call from ~tp: ~tp~n", [From, Unexpected]),
|
ok = log(warning, "Unexpected call from ~tp: ~tp~n", [From, Unexpected]),
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
@@ -249,9 +272,13 @@ handle_info(Unexpected, State) ->
|
|||||||
{noreply, 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},
|
handle_event(#wx{event = #wxCommand{type = command_button_clicked}, id = ID},
|
||||||
State = #s{action = #w{id = ID}}) ->
|
State = #s{action = #w{id = ID}}) ->
|
||||||
NewState = engage(State),
|
NewState = check_tx(State),
|
||||||
{noreply, NewState};
|
{noreply, NewState};
|
||||||
handle_event(#wx{event = #wxCommand{type = command_button_clicked}, id = ID},
|
handle_event(#wx{event = #wxCommand{type = command_button_clicked}, id = ID},
|
||||||
State = #s{copy = #w{id = ID}}) ->
|
State = #s{copy = #w{id = ID}}) ->
|
||||||
@@ -280,34 +307,33 @@ handle_troubling(State = #s{frame = Frame}, Info) ->
|
|||||||
State.
|
State.
|
||||||
|
|
||||||
|
|
||||||
engage(State) ->
|
prep_call(State) ->
|
||||||
case gd_con:chain_id() of
|
case gd_con:chain_id() of
|
||||||
{ok, ChainID} -> engage2(State, ChainID);
|
{ok, ChainID} -> prep_call2(State, ChainID);
|
||||||
Error -> handle_troubling(State, Error)
|
Error -> handle_troubling(State, Error)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
engage2(State, ChainID) ->
|
prep_call2(State, ChainID) ->
|
||||||
tell(info, "ChainID: ~p", [ChainID]),
|
tell(info, "ChainID: ~p", [ChainID]),
|
||||||
case params(State) of
|
case params(State) of
|
||||||
{ok, Params} -> engage3(State, ChainID, Params);
|
{ok, Params} -> prep_call3(State, ChainID, Params);
|
||||||
Error -> handle_troubling(State, Error)
|
Error -> handle_troubling(State, Error)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
engage3(State, ChainID, Params) ->
|
prep_call3(State, ChainID, Params) ->
|
||||||
tell(info, "Params: ~p", [Params]),
|
tell(info, "Params: ~p", [Params]),
|
||||||
case args(State) of
|
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)
|
Error -> handle_troubling(State, Error)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
engage4(State = #s{fundef = {"init", init}, build = Build}, ChainID, Params, Args) ->
|
prep_call4(State = #s{fundef = {"init", init}, build = Build}, ChainID, Params, Args) ->
|
||||||
tell(info, "Args: ~p", [Args]),
|
|
||||||
{CallerID, Nonce, TTL, Gas, GP, Amount} = Params,
|
{CallerID, Nonce, TTL, Gas, GP, Amount} = Params,
|
||||||
case hz:contract_create_built(CallerID, Nonce, Amount, TTL, Gas, GP, Build, Args) of
|
case hz:contract_create_built(CallerID, Nonce, Amount, TTL, Gas, GP, Build, Args) of
|
||||||
{ok, CreateTX} -> deploy(State, ChainID, CallerID, CreateTX);
|
{ok, CreateTX} -> deploy(State, ChainID, CallerID, CreateTX);
|
||||||
Error -> handle_troubling(State, Error)
|
Error -> handle_troubling(State, Error)
|
||||||
end;
|
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,
|
{CallerID, Nonce, TTL, Gas, GP, Amount} = Params,
|
||||||
AACI = maps:get(aaci, Build),
|
AACI = maps:get(aaci, Build),
|
||||||
case hz:contract_call(CallerID, Nonce, Gas, GP, Amount, TTL, AACI, ConID, Name, Args) of
|
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) ->
|
deploy2(State, SignedTX) ->
|
||||||
case hz:post_tx(SignedTX) of
|
case hz:post_tx(SignedTX) of
|
||||||
{ok, Data} ->
|
{ok, Data = #{"tx_hash" := TXHash}} ->
|
||||||
case maps:is_key("reason", Data) of
|
ok = log(info, "Submitted transaction ~s", [TXHash]),
|
||||||
false -> check_tx(State#s{tx_data = Data});
|
check_tx(State#s{tx_data = Data, status = submitted});
|
||||||
true -> handle_troubling(State, {error, Data})
|
{ok, #{"reason" := Reason}} ->
|
||||||
end;
|
handle_troubling(State, {error, Reason});
|
||||||
Error ->
|
Error ->
|
||||||
handle_troubling(State, Error)
|
handle_troubling(State, Error)
|
||||||
end.
|
end.
|
||||||
|
|||||||
Reference in New Issue
Block a user