diff --git a/src/gd_con.erl b/src/gd_con.erl index a26c234..73a8641 100644 --- a/src/gd_con.erl +++ b/src/gd_con.erl @@ -470,8 +470,8 @@ handle_cast({sign_tx, Request}, State) -> ok = do_sign_tx(Request, State), {noreply, State}; handle_cast({deploy, Build}, State) -> - ok = do_deploy(Build, State), - {noreply, State}; + NewState = do_deploy(Build, State), + {noreply, NewState}; handle_cast({prompt_call, FunDef, ConID, Build}, State) -> NewState = do_prompt_call(FunDef, ConID, Build, State), {noreply, NewState}; diff --git a/src/gd_v_call.erl b/src/gd_v_call.erl index b86209b..313480e 100644 --- a/src/gd_v_call.erl +++ b/src/gd_v_call.erl @@ -34,17 +34,18 @@ gas = #w{} :: #w{}, amount = #w{} :: #w{}, action = #w{} :: #w{}, - tx_data = none :: none | map(), - tx_hash = #w{} :: #w{}, - tx_info = none :: none | hz:transaction(), + tx_data = none :: none | printable(), + tx_hash = none :: none | printable(), + tx_info = none :: none | printable(), out = #w{} :: #w{}, copy = #w{} :: #w{}}). --type fun_name() :: string(). --type fun_type() :: call | dryr | init. --type fun_def() :: {fun_name(), fun_type()}. --type param() :: {Label :: string(), Check :: fun(), #w{}}. +-type printable() :: {string() | term(), #w{}}. +-type fun_name() :: string(). +-type fun_type() :: call | dryr | init. +-type fun_def() :: {fun_name(), fun_type()}. +-type param() :: {Label :: string(), Check :: fun(), #w{}}. %%% Interface @@ -103,9 +104,9 @@ init({Prefs, FunDef = {FunName, FunType}, ConID, Build, Selected, Keys}) -> TX_Sz = wxStaticBoxSizer:new(?wxVERTICAL, Frame, [{label, J("Transaction Info")}]), TX_Sz_Box = wxStaticBoxSizer:getStaticBox(TX_Sz), - TX_Data = #w{wx = DataT} = gd_lib:mono_text(TX_Sz_Box, tx_hash), + TX_Data = #w{wx = DataT} = gd_lib:mono_text(TX_Sz_Box, tx_data), TX_Hash = #w{wx = HashT} = gd_lib:mono_text(TX_Sz_Box, tx_hash), - TX_Info = #w{wx = InfoT} = gd_lib:mono_text(TX_Sz_Box, tx_hash), + TX_Info = #w{wx = InfoT} = gd_lib:mono_text(TX_Sz_Box, tx_info), Line = wxStaticLine:new(TX_Sz_Box, [{style, ?wxLI_HORIZONTAL}]), Out = #w{wx = OutTxt} = gd_lib:mono_text(TX_Sz_Box, out), Copy = #w{wx = CopyBn} = gd_lib:button(TX_Sz_Box, J("Copy")), @@ -134,7 +135,9 @@ init({Prefs, FunDef = {FunName, FunType}, ConID, Build, Selected, Keys}) -> 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, + tx_data = {none, TX_Data}, + tx_hash = {none, TX_Hash}, + tx_info = {none, TX_Info}, out = Out, copy = Copy}, {Frame, State}. @@ -274,23 +277,20 @@ 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 + 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; @@ -336,9 +336,10 @@ args(#s{args = ArgFields}) -> {ok, Values}. -deploy(State, ChainID, CallerID, CreateTX) -> +deploy(State = #s{tx_data = TXData}, ChainID, CallerID, CreateTX) -> + NewTXData = show_printable(TXData, CreateTX), case gd_con:sign_call(ChainID, CallerID, CreateTX) of - {ok, SignedTX} -> deploy2(State, SignedTX); + {ok, SignedTX} -> deploy2(State = #s{tx_data = NewTXData}, SignedTX); Error -> handle_troubling(State, Error) end. @@ -350,9 +351,10 @@ deploy2(State, SignedTX) -> end. -do_call(State, ChainID, CallerID, UnsignedTX) -> +do_call(State = #s{tx_data = TXData}, ChainID, CallerID, UnsignedTX) -> + NewTXData = show_printable(TXData, UnsignedTX), case gd_con:sign_call(ChainID, CallerID, UnsignedTX) of - {ok, SignedTX} -> do_call2(State, SignedTX); + {ok, SignedTX} -> do_call2(State = #s{tx_data = NewTXData}, SignedTX); Error -> handle_troubling(State, Error) end. @@ -363,14 +365,18 @@ do_call2(State, SignedTX) -> end. -do_dry_run(State, ConID, TX) -> +do_dry_run(State = #s{tx_data = TXData}, ConID, TX) -> + NewTXData = show_printable(TXData, CreateTX), case hz:dry_run(TX) of - {ok, Result} -> update_info(State#s{tx_info = Result}); - Other -> handle_troubling(State, {error, ConID, Other}) + {ok, Result} -> + show_printable(State#s{tx_info = Result}); + {error, Reason} -> + handle_troubling(State, {error, ConID, Reason}) end. check_tx(State = #s{tx_data = #{"tx_hash" := TXHash} = TXData, tx_info = none}) -> +check_tx(State = #s{tx_data = #w{wx = TXData}}) -> ok = tell("TXData: ~p", [TXData]), case hz:tx_info(TXHash) of {ok, Info = #{"call_info" := #{"return_type" := "ok", "contract_id" := ConID}}} -> @@ -389,12 +395,6 @@ check_tx(State = #s{tx_data = TXData}) -> State. -update_info(State = #s{tx_info = TXInfo, out = #w{wx = Out}}) -> - Formatted = io_lib:format("TXInfo: ~p~n", [TXInfo]), - ok = wxStaticText:setLabel(Out, Formatted), - State. - - copy(#s{tx_info = none}) -> ok; copy(#s{out = #w{wx = Out}}) -> @@ -412,6 +412,16 @@ textify({T, _, _}) when is_list(T) -> T; textify({T, _, _}) -> io_lib:format("~tp", [T]). +show_printable(Data, {_, W = #w{wx = Widget}}) -> + Formatted = io_lib:format("~p", [Data]) + ok = + case wx:getObjectType(Widget) of + wxStaticText -> wxStaticText:setLabel(Widget, Formatted); + wxTextCtrl -> wxTextCtrl:setValue(Widget, Formatted) + end, + {Data, Widget}. + + gt_0(S) -> C = "Must be an integer greater than 0", R = diff --git a/src/gd_v_devman.erl b/src/gd_v_devman.erl index cd2d7e4..5001092 100644 --- a/src/gd_v_devman.erl +++ b/src/gd_v_devman.erl @@ -467,7 +467,7 @@ deploy(State = #s{code = {Codebook, Pages}}) -> deploy2(State, Source) -> ok = case compile(Source) of - {ok, Build} -> gd_con:prompt_call({"init", init}, init, Build); + {ok, Build} -> gd_con:deploy(Build); Other -> tell(info, "Compilation Failed!~n~tp", [Other]) end, State. @@ -602,9 +602,11 @@ get_contract_from_tx(State, Address) -> {ok, #{"call_info" := #{"contract_id" := Contract}}} -> open_hash2(State, Contract); {ok, Other} -> - handle_troubling(State, {bad_address, Other}); + ok = handle_troubling(State, {bad_address, Other}), + State; Error -> - handle_troubling(State, Error) + ok = handle_troubling(State, Error), + State end. open_hash2(State, Address) ->