WIP
This commit is contained in:
+2
-2
@@ -470,8 +470,8 @@ handle_cast({sign_tx, Request}, State) ->
|
|||||||
ok = do_sign_tx(Request, State),
|
ok = do_sign_tx(Request, State),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
handle_cast({deploy, Build}, State) ->
|
handle_cast({deploy, Build}, State) ->
|
||||||
ok = do_deploy(Build, State),
|
NewState = do_deploy(Build, State),
|
||||||
{noreply, State};
|
{noreply, NewState};
|
||||||
handle_cast({prompt_call, FunDef, ConID, Build}, State) ->
|
handle_cast({prompt_call, FunDef, ConID, Build}, State) ->
|
||||||
NewState = do_prompt_call(FunDef, ConID, Build, State),
|
NewState = do_prompt_call(FunDef, ConID, Build, State),
|
||||||
{noreply, NewState};
|
{noreply, NewState};
|
||||||
|
|||||||
+37
-27
@@ -34,17 +34,18 @@
|
|||||||
gas = #w{} :: #w{},
|
gas = #w{} :: #w{},
|
||||||
amount = #w{} :: #w{},
|
amount = #w{} :: #w{},
|
||||||
action = #w{} :: #w{},
|
action = #w{} :: #w{},
|
||||||
tx_data = none :: none | map(),
|
tx_data = none :: none | printable(),
|
||||||
tx_hash = #w{} :: #w{},
|
tx_hash = none :: none | printable(),
|
||||||
tx_info = none :: none | hz:transaction(),
|
tx_info = none :: none | printable(),
|
||||||
out = #w{} :: #w{},
|
out = #w{} :: #w{},
|
||||||
copy = #w{} :: #w{}}).
|
copy = #w{} :: #w{}}).
|
||||||
|
|
||||||
|
|
||||||
-type fun_name() :: string().
|
-type printable() :: {string() | term(), #w{}}.
|
||||||
-type fun_type() :: call | dryr | init.
|
-type fun_name() :: string().
|
||||||
-type fun_def() :: {fun_name(), fun_type()}.
|
-type fun_type() :: call | dryr | init.
|
||||||
-type param() :: {Label :: string(), Check :: fun(), #w{}}.
|
-type fun_def() :: {fun_name(), fun_type()}.
|
||||||
|
-type param() :: {Label :: string(), Check :: fun(), #w{}}.
|
||||||
|
|
||||||
|
|
||||||
%%% Interface
|
%%% 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 = wxStaticBoxSizer:new(?wxVERTICAL, Frame, [{label, J("Transaction Info")}]),
|
||||||
TX_Sz_Box = wxStaticBoxSizer:getStaticBox(TX_Sz),
|
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_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}]),
|
Line = wxStaticLine:new(TX_Sz_Box, [{style, ?wxLI_HORIZONTAL}]),
|
||||||
Out = #w{wx = OutTxt} = gd_lib:mono_text(TX_Sz_Box, out),
|
Out = #w{wx = OutTxt} = gd_lib:mono_text(TX_Sz_Box, out),
|
||||||
Copy = #w{wx = CopyBn} = gd_lib:button(TX_Sz_Box, J("Copy")),
|
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,
|
fundef = FunDef, con_id = ConID, build = Build,
|
||||||
args = Args, kp = KP, params = Params,
|
args = Args, kp = KP, params = Params,
|
||||||
action = Action,
|
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},
|
out = Out, copy = Copy},
|
||||||
{Frame, State}.
|
{Frame, State}.
|
||||||
|
|
||||||
@@ -274,23 +277,20 @@ engage(State) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
engage2(State, ChainID) ->
|
engage2(State, ChainID) ->
|
||||||
tell(info, "ChainID: ~p", [ChainID]),
|
|
||||||
case params(State) of
|
case params(State) of
|
||||||
{ok, Params} -> engage3(State, ChainID, Params);
|
{ok, Params} -> engage3(State, ChainID, Params);
|
||||||
Error -> handle_troubling(State, Error)
|
Error -> handle_troubling(State, Error)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
engage3(State, ChainID, Params) ->
|
engage3(State, ChainID, Params) ->
|
||||||
tell(info, "Params: ~p", [Params]),
|
|
||||||
case args(State) of
|
case args(State) of
|
||||||
{ok, Args} -> engage4(State, ChainID, Params, {sophia, Args});
|
{ok, Args} -> engage4(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) ->
|
engage4(State = #s{fundef = {"init", init}, build = Build}, ChainID, Params, Args) ->
|
||||||
tell(info, "Args: ~p", [Args]),
|
|
||||||
{CallerID, Nonce, TTL, GP, Gas, Amount} = Params,
|
{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);
|
{ok, CreateTX} -> deploy(State, ChainID, CallerID, CreateTX);
|
||||||
Error -> handle_troubling(State, Error)
|
Error -> handle_troubling(State, Error)
|
||||||
end;
|
end;
|
||||||
@@ -336,9 +336,10 @@ args(#s{args = ArgFields}) ->
|
|||||||
{ok, Values}.
|
{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
|
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)
|
Error -> handle_troubling(State, Error)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@@ -350,9 +351,10 @@ deploy2(State, SignedTX) ->
|
|||||||
end.
|
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
|
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)
|
Error -> handle_troubling(State, Error)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@@ -363,14 +365,18 @@ do_call2(State, SignedTX) ->
|
|||||||
end.
|
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
|
case hz:dry_run(TX) of
|
||||||
{ok, Result} -> update_info(State#s{tx_info = Result});
|
{ok, Result} ->
|
||||||
Other -> handle_troubling(State, {error, ConID, Other})
|
show_printable(State#s{tx_info = Result});
|
||||||
|
{error, Reason} ->
|
||||||
|
handle_troubling(State, {error, ConID, Reason})
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
check_tx(State = #s{tx_data = #{"tx_hash" := TXHash} = TXData, tx_info = none}) ->
|
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]),
|
ok = tell("TXData: ~p", [TXData]),
|
||||||
case hz:tx_info(TXHash) of
|
case hz:tx_info(TXHash) of
|
||||||
{ok, Info = #{"call_info" := #{"return_type" := "ok", "contract_id" := ConID}}} ->
|
{ok, Info = #{"call_info" := #{"return_type" := "ok", "contract_id" := ConID}}} ->
|
||||||
@@ -389,12 +395,6 @@ check_tx(State = #s{tx_data = TXData}) ->
|
|||||||
State.
|
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}) ->
|
copy(#s{tx_info = none}) ->
|
||||||
ok;
|
ok;
|
||||||
copy(#s{out = #w{wx = Out}}) ->
|
copy(#s{out = #w{wx = Out}}) ->
|
||||||
@@ -412,6 +412,16 @@ textify({T, _, _}) when is_list(T) -> T;
|
|||||||
textify({T, _, _}) -> io_lib:format("~tp", [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) ->
|
gt_0(S) ->
|
||||||
C = "Must be an integer greater than 0",
|
C = "Must be an integer greater than 0",
|
||||||
R =
|
R =
|
||||||
|
|||||||
+5
-3
@@ -467,7 +467,7 @@ deploy(State = #s{code = {Codebook, Pages}}) ->
|
|||||||
deploy2(State, Source) ->
|
deploy2(State, Source) ->
|
||||||
ok =
|
ok =
|
||||||
case compile(Source) of
|
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])
|
Other -> tell(info, "Compilation Failed!~n~tp", [Other])
|
||||||
end,
|
end,
|
||||||
State.
|
State.
|
||||||
@@ -602,9 +602,11 @@ get_contract_from_tx(State, Address) ->
|
|||||||
{ok, #{"call_info" := #{"contract_id" := Contract}}} ->
|
{ok, #{"call_info" := #{"contract_id" := Contract}}} ->
|
||||||
open_hash2(State, Contract);
|
open_hash2(State, Contract);
|
||||||
{ok, Other} ->
|
{ok, Other} ->
|
||||||
handle_troubling(State, {bad_address, Other});
|
ok = handle_troubling(State, {bad_address, Other}),
|
||||||
|
State;
|
||||||
Error ->
|
Error ->
|
||||||
handle_troubling(State, Error)
|
ok = handle_troubling(State, Error),
|
||||||
|
State
|
||||||
end.
|
end.
|
||||||
|
|
||||||
open_hash2(State, Address) ->
|
open_hash2(State, Address) ->
|
||||||
|
|||||||
Reference in New Issue
Block a user