WIP
This commit is contained in:
parent
9fa365e83f
commit
9365c33351
@ -298,7 +298,7 @@ handle_event(#wx{event = #wxCommand{type = command_button_clicked},
|
|||||||
#w{name = mnemonic} -> show_mnemonic(State);
|
#w{name = mnemonic} -> show_mnemonic(State);
|
||||||
#w{name = rename} -> rename_key(State);
|
#w{name = rename} -> rename_key(State);
|
||||||
#w{name = drop_key} -> drop_key(State);
|
#w{name = drop_key} -> drop_key(State);
|
||||||
#w{name = copy} -> copy(State);
|
#w{name = copy} -> copy_pk(State);
|
||||||
#w{name = www} -> www(State);
|
#w{name = www} -> www(State);
|
||||||
#w{name = send} -> spend(State);
|
#w{name = send} -> spend(State);
|
||||||
#w{name = grids} -> grids_dialogue(State);
|
#w{name = grids} -> grids_dialogue(State);
|
||||||
@ -588,7 +588,7 @@ show_mnemonic(Selected, State = #s{frame = Frame, j = J, accounts = Accounts}) -
|
|||||||
ok =
|
ok =
|
||||||
case wxDialog:showModal(Dialog) of
|
case wxDialog:showModal(Dialog) of
|
||||||
?wxID_CANCEL -> ok;
|
?wxID_CANCEL -> ok;
|
||||||
?wxID_OK -> copy_to_clipboard(Mnemonic)
|
?wxID_OK -> gd_lib:copy_to_clipboard(Mnemonic)
|
||||||
end,
|
end,
|
||||||
ok = wxDialog:destroy(Dialog),
|
ok = wxDialog:destroy(Dialog),
|
||||||
State.
|
State.
|
||||||
@ -656,28 +656,11 @@ drop_key(Selected, State = #s{frame = Frame, j = J, accounts = Accounts, prefs =
|
|||||||
State#s{prefs = NewPrefs}.
|
State#s{prefs = NewPrefs}.
|
||||||
|
|
||||||
|
|
||||||
copy(State = #s{id = {_, #w{wx = ID_T}}}) ->
|
copy_pk(State = #s{id = {_, #w{wx = ID_T}}}) ->
|
||||||
String = wxStaticText:getLabel(ID_T),
|
String = wxStaticText:getLabel(ID_T),
|
||||||
ok = copy_to_clipboard(String),
|
ok = gd_lib:copy_to_clipboard(String),
|
||||||
State.
|
State.
|
||||||
|
|
||||||
copy_to_clipboard(String) ->
|
|
||||||
CB = wxClipboard:get(),
|
|
||||||
case wxClipboard:open(CB) of
|
|
||||||
true ->
|
|
||||||
Text = wxTextDataObject:new([{text, String}]),
|
|
||||||
case wxClipboard:setData(CB, Text) of
|
|
||||||
true ->
|
|
||||||
R = wxClipboard:flush(CB),
|
|
||||||
log(info, "String copied to system clipboard. Flushed: ~p", [R]);
|
|
||||||
false ->
|
|
||||||
log(info, "Failed to copy to clipboard")
|
|
||||||
end,
|
|
||||||
ok = wxClipboard:close(CB);
|
|
||||||
false ->
|
|
||||||
log(info, "Failed to acquire the clipboard.")
|
|
||||||
end.
|
|
||||||
|
|
||||||
|
|
||||||
www(State = #s{id = {_, #w{wx = ID_T}}, j = J}) ->
|
www(State = #s{id = {_, #w{wx = ID_T}}, j = J}) ->
|
||||||
case wxStaticText:getLabel(ID_T) of
|
case wxStaticText:getLabel(ID_T) of
|
||||||
|
|||||||
@ -7,7 +7,8 @@
|
|||||||
|
|
||||||
-export([is_int/1,
|
-export([is_int/1,
|
||||||
mono_text/2, mono_text/3,
|
mono_text/2, mono_text/3,
|
||||||
button/2, button/3]).
|
button/2, button/3,
|
||||||
|
copy_to_clipboard/1]).
|
||||||
|
|
||||||
-include("$zx_include/zx_logger.hrl").
|
-include("$zx_include/zx_logger.hrl").
|
||||||
-include("gd.hrl").
|
-include("gd.hrl").
|
||||||
@ -76,3 +77,24 @@ button(Parent, Label) ->
|
|||||||
button(Parent, Name, Label) ->
|
button(Parent, Name, Label) ->
|
||||||
Button = wxButton:new(Parent, ?wxID_ANY, [{label, Label}]),
|
Button = wxButton:new(Parent, ?wxID_ANY, [{label, Label}]),
|
||||||
#w{name = Name, id = wxButton:getId(Button), wx = Button}.
|
#w{name = Name, id = wxButton:getId(Button), wx = Button}.
|
||||||
|
|
||||||
|
|
||||||
|
-spec copy_to_clipboard(String) -> ok
|
||||||
|
when String :: unicode:charlist().
|
||||||
|
|
||||||
|
copy_to_clipboard(String) ->
|
||||||
|
CB = wxClipboard:get(),
|
||||||
|
case wxClipboard:open(CB) of
|
||||||
|
true ->
|
||||||
|
Text = wxTextDataObject:new([{text, String}]),
|
||||||
|
case wxClipboard:setData(CB, Text) of
|
||||||
|
true ->
|
||||||
|
R = wxClipboard:flush(CB),
|
||||||
|
log(info, "String copied to system clipboard. Flushed: ~p", [R]);
|
||||||
|
false ->
|
||||||
|
log(info, "Failed to copy to clipboard")
|
||||||
|
end,
|
||||||
|
ok = wxClipboard:close(CB);
|
||||||
|
false ->
|
||||||
|
log(info, "Failed to acquire the clipboard.")
|
||||||
|
end.
|
||||||
|
|||||||
@ -32,7 +32,9 @@
|
|||||||
gas = #w{} :: #w{},
|
gas = #w{} :: #w{},
|
||||||
amount = #w{} :: #w{},
|
amount = #w{} :: #w{},
|
||||||
action = #w{} :: #w{},
|
action = #w{} :: #w{},
|
||||||
|
tx_data = none :: none | map(),
|
||||||
tx_hash = #w{} :: #w{},
|
tx_hash = #w{} :: #w{},
|
||||||
|
tx_info = none :: none | hz:transaction(),
|
||||||
out = #w{} :: #w{},
|
out = #w{} :: #w{},
|
||||||
copy = #w{} :: #w{}}).
|
copy = #w{} :: #w{}}).
|
||||||
|
|
||||||
@ -118,7 +120,8 @@ init({Prefs, {FunName, FunType}, ConID, Build, Selected, Keys}) ->
|
|||||||
true = wxFrame:show(Frame),
|
true = wxFrame:show(Frame),
|
||||||
State =
|
State =
|
||||||
#s{wx = Wx, frame = Frame, j = J, prefs = Prefs,
|
#s{wx = Wx, frame = Frame, j = J, prefs = Prefs,
|
||||||
con_id = ConID, build = Build, args = Args,
|
con_id = ConID, build = Build,
|
||||||
|
args = Args, keypicker = KeyPicker,
|
||||||
ttl = TTL_T, gasprice = GasPriceT, gas = GasT, amount = AmountT,
|
ttl = TTL_T, gasprice = GasPriceT, gas = GasT, amount = AmountT,
|
||||||
action = Action, copy = Copy},
|
action = Action, copy = Copy},
|
||||||
{Frame, State}.
|
{Frame, State}.
|
||||||
@ -217,9 +220,12 @@ handle_info(Unexpected, State) ->
|
|||||||
|
|
||||||
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 = engage(State),
|
||||||
{noreply, NewState};
|
{noreply, NewState};
|
||||||
|
handle_event(#wx{event = #wxCommand{type = command_button_clicked}, id = ID},
|
||||||
|
State = #s{copy = #w{id = ID}}) ->
|
||||||
|
ok = copy(State),
|
||||||
|
{noreply, State};
|
||||||
handle_event(Event, State) ->
|
handle_event(Event, State) ->
|
||||||
ok = tell(info, "Unexpected event ~tp State: ~tp~n", [Event, State]),
|
ok = tell(info, "Unexpected event ~tp State: ~tp~n", [Event, State]),
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
@ -270,54 +276,81 @@ engage(State = #s{con_id = ConID, build = Build, fundef = {Name, Type}}, ChainID
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
% NEXT: Complete the signature and enter check_tx/2
|
params(#s{ttl = #w{wx = TTL},
|
||||||
|
gasprice = #w{wx = GasPrice},
|
||||||
|
gas = #w{wx = Gas},
|
||||||
|
amount = #w{wx = Amount},
|
||||||
|
}) ->
|
||||||
|
|
||||||
|
|
||||||
|
args(#s{args = ArgFields}) ->
|
||||||
|
|
||||||
|
|
||||||
deploy(State, ChainID, CallerID, CreateTX) ->
|
deploy(State, ChainID, CallerID, CreateTX) ->
|
||||||
SignedTX = hz:sign_tx(CreateTX, SecKey, ChainID),
|
case gd_con:sign_tx(ChainID, CallerID, CreateTX) of
|
||||||
tell(info, "SignedTX: ~p", [SignedTX]),
|
{ok, SignedTX} -> deploy2(State, SignedTX);
|
||||||
case hz:post_tx(SignedTX) of
|
Error -> handle_troubling(State, Error)
|
||||||
{ok, Data = #{"tx_hash" := TXHash}} ->
|
|
||||||
ok = tell("Contract deploy TX succeded with: ~p", [TXHash]),
|
|
||||||
do_deploy3(Data);
|
|
||||||
{ok, WTF} ->
|
|
||||||
gd_v_devman:trouble({error, WTF});
|
|
||||||
Error ->
|
|
||||||
gd_v_devman:trouble(Error)
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
do_deploy3(#{"tx_hash" := TXHash}) ->
|
deploy2(State, SignedTX) ->
|
||||||
case hz:tx_info(TXHash) of
|
case hz:post_tx(SignedTX) of
|
||||||
{ok, #{"call_info" := #{"return_type" := "ok", "contract_id" := ConID}}} ->
|
{ok, Data} -> check_tx(State#s{tx_data = Data});
|
||||||
gd_v_devman:open_contract(ConID);
|
{ok, WTF} -> handle_troubling(State, {error, WTF});
|
||||||
{error, "Tx not mined"} ->
|
Error -> handle_troubling(State, Error)
|
||||||
gd_v_devman:trouble({tx_hash, TXHash});
|
|
||||||
{ok, Reason = #{"call_info" := #{"return_type" := "revert"}}} ->
|
|
||||||
gd_v_devman:trouble({error, Reason});
|
|
||||||
Error ->
|
|
||||||
gd_v_devman:trouble(Error)
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
do_call(State, ChainID, CallerID, UnsignedTX) ->
|
do_call(State, ChainID, CallerID, UnsignedTX) ->
|
||||||
case gd_con:sign_call(ChainID, CallerID, UnsignedTX) of
|
case gd_con:sign_call(ChainID, CallerID, UnsignedTX) of
|
||||||
{ok, SignedTX} -> do_call(State, SignedTX);
|
{ok, SignedTX} -> do_call2(State, SignedTX);
|
||||||
Error -> handle_troubling(State, Error)
|
Error -> handle_troubling(State, Error)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
do_call(State, SignedTX) ->
|
do_call2(State, SignedTX) ->
|
||||||
case hz:post_tx(SignedTX) of
|
case hz:post_tx(SignedTX) of
|
||||||
{ok, TX_Hash} ->
|
{ok, Data} -> check_tx(SDtate = #s{tx_data = Data});
|
||||||
|
Error -> handle_troubling(State, Error)
|
||||||
|
end.
|
||||||
|
|
||||||
do_dry_run(State, ConID, TX) ->
|
do_dry_run(State, ConID, TX) ->
|
||||||
case hz:dry_run(TX) of
|
case hz:dry_run(TX) of
|
||||||
{ok, Result} -> gd_v_devman:dryrun_result(ConID, Result);
|
{ok, Result} -> gd_v_devman:dryrun_result(ConID, Result);
|
||||||
Other -> gd_v_devmam:trouble({error, ConID, Other})
|
Other -> gd_v_devmam:trouble({error, ConID, Other})
|
||||||
end.
|
end.
|
||||||
ok = gd_con:dry_run(ConID, TX),
|
|
||||||
|
|
||||||
|
check_tx(State = #s{tx_data = #{"tx_hash" := TXHash} = TXData, tx_info = none}) ->
|
||||||
|
ok = tell("TXData: ~p", [TXData]),
|
||||||
|
case hz:tx_info(TXHash) of
|
||||||
|
{ok, Info = #{"call_info" := #{"return_type" := "ok", "contract_id" := ConID}}} ->
|
||||||
|
ok = gd_v_devman:open_contract(ConID),
|
||||||
|
update_info(State#s{tx_info = Info});
|
||||||
|
{error, "Tx not mined"} ->
|
||||||
|
handle_troubling(State, {error, not_mined});
|
||||||
|
{ok, Reason = #{"call_info" := #{"return_type" := "revert"}}} ->
|
||||||
|
handle_troubling(State, {error, Reason});
|
||||||
|
Error ->
|
||||||
|
handle_troubling(State, Error)
|
||||||
|
end;
|
||||||
|
check_tx(State = #s{tx_info = TXInfo}) ->
|
||||||
|
ok = tell("Nothing to check"),
|
||||||
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(State = #s{tx_info = none}) ->
|
||||||
|
ok;
|
||||||
|
copy(State = #s{out = #w{wx = Out}}) ->
|
||||||
|
Output = wxStaticText:getLabel(Out),
|
||||||
|
gd_lib:copy_to_clipboard(Output).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
textify({integer, _, _}) -> "int";
|
textify({integer, _, _}) -> "int";
|
||||||
textify({boolean, _, _}) -> "bool";
|
textify({boolean, _, _}) -> "bool";
|
||||||
textify({{bytes, [I]}, _, _}) -> io_lib:format("bytes(~w)", [I]);
|
textify({{bytes, [I]}, _, _}) -> io_lib:format("bytes(~w)", [I]);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user