Compare commits
71 Commits
b8a31e994f
...
call500
| Author | SHA1 | Date | |
|---|---|---|---|
| c6486408cb | |||
| 903a32931d | |||
| cfafa27c2f | |||
| 46537a896f | |||
| 97589a1da5 | |||
| e5db26ab4c | |||
| 28f4a20bc0 | |||
| 6f9555a7c9 | |||
| 0c9e9805f0 | |||
| 115ca656ba | |||
| 5a745af71b | |||
| 1c59ed413a | |||
| ca933a33db | |||
| b4dbf21c41 | |||
| 41bd9eeacd | |||
| b071467faa | |||
| 8b390f8d82 | |||
| 2a52516fd3 | |||
| 223552324f | |||
| ae8c659c03 | |||
| 90d99e1eca | |||
| ac18ecc916 | |||
| d1ee4c6a24 | |||
| 0a671e7c9c | |||
| 7008195090 | |||
| 24ce75f520 | |||
| fadc252fb2 | |||
| a4db8d9a95 | |||
| acd84d65a8 | |||
| 9365c33351 | |||
| 9fa365e83f | |||
| 713650f88b | |||
| ae17d21f4f | |||
| fcf44f55a1 | |||
| 3a570f000e | |||
| 34a73a8e99 | |||
| df44118463 | |||
| f9cb72598f | |||
| 66f5795c49 | |||
| d2d9ae613e | |||
| 2a52b593bb | |||
| e10236214d | |||
| b0b3392c91 | |||
| 7697417dd8 | |||
| 3e638cd100 | |||
| 9ea34f43bd | |||
| 347aec2e46 | |||
| d59278a26c | |||
| 07875ab0e0 | |||
| 03b1f31935 | |||
| 99669a50c7 | |||
| 52994a12cb | |||
| 8a8bee0bbd | |||
| 39b2e48f68 | |||
| 638c88f900 | |||
| d9acde1b83 | |||
| 6a8c4fe1e1 | |||
| d70f5bb389 | |||
| d7a8a81fa9 | |||
| 5a4c934d10 | |||
| c59ef4b14e | |||
| bd047a6a46 | |||
| 76f9d074a9 | |||
| 07628a71b3 | |||
| 363dfaf271 | |||
| 25550cca32 | |||
| c452604f4b | |||
| 4446357437 | |||
| d8b8fee232 | |||
| 6a1c8ecf62 | |||
| b4ea4bdf10 |
+4
-4
@@ -3,8 +3,8 @@
|
|||||||
{registered,[]},
|
{registered,[]},
|
||||||
{included_applications,[]},
|
{included_applications,[]},
|
||||||
{applications,[stdlib,kernel,sasl,ssl]},
|
{applications,[stdlib,kernel,sasl,ssl]},
|
||||||
{vsn,"0.7.0"},
|
{vsn,"0.9.0"},
|
||||||
{modules,[gajudesk,gd_con,gd_grids,gd_gui,gd_jt,
|
{modules,[gajudesk,gd_con,gd_grids,gd_gui,gd_jt,gd_lib,
|
||||||
gd_sophia_editor,gd_sup,gd_v,gd_v_devman,gd_v_netman,
|
gd_m_spend,gd_m_wallet_importer,gd_sophia_editor,
|
||||||
gd_v_wallman]},
|
gd_sup,gd_v,gd_v_devman,gd_v_netman,gd_v_wallman]},
|
||||||
{mod,{gajudesk,[]}}]}.
|
{mod,{gajudesk,[]}}]}.
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
% Widgets
|
||||||
|
-record(w,
|
||||||
|
{name = none :: string() | atom() | {FunName :: binary(), call | dryr},
|
||||||
|
id = 0 :: integer(),
|
||||||
|
wx = none :: none | wx:wx_object()}).
|
||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
%%% @end
|
%%% @end
|
||||||
|
|
||||||
-module(gajudesk).
|
-module(gajudesk).
|
||||||
-vsn("0.7.0").
|
-vsn("0.9.0").
|
||||||
-behavior(application).
|
-behavior(application).
|
||||||
-author("Craig Everett <craigeverett@qpq.swiss>").
|
-author("Craig Everett <craigeverett@qpq.swiss>").
|
||||||
-copyright("QPQ AG <info@qpq.swiss>").
|
-copyright("QPQ AG <info@qpq.swiss>").
|
||||||
|
|||||||
+427
-265
@@ -3,7 +3,7 @@
|
|||||||
%%% @end
|
%%% @end
|
||||||
|
|
||||||
-module(gd_con).
|
-module(gd_con).
|
||||||
-vsn("0.7.0").
|
-vsn("0.9.0").
|
||||||
-author("Craig Everett <craigeverett@qpq.swiss>").
|
-author("Craig Everett <craigeverett@qpq.swiss>").
|
||||||
-copyright("QPQ AG <info@qpq.swiss>").
|
-copyright("QPQ AG <info@qpq.swiss>").
|
||||||
-license("GPL-3.0-or-later").
|
-license("GPL-3.0-or-later").
|
||||||
@@ -14,17 +14,19 @@
|
|||||||
selected/1, network/0,
|
selected/1, network/0,
|
||||||
password/2,
|
password/2,
|
||||||
refresh/0,
|
refresh/0,
|
||||||
nonce/1, spend/1, chain/1, grids/1, sign_mess/1, sign_tx/1, sign_call/3, dry_run/2,
|
nonce/1, spend/1, chain_id/0, grids/1,
|
||||||
deploy/3,
|
sign_mess/1, sign_binary/1, sign_tx/1, sign_call/3,
|
||||||
|
deploy/1, prompt_call/3, list_calls/0,
|
||||||
|
open_contract/1, open_contract/2, show_call/2, show_call/3,
|
||||||
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([encrypt/2, decrypt/2]).
|
-export([encrypt/2, decrypt/2]).
|
||||||
-export([save/2]).
|
-export([save/2]).
|
||||||
-export([start_link/0, stop/0]).
|
-export([start_link/0, stop/0]).
|
||||||
-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_call/3, handle_cast/2, handle_info/2]).
|
||||||
-include("$zx_include/zx_logger.hrl").
|
-include("$zx_include/zx_logger.hrl").
|
||||||
|
|
||||||
-include("gd.hrl").
|
-include("gd.hrl").
|
||||||
|
|
||||||
|
|
||||||
@@ -40,7 +42,7 @@
|
|||||||
-record(s,
|
-record(s,
|
||||||
{version = 1 :: integer(),
|
{version = 1 :: integer(),
|
||||||
window = none :: none | wx:wx_object(),
|
window = none :: none | wx:wx_object(),
|
||||||
timer = none :: none | reference(),
|
timer = none :: none | {Timer :: reference(), MS :: pos_integer()},
|
||||||
tasks = [] :: [#ui{}],
|
tasks = [] :: [#ui{}],
|
||||||
selected = 0 :: non_neg_integer(),
|
selected = 0 :: non_neg_integer(),
|
||||||
wallet = none :: none | #wallet{},
|
wallet = none :: none | #wallet{},
|
||||||
@@ -72,7 +74,7 @@ show_ui(Name) ->
|
|||||||
Result :: ok | {error, Reason :: term()}.
|
Result :: ok | {error, Reason :: term()}.
|
||||||
|
|
||||||
open_wallet(Path, Phrase) ->
|
open_wallet(Path, Phrase) ->
|
||||||
gen_server:call(?MODULE, {open_wallet, Path, Phrase}).
|
gen_server:call(?MODULE, {open_wallet, Path, Phrase}, infinity).
|
||||||
|
|
||||||
|
|
||||||
-spec close_wallet() -> ok.
|
-spec close_wallet() -> ok.
|
||||||
@@ -152,11 +154,11 @@ spend(TX) ->
|
|||||||
gen_server:cast(?MODULE, {spend, TX}).
|
gen_server:cast(?MODULE, {spend, TX}).
|
||||||
|
|
||||||
|
|
||||||
-spec chain(ID) -> ok
|
-spec chain_id() -> {ok, ID}
|
||||||
when ID :: string().
|
when ID :: binary().
|
||||||
|
|
||||||
chain(ID) ->
|
chain_id() ->
|
||||||
gen_server:cast(?MODULE, {chain, ID}).
|
gen_server:call(?MODULE, chain_id).
|
||||||
|
|
||||||
|
|
||||||
-spec grids(string()) -> ok.
|
-spec grids(string()) -> ok.
|
||||||
@@ -172,6 +174,13 @@ sign_mess(Request) ->
|
|||||||
gen_server:cast(?MODULE, {sign_mess, Request}).
|
gen_server:cast(?MODULE, {sign_mess, Request}).
|
||||||
|
|
||||||
|
|
||||||
|
-spec sign_binary(Request) -> ok
|
||||||
|
when Request :: map().
|
||||||
|
|
||||||
|
sign_binary(Request) ->
|
||||||
|
gen_server:cast(?MODULE, {sign_binary, Request}).
|
||||||
|
|
||||||
|
|
||||||
-spec sign_tx(Request) -> ok
|
-spec sign_tx(Request) -> ok
|
||||||
when Request :: map().
|
when Request :: map().
|
||||||
|
|
||||||
@@ -179,38 +188,92 @@ sign_tx(Request) ->
|
|||||||
gen_server:cast(?MODULE, {sign_tx, Request}).
|
gen_server:cast(?MODULE, {sign_tx, Request}).
|
||||||
|
|
||||||
|
|
||||||
-spec sign_call(ConID, PubKey, TX) -> ok
|
-spec sign_call(ChainID, PubKey, TX) -> Result
|
||||||
when ConID :: gajudesk:id(),
|
when ChainID :: binary(),
|
||||||
PubKey :: gajudesk:id(),
|
PubKey :: gajudesk:id(),
|
||||||
TX :: binary().
|
TX :: binary(),
|
||||||
|
Result :: {ok, SignedTX :: binary()}
|
||||||
|
| {error, Reason :: term()}.
|
||||||
|
|
||||||
sign_call(ConID, PubKey, TX) ->
|
sign_call(ChainID, PubKey, TX) ->
|
||||||
gen_server:cast(?MODULE, {sign_call, ConID, PubKey, TX}).
|
gen_server:call(?MODULE, {sign_call, ChainID, PubKey, TX}).
|
||||||
|
|
||||||
|
|
||||||
-spec dry_run(ConID, TX) -> ok
|
-spec deploy(Build) -> ok
|
||||||
when ConID :: gajudesk:id(),
|
when Build :: map().
|
||||||
TX :: binary().
|
|
||||||
|
|
||||||
dry_run(ConID, TX) ->
|
deploy(Build) ->
|
||||||
gen_server:cast(?MODULE, {dry_run, ConID, TX}).
|
gen_server:cast(?MODULE, {deploy, Build}).
|
||||||
|
|
||||||
|
|
||||||
-spec deploy(Build, Params, InitArgs) -> Result
|
-spec prompt_call(FunDef, ConID, Build) -> ok
|
||||||
when Build :: map(),
|
when FunDef :: {FunName, FunType},
|
||||||
Params :: {PK :: gajudesk:id(),
|
FunName :: string(),
|
||||||
Nonce :: non_neg_integer(),
|
FunType :: call | dryr | init,
|
||||||
TTL :: pos_integer(),
|
ConID :: none | string(),
|
||||||
GasP :: pos_integer(),
|
Build :: map(). % Fixme
|
||||||
Gas :: pos_integer(),
|
|
||||||
Amount :: pos_integer()},
|
|
||||||
InitArgs :: [Arg :: string()],
|
|
||||||
Result :: {ok, TX_Hash :: gajudesk:id()}
|
|
||||||
| {error, Reason},
|
|
||||||
Reason :: term(). % FIXME
|
|
||||||
|
|
||||||
deploy(Build, Params, InitArgs) ->
|
prompt_call(FunDef, ConID, Build) ->
|
||||||
gen_server:cast(?MODULE, {deploy, Build, Params, InitArgs}).
|
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 open_contract(ConID) -> ok
|
||||||
|
when ConID :: string().
|
||||||
|
%% @doc
|
||||||
|
%% @equiv open_contract(ConID, true).
|
||||||
|
|
||||||
|
open_contract(ConID) ->
|
||||||
|
open_contract(ConID, true).
|
||||||
|
|
||||||
|
|
||||||
|
-spec open_contract(ConID, DevmanToFront) -> ok
|
||||||
|
when ConID :: string(),
|
||||||
|
DevmanToFront :: boolean().
|
||||||
|
%% @doc
|
||||||
|
%% Ask the controller to tell the devman interface to open a deployed contract.
|
||||||
|
%% The controller will start the devman if it isn't already on.
|
||||||
|
|
||||||
|
open_contract(ConID, DevmanToFront) when is_binary(ConID) ->
|
||||||
|
gen_server:cast(?MODULE, {open_contract, ConID, DevmanToFront});
|
||||||
|
open_contract(ConID, DevmanToFront) when is_list(ConID) ->
|
||||||
|
open_contract(list_to_binary(ConID), DevmanToFront).
|
||||||
|
|
||||||
|
|
||||||
|
-spec show_call(ConID, Info) -> ok
|
||||||
|
when ConID :: string(),
|
||||||
|
Info :: map().
|
||||||
|
%% @doc
|
||||||
|
%% @equiv show_call(ConID, Info, true).
|
||||||
|
|
||||||
|
show_call(ConID, Info) ->
|
||||||
|
show_call(ConID, Info, true).
|
||||||
|
|
||||||
|
|
||||||
|
-spec show_call(ConID, Info, DevmanToFront) -> ok
|
||||||
|
when ConID :: string(),
|
||||||
|
Info :: map(),
|
||||||
|
DevmanToFront :: boolean().
|
||||||
|
%% @doc
|
||||||
|
%% Ask the controller to tell the devman interface to dislpay the result of a call
|
||||||
|
%% to the indicated contract. Opens the contract in question if it isn't alread open.
|
||||||
|
%% Starts the devman if it isn't already running.
|
||||||
|
|
||||||
|
show_call(ConID, Info, DevmanToFront) when is_binary(ConID) ->
|
||||||
|
gen_server:cast(?MODULE, {show_call, ConID, Info, DevmanToFront});
|
||||||
|
show_call(ConID, Info, DevmanToFront) when is_list(ConID) ->
|
||||||
|
show_call(list_to_binary(ConID), Info, DevmanToFront).
|
||||||
|
|
||||||
|
|
||||||
-spec make_key(Type, Size, Name, Seed, Encoding, Transform) -> ok
|
-spec make_key(Type, Size, Name, Seed, Encoding, Transform) -> ok
|
||||||
@@ -270,6 +333,8 @@ list_keys() ->
|
|||||||
gen_server:call(?MODULE, list_keys).
|
gen_server:call(?MODULE, list_keys).
|
||||||
|
|
||||||
|
|
||||||
|
%%% Network functions
|
||||||
|
|
||||||
-spec add_node(New) -> ok
|
-spec add_node(New) -> ok
|
||||||
when New :: #node{}.
|
when New :: #node{}.
|
||||||
|
|
||||||
@@ -284,6 +349,25 @@ set_sole_node(TheOneTrueNode) ->
|
|||||||
gen_server:cast(?MODULE, {set_sole_node, TheOneTrueNode}).
|
gen_server:cast(?MODULE, {set_sole_node, TheOneTrueNode}).
|
||||||
|
|
||||||
|
|
||||||
|
-spec tic(Interval) -> ok
|
||||||
|
when Interval :: pos_integer() | stop.
|
||||||
|
|
||||||
|
tic(stop) ->
|
||||||
|
gen_server:cast(?MODULE, {tic, stop});
|
||||||
|
tic(0) ->
|
||||||
|
gen_server:cast(?MODULE, {tic, stop});
|
||||||
|
tic(Interval) when Interval ->
|
||||||
|
gen_server:cast(?MODULE, {tic, Interval}).
|
||||||
|
|
||||||
|
|
||||||
|
-spec update_balance(AccountID, Pucks) -> ok
|
||||||
|
when AccountID :: gajudesk:id(),
|
||||||
|
Pucks :: non_neg_integer().
|
||||||
|
|
||||||
|
update_balance(AccountID, Pucks) ->
|
||||||
|
gen_server:cast(?MODULE, {update_balance, AccountID, Pucks}).
|
||||||
|
|
||||||
|
|
||||||
%%% Lifecycle functions
|
%%% Lifecycle functions
|
||||||
-spec stop() -> ok.
|
-spec stop() -> ok.
|
||||||
|
|
||||||
@@ -322,26 +406,30 @@ start_link() ->
|
|||||||
init(none) ->
|
init(none) ->
|
||||||
ok = log(info, "Starting"),
|
ok = log(info, "Starting"),
|
||||||
process_flag(sensitive, true),
|
process_flag(sensitive, true),
|
||||||
Prefs = read_prefs(),
|
{FirstRun, Prefs} = read_prefs(),
|
||||||
GUI_Prefs = maps:get(gd_gui, Prefs, #{}),
|
GUI_Prefs = maps:get(gd_gui, Prefs, #{}),
|
||||||
Window = gd_gui:start_link(GUI_Prefs),
|
Window = gd_gui:start_link(GUI_Prefs),
|
||||||
Wallets = get_prefs(wallets, Prefs, []),
|
Wallets = get_prefs(wallets, Prefs, []),
|
||||||
T = erlang:send_after(tic(), self(), tic),
|
ok = hz:timeout(default_tic()),
|
||||||
State = #s{window = Window, timer = T, wallets = Wallets, prefs = Prefs},
|
State = #s{window = Window, wallets = Wallets, prefs = Prefs},
|
||||||
NewState = do_show_ui(gd_v_wallman, State),
|
NewState = do_show_ui(gd_v_wallman, State),
|
||||||
ok = gd_v_wallman:first_run(),
|
ok =
|
||||||
|
case FirstRun of
|
||||||
|
false -> gd_v_wallman:to_front();
|
||||||
|
true -> gd_v_wallman:first_run()
|
||||||
|
end,
|
||||||
{ok, NewState}.
|
{ok, NewState}.
|
||||||
|
|
||||||
|
|
||||||
read_prefs() ->
|
read_prefs() ->
|
||||||
case file:consult(prefs_path()) of
|
case file:consult(prefs_path()) of
|
||||||
{ok, Prefs} -> proplists:to_map(Prefs);
|
{ok, Prefs} -> {false, proplists:to_map(Prefs)};
|
||||||
_ -> #{}
|
_ -> {true, #{}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
tic() ->
|
default_tic() ->
|
||||||
6000.
|
10_000.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -367,6 +455,12 @@ handle_call(list_keys, _, State) ->
|
|||||||
handle_call({nonce, ID}, _, State) ->
|
handle_call({nonce, ID}, _, State) ->
|
||||||
Response = do_nonce(ID),
|
Response = do_nonce(ID),
|
||||||
{reply, Response, State};
|
{reply, Response, State};
|
||||||
|
handle_call(chain_id, _, State) ->
|
||||||
|
Response = do_chain_id(State),
|
||||||
|
{reply, Response, State};
|
||||||
|
handle_call({sign_call, ChainID, PubKey, TX}, _, State) ->
|
||||||
|
Response = do_sign_call(State, ChainID, PubKey, TX),
|
||||||
|
{reply, Response, State};
|
||||||
handle_call({open_wallet, Path, Phrase}, _, State) ->
|
handle_call({open_wallet, Path, Phrase}, _, State) ->
|
||||||
{Response, NewState} = do_open_wallet(Path, Phrase, State),
|
{Response, NewState} = do_open_wallet(Path, Phrase, State),
|
||||||
{reply, Response, NewState};
|
{reply, Response, NewState};
|
||||||
@@ -422,27 +516,24 @@ handle_cast(refresh, State) ->
|
|||||||
handle_cast({spend, TX}, State) ->
|
handle_cast({spend, TX}, State) ->
|
||||||
ok = do_spend(TX, State),
|
ok = do_spend(TX, State),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
handle_cast({chain, ID}, State) ->
|
|
||||||
NewState = do_chain(ID, State),
|
|
||||||
{noreply, NewState};
|
|
||||||
handle_cast({grids, String}, State) ->
|
handle_cast({grids, String}, State) ->
|
||||||
ok = do_grids(String),
|
ok = do_grids(String),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
handle_cast({sign_mess, Request}, State) ->
|
handle_cast({sign_mess, Request}, State) ->
|
||||||
ok = do_sign_mess(Request, State),
|
ok = do_sign_mess(Request, State),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
|
handle_cast({sign_binary, Request}, State) ->
|
||||||
|
ok = do_sign_binary(Request, State),
|
||||||
|
{noreply, State};
|
||||||
handle_cast({sign_tx, Request}, State) ->
|
handle_cast({sign_tx, Request}, State) ->
|
||||||
ok = do_sign_tx(Request, State),
|
ok = do_sign_tx(Request, State),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
handle_cast({sign_call, ConID, PubKey, TX}, State) ->
|
handle_cast({deploy, Build}, State) ->
|
||||||
ok = do_sign_call(State, ConID, PubKey, TX),
|
ok = do_deploy(Build, State),
|
||||||
{noreply, State};
|
|
||||||
handle_cast({dry_run, ConID, TX}, State) ->
|
|
||||||
ok = do_dry_run(ConID, TX),
|
|
||||||
{noreply, State};
|
|
||||||
handle_cast({deploy, Build, Params, InitArgs}, State) ->
|
|
||||||
ok = do_deploy(Build, Params, InitArgs, State),
|
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
|
handle_cast({prompt_call, FunDef, ConID, Build}, State) ->
|
||||||
|
NewState = do_prompt_call(FunDef, ConID, Build, State),
|
||||||
|
{noreply, NewState};
|
||||||
handle_cast({make_key, Name, Seed, Encoding, Transform}, State) ->
|
handle_cast({make_key, Name, Seed, Encoding, Transform}, State) ->
|
||||||
NewState = do_make_key(Name, Seed, Encoding, Transform, State),
|
NewState = do_make_key(Name, Seed, Encoding, Transform, State),
|
||||||
{noreply, NewState};
|
{noreply, NewState};
|
||||||
@@ -455,12 +546,21 @@ handle_cast({rename_key, ID, NewName}, State) ->
|
|||||||
handle_cast({drop_key, ID}, State) ->
|
handle_cast({drop_key, ID}, State) ->
|
||||||
NewState = do_drop_key(ID, State),
|
NewState = do_drop_key(ID, State),
|
||||||
{noreply, NewState};
|
{noreply, NewState};
|
||||||
|
handle_cast({open_contract, ConID, ToFront}, State) ->
|
||||||
|
NewState = do_open_contract(ConID, ToFront, State),
|
||||||
|
{noreply, NewState};
|
||||||
|
handle_cast({show_call, ConID, Info, ToFront}, State) ->
|
||||||
|
NewState = do_show_call(ConID, Info, ToFront, State),
|
||||||
|
{noreply, NewState};
|
||||||
handle_cast({add_node, New}, State) ->
|
handle_cast({add_node, New}, State) ->
|
||||||
NewState = do_add_node(New, State),
|
NewState = do_add_node(New, State),
|
||||||
{noreply, NewState};
|
{noreply, NewState};
|
||||||
handle_cast({set_sole_node, TheOneTrueNode}, State) ->
|
handle_cast({set_sole_node, TheOneTrueNode}, State) ->
|
||||||
NewState = do_set_sole_node(TheOneTrueNode, State),
|
NewState = do_set_sole_node(TheOneTrueNode, State),
|
||||||
{noreply, NewState};
|
{noreply, NewState};
|
||||||
|
handle_cast({tic, Interval}, State) ->
|
||||||
|
NewState = do_tic(Interval, State),
|
||||||
|
{noreply, NewState};
|
||||||
handle_cast(stop, State) ->
|
handle_cast(stop, State) ->
|
||||||
NewState = do_stop(State),
|
NewState = do_stop(State),
|
||||||
{noreply, NewState};
|
{noreply, NewState};
|
||||||
@@ -478,7 +578,7 @@ handle_cast(Unexpected, State) ->
|
|||||||
%% See: http://erlang.org/doc/man/gen_server.html#Module:handle_info-2
|
%% See: http://erlang.org/doc/man/gen_server.html#Module:handle_info-2
|
||||||
|
|
||||||
handle_info(tic, State) ->
|
handle_info(tic, State) ->
|
||||||
NewState = do_tic(State),
|
NewState = handle_tic(State),
|
||||||
{noreply, NewState};
|
{noreply, NewState};
|
||||||
handle_info({show_ui, Name}, State) ->
|
handle_info({show_ui, Name}, State) ->
|
||||||
NewState = do_show_ui(Name, State),
|
NewState = do_show_ui(Name, State),
|
||||||
@@ -513,23 +613,35 @@ code_change(_, State, _) ->
|
|||||||
|
|
||||||
terminate(Reason, _) ->
|
terminate(Reason, _) ->
|
||||||
ok = log(info, "Reason: ~p,", [Reason]),
|
ok = log(info, "Reason: ~p,", [Reason]),
|
||||||
case whereis(gmc_con) of
|
zx:stop().
|
||||||
undefined ->
|
|
||||||
zx:stop();
|
|
||||||
PID ->
|
|
||||||
ok = log(info, "gd_con found at: ~p", [PID]),
|
|
||||||
application:stop(gajumine)
|
|
||||||
end.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%%% GUI doers
|
%%% GUI doers
|
||||||
|
|
||||||
|
-spec do_show_ui(Name, State) -> NewState
|
||||||
|
when Name :: ui_name() | term(),
|
||||||
|
State :: state(),
|
||||||
|
NewState :: state().
|
||||||
|
|
||||||
do_show_ui(Name, State = #s{tasks = Tasks, prefs = Prefs}) ->
|
do_show_ui(Name, State) ->
|
||||||
|
do_show_ui(Name, true, State).
|
||||||
|
|
||||||
|
|
||||||
|
-spec do_show_ui(Name, ToFront, State) -> NewState
|
||||||
|
when Name :: ui_name() | term(),
|
||||||
|
ToFront :: boolean(),
|
||||||
|
State :: state(),
|
||||||
|
NewState :: state().
|
||||||
|
|
||||||
|
do_show_ui(Name, ToFront, State = #s{tasks = Tasks, prefs = Prefs}) ->
|
||||||
case lists:keyfind(Name, #ui.name, Tasks) of
|
case lists:keyfind(Name, #ui.name, Tasks) of
|
||||||
#ui{wx = Win} ->
|
#ui{wx = Win} ->
|
||||||
ok = Name:to_front(Win),
|
ok =
|
||||||
|
case ToFront of
|
||||||
|
true -> Name:to_front(Win);
|
||||||
|
false -> ok
|
||||||
|
end,
|
||||||
State;
|
State;
|
||||||
false ->
|
false ->
|
||||||
TaskPrefs = maps:get(Name, Prefs, #{}),
|
TaskPrefs = maps:get(Name, Prefs, #{}),
|
||||||
@@ -554,9 +666,11 @@ task_data(gd_v_devman, #s{}) ->
|
|||||||
|
|
||||||
%%% Network operations
|
%%% Network operations
|
||||||
|
|
||||||
do_chain(_, State) ->
|
% NOTE: This is temporary. As GD becomes more chain aware this will move.
|
||||||
tell("Would be doing chain in do_chain/2 here"),
|
do_chain_id(#s{wallet = #wallet{chain_id = ChainID}}) ->
|
||||||
State.
|
{ok, ChainID};
|
||||||
|
do_chain_id(_) ->
|
||||||
|
{error, no_chain}.
|
||||||
|
|
||||||
|
|
||||||
do_add_node(New, State) ->
|
do_add_node(New, State) ->
|
||||||
@@ -598,26 +712,31 @@ do_refresh(State = #s{wallet = #wallet{endpoint = Node}}) ->
|
|||||||
|
|
||||||
|
|
||||||
do_refresh2(ChainID, State = #s{wallet = W = #wallet{poas = POAs}}) ->
|
do_refresh2(ChainID, State = #s{wallet = W = #wallet{poas = POAs}}) ->
|
||||||
CheckBalance = check_balance(ChainID),
|
CheckBalance = check_balance(ChainID, "gaju"),
|
||||||
NewPOAs = lists:map(CheckBalance, POAs),
|
NewPOAs = lists:map(CheckBalance, POAs),
|
||||||
ok = gd_gui:show(NewPOAs),
|
ok = gd_gui:show(NewPOAs),
|
||||||
NewW = W#wallet{chain_id = ChainID, poas = NewPOAs},
|
NewW = W#wallet{chain_id = ChainID, poas = NewPOAs},
|
||||||
State#s{wallet = NewW}.
|
State#s{wallet = NewW}.
|
||||||
|
|
||||||
|
|
||||||
check_balance(ChainID) ->
|
check_balance(ChainID, Coin) ->
|
||||||
fun(This = #poa{id = ID}) ->
|
fun(This = #poa{id = ID, balances = Balances}) ->
|
||||||
|
#balance{dist = Dist} = lists:keyfind(Coin, #balance.coin, Balances),
|
||||||
|
Old = proplists:get_value(ChainID, Dist, 0),
|
||||||
Pucks =
|
Pucks =
|
||||||
case hz:acc(ID) of
|
case hz:acc(ID) of
|
||||||
{ok, #{"balance" := P}} -> P;
|
{ok, #{"balance" := Old}} -> Old;
|
||||||
{error, "Account not found"} -> 0
|
{ok, #{"balance" := New}} -> New;
|
||||||
|
{error, "Account not found"} -> 0;
|
||||||
|
{error, timeout} -> Old
|
||||||
end,
|
end,
|
||||||
Dist = [{ChainID, Pucks}],
|
NewDist = [{ChainID, Pucks}],
|
||||||
Gaju = #balance{coin = "gaju", total = Pucks, dist = Dist},
|
Gaju = #balance{coin = "gaju", total = Pucks, dist = NewDist},
|
||||||
This#poa{balances = [Gaju]}
|
This#poa{balances = [Gaju]}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ensure_hz_set(Node = #node{ip = IP, external = Port}) ->
|
ensure_hz_set(Node = #node{ip = IP, external = Port}) ->
|
||||||
case hz:chain_nodes() of
|
case hz:chain_nodes() of
|
||||||
[{IP, Port}] ->
|
[{IP, Port}] ->
|
||||||
@@ -679,23 +798,23 @@ do_grids_sig(JSON, URL) ->
|
|||||||
|
|
||||||
do_grids_sig2(Request = #{"grids" := 1, "type" := "message"}) ->
|
do_grids_sig2(Request = #{"grids" := 1, "type" := "message"}) ->
|
||||||
gd_gui:grids_mess_sig(Request);
|
gd_gui:grids_mess_sig(Request);
|
||||||
|
do_grids_sig2(Request = #{"grids" := 1, "type" := "binary"}) ->
|
||||||
|
gd_gui:grids_mess_sig(Request);
|
||||||
do_grids_sig2(Request = #{"grids" := 1, "type" := "tx"}) ->
|
do_grids_sig2(Request = #{"grids" := 1, "type" := "tx"}) ->
|
||||||
gd_gui:grids_mess_sig(Request);
|
gd_gui:grids_mess_sig(Request);
|
||||||
do_grids_sig2(WTF) ->
|
do_grids_sig2(WTF) ->
|
||||||
gd_gui:trouble({trash, WTF}).
|
gd_gui:trouble({trash, WTF}).
|
||||||
|
|
||||||
|
|
||||||
do_sign_mess(Request = #{"public_id" := ID, "payload" := Message},
|
do_sign_mess(Request = #{"public_id" := ID}, #s{wallet = #wallet{keys = Keys}}) ->
|
||||||
#s{wallet = #wallet{keys = Keys}}) ->
|
|
||||||
case lists:keyfind(ID, #key.id, Keys) of
|
case lists:keyfind(ID, #key.id, Keys) of
|
||||||
#key{pair = #{secret := SecKey}} ->
|
#key{pair = #{secret := SecKey}} -> do_sign_mess2(Request, SecKey);
|
||||||
Sig = base64:encode(hz:sign_message(list_to_binary(Message), SecKey)),
|
false -> gd_gui:trouble({bad_key, ID})
|
||||||
do_sign_mess2(Request#{"signature" => Sig});
|
|
||||||
false ->
|
|
||||||
gd_gui:trouble({bad_key, ID})
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
do_sign_mess2(Request = #{"url" := URL}) ->
|
do_sign_mess2(Request = #{"payload" := Message}, SecKey) ->
|
||||||
|
Sig = base64:encode(hz:sign_message(list_to_binary(Message), SecKey)),
|
||||||
|
SignedRequest = maps:put("signature", Sig, Request),
|
||||||
ResponseKeys =
|
ResponseKeys =
|
||||||
["grids",
|
["grids",
|
||||||
"chain",
|
"chain",
|
||||||
@@ -704,11 +823,31 @@ do_sign_mess2(Request = #{"url" := URL}) ->
|
|||||||
"public_id",
|
"public_id",
|
||||||
"payload",
|
"payload",
|
||||||
"signature"],
|
"signature"],
|
||||||
Response = zj:encode(maps:with(ResponseKeys, Request)),
|
post_grids_response(ResponseKeys, SignedRequest).
|
||||||
case httpc:request(post, {URL, [], "application/json", Response}, [], []) of
|
|
||||||
{ok, {{_, 200, _}, _, JSON}} -> log(info, "Signature posted: ~p", [JSON]);
|
|
||||||
{error, socket_closed_remotely} -> tell("Yep, closed remotely.");
|
do_sign_binary(Request = #{"public_id" := ID}, #s{wallet = #wallet{keys = Keys}}) ->
|
||||||
Error -> gd_gui:trouble(Error)
|
case lists:keyfind(ID, #key.id, Keys) of
|
||||||
|
#key{pair = #{secret := SecKey}} -> do_sign_binary2(Request, SecKey);
|
||||||
|
false -> gd_gui:trouble({bad_key, ID})
|
||||||
|
end.
|
||||||
|
|
||||||
|
do_sign_binary2(Request = #{"payload" := Payload}, SecKey) ->
|
||||||
|
case base64_decode(Payload) of
|
||||||
|
{ok, Binary} ->
|
||||||
|
Sig = base64:encode(hz:sign_binary(Binary, SecKey)),
|
||||||
|
SignedRequest = maps:put("signature", Sig, Request),
|
||||||
|
ResponseKeys =
|
||||||
|
["grids",
|
||||||
|
"chain",
|
||||||
|
"network_id",
|
||||||
|
"type",
|
||||||
|
"public_id",
|
||||||
|
"payload",
|
||||||
|
"signature"],
|
||||||
|
post_grids_response(ResponseKeys, SignedRequest);
|
||||||
|
Error ->
|
||||||
|
gd_gui:trouble(Error)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
@@ -719,12 +858,7 @@ do_sign_tx(Request = #{"public_id" := ID, "payload" := CallData, "network_id" :=
|
|||||||
#key{pair = #{secret := SecKey}} ->
|
#key{pair = #{secret := SecKey}} ->
|
||||||
BinaryTX = list_to_binary(CallData),
|
BinaryTX = list_to_binary(CallData),
|
||||||
SignedTX = hz:sign_tx(BinaryTX, SecKey, BinNID),
|
SignedTX = hz:sign_tx(BinaryTX, SecKey, BinNID),
|
||||||
do_sign_tx2(Request#{"signed" => true, "payload" := SignedTX});
|
SignedRequest = Request#{"signed" => true, "payload" := SignedTX},
|
||||||
false ->
|
|
||||||
gd_gui:trouble({bad_key, ID})
|
|
||||||
end.
|
|
||||||
|
|
||||||
do_sign_tx2(Request = #{"url" := URL}) ->
|
|
||||||
ResponseKeys =
|
ResponseKeys =
|
||||||
["grids",
|
["grids",
|
||||||
"chain",
|
"chain",
|
||||||
@@ -733,6 +867,13 @@ do_sign_tx2(Request = #{"url" := URL}) ->
|
|||||||
"public_id",
|
"public_id",
|
||||||
"payload",
|
"payload",
|
||||||
"signed"],
|
"signed"],
|
||||||
|
post_grids_response(ResponseKeys, SignedRequest);
|
||||||
|
false ->
|
||||||
|
gd_gui:trouble({bad_key, ID})
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
post_grids_response(ResponseKeys, Request = #{"url" := URL}) ->
|
||||||
Response = zj:encode(maps:with(ResponseKeys, Request)),
|
Response = zj:encode(maps:with(ResponseKeys, Request)),
|
||||||
case httpc:request(post, {URL, [], "application/json", Response}, [], []) of
|
case httpc:request(post, {URL, [], "application/json", Response}, [], []) of
|
||||||
{ok, {{_, 200, _}, _, JSON}} -> log(info, "Signed TX posted: ~p", [JSON]);
|
{ok, {{_, 200, _}, _, JSON}} -> log(info, "Signed TX posted: ~p", [JSON]);
|
||||||
@@ -741,41 +882,13 @@ do_sign_tx2(Request = #{"url" := URL}) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
do_sign_call(#s{wallet = #wallet{keys = Keys, chain_id = ChainID}},
|
do_sign_call(#s{wallet = #wallet{keys = Keys}}, ChainID, PubKey, TX) ->
|
||||||
ConID,
|
case lists:keyfind(PubKey, #key.id, Keys) of
|
||||||
PubKey,
|
#key{pair = #{secret := SecKey}} ->
|
||||||
TX) ->
|
|
||||||
#key{pair = #{secret := SecKey}} = lists:keyfind(PubKey, #key.id, Keys),
|
|
||||||
SignedTX = hz:sign_tx(TX, SecKey, ChainID),
|
SignedTX = hz:sign_tx(TX, SecKey, ChainID),
|
||||||
case hz:post_tx(SignedTX) of
|
{ok, SignedTX};
|
||||||
{ok, Data = #{"tx_hash" := TXHash}} ->
|
false ->
|
||||||
ok = tell("TX succeded with: ~p", [TXHash]),
|
{error, bad_key}
|
||||||
do_sign_call2(ConID, Data);
|
|
||||||
{ok, WTF} ->
|
|
||||||
gd_v_devman:trouble({error, WTF});
|
|
||||||
Error ->
|
|
||||||
gd_v_devman:trouble(Error)
|
|
||||||
end;
|
|
||||||
do_sign_call(_, _, _, _) ->
|
|
||||||
gd_v_devman:trouble({error, no_chain}).
|
|
||||||
|
|
||||||
do_sign_call2(ConID, #{"tx_hash" := TXHash}) ->
|
|
||||||
case hz:tx_info(TXHash) of
|
|
||||||
{ok, CallInfo = #{"call_info" := #{"return_type" := "ok"}}} ->
|
|
||||||
gd_v_devman:call_result(ConID, CallInfo);
|
|
||||||
{error, "Tx not mined"} ->
|
|
||||||
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.
|
|
||||||
|
|
||||||
|
|
||||||
do_dry_run(ConID, TX) ->
|
|
||||||
case hz:dry_run(TX) of
|
|
||||||
{ok, Result} -> gd_v_devman:dryrun_result(ConID, Result);
|
|
||||||
Other -> gd_v_devmam:trouble({error, ConID, Other})
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
@@ -800,7 +913,7 @@ do_spend(#spend_tx{sender_id = SenderID,
|
|||||||
Nonce,
|
Nonce,
|
||||||
Payload,
|
Payload,
|
||||||
NetworkID),
|
NetworkID),
|
||||||
tell(info, "Outcome: ~p", [Outcome]);
|
tell(info, "SpendTX Outcome: ~p", [Outcome]);
|
||||||
false ->
|
false ->
|
||||||
log(warning, "Tried do_spend with a bad key: ~p", [SenderID])
|
log(warning, "Tried do_spend with a bad key: ~p", [SenderID])
|
||||||
end.
|
end.
|
||||||
@@ -822,23 +935,31 @@ do_network(#s{wallet = #wallet{chain_id = ChainID}}) ->
|
|||||||
{ok, ChainID}.
|
{ok, ChainID}.
|
||||||
|
|
||||||
|
|
||||||
|
do_deploy(Build, State) ->
|
||||||
%%% State Operations
|
do_prompt_call({"init", init}, none, Build, State).
|
||||||
|
|
||||||
encrypt(Pass, Binary) ->
|
|
||||||
Flags = [{encrypt, true}, {padding, pkcs_padding}],
|
|
||||||
crypto:crypto_one_time(aes_256_ecb, Pass, Binary, Flags).
|
|
||||||
|
|
||||||
|
|
||||||
decrypt(Pass, Binary) ->
|
do_prompt_call(FunDef, ConID, Build, State = #s{tasks = Tasks, prefs = Prefs}) ->
|
||||||
Flags = [{encrypt, false}, {padding, pkcs_padding}],
|
Name = {ConID, FunDef},
|
||||||
crypto:crypto_one_time(aes_256_ecb, Pass, Binary, Flags).
|
case do_list_keys(State) of
|
||||||
|
{ok, Selected, KeyIDs} ->
|
||||||
|
case lists:keyfind(Name, #ui.name, Tasks) of
|
||||||
pass(none) ->
|
#ui{wx = Win} ->
|
||||||
none;
|
ok = gd_v_call:to_front(Win),
|
||||||
pass(Phrase) ->
|
State;
|
||||||
crypto:hash(sha3_256, Phrase).
|
false ->
|
||||||
|
CallPrefs = maps:get(gd_v_call, Prefs, #{}),
|
||||||
|
Args = {CallPrefs, FunDef, ConID, Build, Selected, KeyIDs},
|
||||||
|
Win = gd_v_call:start_link(Args),
|
||||||
|
PID = wx_object:get_pid(Win),
|
||||||
|
Mon = monitor(process, PID),
|
||||||
|
UI = #ui{name = Name, pid = PID, wx = Win, mon = Mon},
|
||||||
|
State#s{tasks = [UI | Tasks]}
|
||||||
|
end;
|
||||||
|
error ->
|
||||||
|
ok = gd_gui:trouble("ERROR: No Wallet Selected"),
|
||||||
|
State
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
do_make_key(Name, <<>>, _, Transform, State) ->
|
do_make_key(Name, <<>>, _, Transform, State) ->
|
||||||
@@ -889,33 +1010,6 @@ do_make_key2(Name, Bin, Transform,
|
|||||||
State#s{wallet = Updated}.
|
State#s{wallet = Updated}.
|
||||||
|
|
||||||
|
|
||||||
base64_decode(String) ->
|
|
||||||
try
|
|
||||||
{ok, base64:decode(String)}
|
|
||||||
catch
|
|
||||||
E:R -> {E, R}
|
|
||||||
end.
|
|
||||||
|
|
||||||
|
|
||||||
transform({sha3, 256}) ->
|
|
||||||
fun(D) -> crypto:hash(sha3_256, D) end;
|
|
||||||
transform({sha2, 256}) ->
|
|
||||||
fun(D) -> crypto:hash(sha256, D) end;
|
|
||||||
transform({x_or, 256}) ->
|
|
||||||
fun t_xor/1.
|
|
||||||
|
|
||||||
|
|
||||||
t_xor(Bin) -> t_xor(Bin, <<0:256>>).
|
|
||||||
|
|
||||||
t_xor(<<H:32/binary, T/binary>>, A) ->
|
|
||||||
t_xor(T, crypto:exor(H, A));
|
|
||||||
t_xor(<<>>, A) ->
|
|
||||||
A;
|
|
||||||
t_xor(B, A) ->
|
|
||||||
H = <<0:(256 - bit_size(B)), B/binary>>,
|
|
||||||
crypto:exor(H, A).
|
|
||||||
|
|
||||||
|
|
||||||
do_recover_key(Mnemonic, State) ->
|
do_recover_key(Mnemonic, State) ->
|
||||||
case hz_key_master:decode(Mnemonic) of
|
case hz_key_master:decode(Mnemonic) of
|
||||||
{ok, Seed} ->
|
{ok, Seed} ->
|
||||||
@@ -944,54 +1038,6 @@ do_recover_key2(Seed, State = #s{wallet = Current, wallets = Wallets, pass = Pas
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
do_mnemonic(ID, #s{wallet = #wallet{keys = Keys}}) ->
|
|
||||||
case lists:keyfind(ID, #key.id, Keys) of
|
|
||||||
#key{pair = #{secret := <<K:32/binary, _/binary>>}} ->
|
|
||||||
Mnemonic = hz_key_master:encode(K),
|
|
||||||
{ok, Mnemonic};
|
|
||||||
false ->
|
|
||||||
{error, bad_key}
|
|
||||||
end.
|
|
||||||
|
|
||||||
|
|
||||||
do_deploy(Build,
|
|
||||||
{PubKey, Nonce, TTL, GasPrice, Gas, Amount},
|
|
||||||
InitArgs,
|
|
||||||
#s{wallet = #wallet{keys = Keys, chain_id = ChainID}}) ->
|
|
||||||
#key{pair = #{secret := SecKey}} = lists:keyfind(PubKey, #key.id, Keys),
|
|
||||||
case hz:contract_create_built(PubKey,
|
|
||||||
Nonce, Amount, TTL, Gas, GasPrice,
|
|
||||||
Build, InitArgs) of
|
|
||||||
{ok, CreateTX} -> do_deploy2(SecKey, CreateTX, ChainID);
|
|
||||||
Error -> gd_v_devman:trouble(Error)
|
|
||||||
end.
|
|
||||||
|
|
||||||
do_deploy2(SecKey, CreateTX, ChainID) ->
|
|
||||||
SignedTX = hz:sign_tx(CreateTX, SecKey, ChainID),
|
|
||||||
tell(info, "SignedTX: ~p", [SignedTX]),
|
|
||||||
case hz:post_tx(SignedTX) of
|
|
||||||
{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.
|
|
||||||
|
|
||||||
do_deploy3(#{"tx_hash" := TXHash}) ->
|
|
||||||
case hz:tx_info(TXHash) of
|
|
||||||
{ok, #{"call_info" := #{"return_type" := "ok", "contract_id" := ConID}}} ->
|
|
||||||
gd_v_devman:open_contract(ConID);
|
|
||||||
{error, "Tx not mined"} ->
|
|
||||||
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.
|
|
||||||
|
|
||||||
|
|
||||||
do_rename_key(ID, NewName, State = #s{wallet = W, wallets = Wallets, pass = Pass}) ->
|
do_rename_key(ID, NewName, State = #s{wallet = W, wallets = Wallets, pass = Pass}) ->
|
||||||
#wallet{name = Name, poas = POAs, keys = Keys} = W,
|
#wallet{name = Name, poas = POAs, keys = Keys} = W,
|
||||||
RW = lists:keyfind(Name, #wr.name, Wallets),
|
RW = lists:keyfind(Name, #wr.name, Wallets),
|
||||||
@@ -1016,43 +1062,47 @@ do_drop_key(ID, State = #s{wallet = W, wallets = Wallets, pass = Pass}) ->
|
|||||||
State#s{wallet = NewWallet}.
|
State#s{wallet = NewWallet}.
|
||||||
|
|
||||||
|
|
||||||
do_open_wallet(Path, Phrase, State) ->
|
do_open_contract(ConID, ToFront, State) ->
|
||||||
|
NewState = do_show_ui(gd_v_devman, ToFront, State),
|
||||||
|
ok = gd_v_devman:open_contract(ConID),
|
||||||
|
NewState.
|
||||||
|
|
||||||
|
|
||||||
|
do_show_call(ConID, Info, ToFront, State) ->
|
||||||
|
NewState = do_show_ui(gd_v_devman, ToFront, State),
|
||||||
|
ok = gd_v_devman:open_contract(ConID),
|
||||||
|
ok = gd_v_devman:call_result(ConID, Info),
|
||||||
|
NewState.
|
||||||
|
|
||||||
|
|
||||||
|
do_open_wallet(Path, Phrase, State = #s{timer = Timer}) ->
|
||||||
Pass = pass(Phrase),
|
Pass = pass(Phrase),
|
||||||
case read(Path, Pass) of
|
case read(Path, Pass) of
|
||||||
{ok, Recovered = #wallet{name = Name, poas = POAs, endpoint = Node}} ->
|
{ok, Recovered = #wallet{name = Name, poas = POAs, endpoint = _Node}} ->
|
||||||
ok = gd_gui:show(POAs),
|
ok = gd_gui:show(POAs),
|
||||||
ok = gd_gui:wallet(Name),
|
ok = gd_gui:wallet(Name),
|
||||||
|
% TODO: set_hz/1 should dispatch async to the gd_netman.
|
||||||
|
% ok = set_hz(Node),
|
||||||
|
% case ensure_hz_set(Node) of
|
||||||
|
% {ok, ChainID} -> gd_gui:chain(ChainID, Node);
|
||||||
|
% Error -> gd_gui:trouble(Error)
|
||||||
|
% end,
|
||||||
ok =
|
ok =
|
||||||
case ensure_hz_set(Node) of
|
case Timer of
|
||||||
{ok, ChainID} -> gd_gui:chain(ChainID, Node);
|
none ->
|
||||||
Error -> gd_gui:trouble(Error)
|
ok;
|
||||||
|
{OldT, _} ->
|
||||||
|
_ = erlang:cancel_timer(OldT),
|
||||||
|
ok
|
||||||
end,
|
end,
|
||||||
{ok, State#s{pass = Pass, wallet = Recovered}};
|
MS = default_tic(),
|
||||||
|
T = erlang:send_after(200, self(), tic),
|
||||||
|
{ok, State#s{pass = Pass, wallet = Recovered, timer = {T, MS}}};
|
||||||
Error ->
|
Error ->
|
||||||
{Error, State}
|
{Error, State}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
default_wallet(mainnet) ->
|
|
||||||
Node = #node{ip = "groot.mainnet.gajumaru.io"},
|
|
||||||
Groot = #chain{id = <<"groot.mainnet">>,
|
|
||||||
nodes = [Node]},
|
|
||||||
MainNet = #net{id = <<"mainnet">>, chains = [Groot]},
|
|
||||||
#wallet{nets = [MainNet], endpoint = Node};
|
|
||||||
default_wallet(testnet) ->
|
|
||||||
Node = #node{ip = "groot.testnet.gajumaru.io"},
|
|
||||||
Groot = #chain{id = <<"groot.testnet">>,
|
|
||||||
nodes = [Node]},
|
|
||||||
TestNet = #net{id = <<"testnet">>, chains = [Groot]},
|
|
||||||
#wallet{nets = [TestNet], endpoint = Node};
|
|
||||||
default_wallet(devnet) ->
|
|
||||||
% TODO: This accounts for the nature of devnets by defining *no* chains.
|
|
||||||
% The GUI/CON will need to manage this properly when encountered and prompt.
|
|
||||||
DevNet = #net{id = <<"devnet">>,
|
|
||||||
chains = []},
|
|
||||||
#wallet{nets = [DevNet]}.
|
|
||||||
|
|
||||||
|
|
||||||
do_password(none, none, State) ->
|
do_password(none, none, State) ->
|
||||||
State;
|
State;
|
||||||
do_password(none, New, State = #s{pass = none,
|
do_password(none, New, State = #s{pass = none,
|
||||||
@@ -1197,16 +1247,6 @@ maybe_clean(false, _) ->
|
|||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
|
||||||
get_prefs(K, M, D) ->
|
|
||||||
P = maps:get(?MODULE, M, #{}),
|
|
||||||
maps:get(K, P, D).
|
|
||||||
|
|
||||||
put_prefs(K, V, M) ->
|
|
||||||
P = maps:get(?MODULE, M, #{}),
|
|
||||||
NewP = maps:put(K, V, P),
|
|
||||||
maps:put(?MODULE, NewP, M).
|
|
||||||
|
|
||||||
|
|
||||||
do_save(Module, Prefs, State = #s{prefs = Cached}) ->
|
do_save(Module, Prefs, State = #s{prefs = Cached}) ->
|
||||||
Updated = maps:put(Module, Prefs, Cached),
|
Updated = maps:put(Module, Prefs, Cached),
|
||||||
ok = persist(Updated),
|
ok = persist(Updated),
|
||||||
@@ -1222,13 +1262,17 @@ do_close_wallet(State = #s{wallet = Current, wallets = Wallets, pass = Pass}) ->
|
|||||||
State#s{selected = 0, pass = none, wallet = none}.
|
State#s{selected = 0, pass = none, wallet = none}.
|
||||||
|
|
||||||
|
|
||||||
save_wallet(#wr{path = Path, pass = false}, none, Wallet) ->
|
save_wallet(#wr{path = Path, pass = false}, none, Wallet = #wallet{name = Name}) ->
|
||||||
ok = filelib:ensure_dir(Path),
|
ok = filelib:ensure_dir(Path),
|
||||||
file:write_file(Path, term_to_binary(Wallet));
|
ok = log(info, "Saving plain wallet ~ts file to disk...", [Name]),
|
||||||
save_wallet(#wr{path = Path, pass = true}, Pass, Wallet) ->
|
ok = file:write_file(Path, term_to_binary(Wallet)),
|
||||||
|
log(info, "Wallet ~ts file written.", [Name]);
|
||||||
|
save_wallet(#wr{path = Path, pass = true}, Pass, Wallet = #wallet{name = Name}) ->
|
||||||
ok = filelib:ensure_dir(Path),
|
ok = filelib:ensure_dir(Path),
|
||||||
Cipher = encrypt(Pass, term_to_binary(Wallet)),
|
Cipher = encrypt(Pass, term_to_binary(Wallet)),
|
||||||
file:write_file(Path, Cipher).
|
ok = log(info, "Saving cipher wallet ~ts file to disk.", [Name]),
|
||||||
|
ok = file:write_file(Path, Cipher),
|
||||||
|
log(info, "Wallet ~ts file written.", [Name]).
|
||||||
|
|
||||||
|
|
||||||
read(Path, none) ->
|
read(Path, none) ->
|
||||||
@@ -1267,31 +1311,149 @@ read3(T) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
do_tic(State = #s{wallet = This = #wallet{poas = POAs, endpoint = Node}, selected = Selected}) when Selected > 0 ->
|
do_tic(stop, State = #s{timer = none}) ->
|
||||||
|
State;
|
||||||
|
do_tic(stop, State = #s{timer = {T, _}}) ->
|
||||||
|
_ = erlang:cancel_timer(T),
|
||||||
|
State#s{timer = none};
|
||||||
|
do_tic(MS, State = #s{timer = none}) ->
|
||||||
|
T = erlang:send_after(MS, self(), tic),
|
||||||
|
State#s{timer = {T, MS}};
|
||||||
|
do_tic(MS, State = #s{timer = {T, _}}) ->
|
||||||
|
_ = erlang:cancel_timer(T),
|
||||||
|
T = erlang:send_after(MS, self(), tic),
|
||||||
|
State#s{timer = {T, MS}}.
|
||||||
|
|
||||||
|
handle_tic(State = #s{wallet = #wallet{poas = []}, timer = {T, MS}}) ->
|
||||||
|
ok = cancel_timer(T),
|
||||||
|
NewT = erlang:send_after(MS, self(), tic),
|
||||||
|
State#s{timer = {NewT, MS}};
|
||||||
|
handle_tic(State = #s{wallet = This = #wallet{poas = POAs, endpoint = Node},
|
||||||
|
timer = {T, MS},
|
||||||
|
selected = Selected})
|
||||||
|
when Selected > 0 ->
|
||||||
|
% TODO: The closure below is kind of silly. The internal hz:acc/1 account will
|
||||||
|
% Expand to become hz:acc/2, accepting a chain ID later.
|
||||||
NewState =
|
NewState =
|
||||||
case ensure_hz_set(Node) of
|
case ensure_hz_set(Node) of
|
||||||
{ok, ChainID} ->
|
{ok, ChainID} ->
|
||||||
POA = #poa{id = ID} = lists:nth(Selected, POAs),
|
POA = #poa{id = ID} = lists:nth(Selected, POAs),
|
||||||
CheckBalance = check_balance(ChainID),
|
CheckBalance = check_balance(ChainID, "gaju"),
|
||||||
NewPOA = CheckBalance(POA),
|
NewPOA = CheckBalance(POA),
|
||||||
NewPOAs = lists:keystore(ID, #poa.id, POAs, NewPOA),
|
NewPOAs = lists:keystore(ID, #poa.id, POAs, NewPOA),
|
||||||
ok = gd_gui:show(NewPOAs),
|
ok = gd_gui:show(NewPOAs),
|
||||||
State#s{wallet = This#wallet{poas = POAs}};
|
State#s{wallet = This#wallet{poas = NewPOAs}};
|
||||||
Error ->
|
Error ->
|
||||||
ok = log(info, "Balance update on tic failed with: ~p", [Error]),
|
ok = log(info, "Balance update on tic failed with: ~p", [Error]),
|
||||||
State
|
State
|
||||||
end,
|
end,
|
||||||
T = erlang:send_after(tic(), self(), tic),
|
ok = cancel_timer(T),
|
||||||
NewState#s{timer = T};
|
NewT = erlang:send_after(MS, self(), tic),
|
||||||
do_tic(State) ->
|
NewState#s{timer = {NewT, MS}};
|
||||||
T = erlang:send_after(tic(), self(), tic),
|
handle_tic(State = #s{timer = {T, MS}}) ->
|
||||||
State#s{timer = T}.
|
ok = cancel_timer(T),
|
||||||
|
NewT = erlang:send_after(MS, self(), tic),
|
||||||
|
State#s{timer = {NewT, MS}};
|
||||||
|
handle_tic(State) ->
|
||||||
|
State.
|
||||||
|
|
||||||
|
cancel_timer(T) ->
|
||||||
|
case erlang:cancel_timer(T) of
|
||||||
|
false -> ok;
|
||||||
|
R -> log(warning, "Tic timers are doubled up. Remaining: ~wms", [R])
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%%% Stateless Operations
|
||||||
|
|
||||||
|
encrypt(Pass, Binary) ->
|
||||||
|
Flags = [{encrypt, true}, {padding, pkcs_padding}],
|
||||||
|
crypto:crypto_one_time(aes_256_ecb, Pass, Binary, Flags).
|
||||||
|
|
||||||
|
|
||||||
|
decrypt(Pass, Binary) ->
|
||||||
|
Flags = [{encrypt, false}, {padding, pkcs_padding}],
|
||||||
|
crypto:crypto_one_time(aes_256_ecb, Pass, Binary, Flags).
|
||||||
|
|
||||||
|
|
||||||
|
pass(none) ->
|
||||||
|
none;
|
||||||
|
pass(Phrase) ->
|
||||||
|
crypto:hash(sha3_256, Phrase).
|
||||||
|
|
||||||
|
|
||||||
|
base64_decode(String) ->
|
||||||
|
try
|
||||||
|
{ok, base64:decode(String)}
|
||||||
|
catch
|
||||||
|
E:R -> {E, R}
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
transform({sha3, 256}) ->
|
||||||
|
fun(D) -> crypto:hash(sha3_256, D) end;
|
||||||
|
transform({sha2, 256}) ->
|
||||||
|
fun(D) -> crypto:hash(sha256, D) end;
|
||||||
|
transform({x_or, 256}) ->
|
||||||
|
fun t_xor/1.
|
||||||
|
|
||||||
|
|
||||||
|
t_xor(Bin) -> t_xor(Bin, <<0:256>>).
|
||||||
|
|
||||||
|
t_xor(<<H:32/binary, T/binary>>, A) ->
|
||||||
|
t_xor(T, crypto:exor(H, A));
|
||||||
|
t_xor(<<>>, A) ->
|
||||||
|
A;
|
||||||
|
t_xor(B, A) ->
|
||||||
|
H = <<0:(256 - bit_size(B)), B/binary>>,
|
||||||
|
crypto:exor(H, A).
|
||||||
|
|
||||||
|
|
||||||
|
do_mnemonic(ID, #s{wallet = #wallet{keys = Keys}}) ->
|
||||||
|
case lists:keyfind(ID, #key.id, Keys) of
|
||||||
|
#key{pair = #{secret := <<K:32/binary, _/binary>>}} ->
|
||||||
|
Mnemonic = hz_key_master:encode(K),
|
||||||
|
{ok, Mnemonic};
|
||||||
|
false ->
|
||||||
|
{error, bad_key}
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
default_wallet(mainnet) ->
|
||||||
|
Node = #node{ip = "groot.mainnet.gajumaru.io"},
|
||||||
|
Groot = #chain{id = <<"groot.mainnet">>,
|
||||||
|
nodes = [Node]},
|
||||||
|
MainNet = #net{id = <<"mainnet">>, chains = [Groot]},
|
||||||
|
#wallet{nets = [MainNet], endpoint = Node};
|
||||||
|
default_wallet(testnet) ->
|
||||||
|
Node = #node{ip = "groot.testnet.gajumaru.io"},
|
||||||
|
Groot = #chain{id = <<"groot.testnet">>,
|
||||||
|
nodes = [Node]},
|
||||||
|
TestNet = #net{id = <<"testnet">>, chains = [Groot]},
|
||||||
|
#wallet{nets = [TestNet], endpoint = Node};
|
||||||
|
default_wallet(devnet) ->
|
||||||
|
% TODO: This accounts for the nature of devnets by defining *no* chains.
|
||||||
|
% The GUI/CON will need to manage this properly when encountered and prompt.
|
||||||
|
DevNet = #net{id = <<"devnet">>,
|
||||||
|
chains = []},
|
||||||
|
#wallet{nets = [DevNet]}.
|
||||||
|
|
||||||
|
|
||||||
|
get_prefs(K, M, D) ->
|
||||||
|
P = maps:get(?MODULE, M, #{}),
|
||||||
|
maps:get(K, P, D).
|
||||||
|
|
||||||
|
put_prefs(K, V, M) ->
|
||||||
|
P = maps:get(?MODULE, M, #{}),
|
||||||
|
NewP = maps:put(K, V, P),
|
||||||
|
maps:put(?MODULE, NewP, M).
|
||||||
|
|
||||||
|
|
||||||
persist(Prefs) ->
|
persist(Prefs) ->
|
||||||
Path = prefs_path(),
|
Path = prefs_path(),
|
||||||
ok = filelib:ensure_dir(Path),
|
ok = filelib:ensure_dir(Path),
|
||||||
|
ok = log(info, "Writing prefs to disk."),
|
||||||
zx_lib:write_terms(Path, proplists:from_map(Prefs)).
|
zx_lib:write_terms(Path, proplists:from_map(Prefs)).
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -37,7 +37,7 @@
|
|||||||
%%% @end
|
%%% @end
|
||||||
|
|
||||||
-module(gd_grids).
|
-module(gd_grids).
|
||||||
-vsn("0.7.0").
|
-vsn("0.9.0").
|
||||||
-author("Craig Everett <craigeverett@qpq.swiss>").
|
-author("Craig Everett <craigeverett@qpq.swiss>").
|
||||||
-copyright("QPQ AG <info@qpq.swiss>").
|
-copyright("QPQ AG <info@qpq.swiss>").
|
||||||
-license("GPL-3.0-or-later").
|
-license("GPL-3.0-or-later").
|
||||||
|
|||||||
+88
-222
@@ -3,7 +3,7 @@
|
|||||||
%%% @end
|
%%% @end
|
||||||
|
|
||||||
-module(gd_gui).
|
-module(gd_gui).
|
||||||
-vsn("0.7.0").
|
-vsn("0.9.0").
|
||||||
-author("Craig Everett <craigeverett@qpq.swiss>").
|
-author("Craig Everett <craigeverett@qpq.swiss>").
|
||||||
-copyright("QPQ AG <info@qpq.swiss>").
|
-copyright("QPQ AG <info@qpq.swiss>").
|
||||||
-license("GPL-3.0-or-later").
|
-license("GPL-3.0-or-later").
|
||||||
@@ -17,13 +17,9 @@
|
|||||||
handle_call/3, handle_cast/2, handle_info/2, handle_event/2]).
|
handle_call/3, handle_cast/2, handle_info/2, handle_event/2]).
|
||||||
-include("$zx_include/zx_logger.hrl").
|
-include("$zx_include/zx_logger.hrl").
|
||||||
-include("gd.hrl").
|
-include("gd.hrl").
|
||||||
|
-include("gdl.hrl").
|
||||||
|
|
||||||
|
|
||||||
-record(w,
|
|
||||||
{name = none :: atom(),
|
|
||||||
id = 0 :: integer(),
|
|
||||||
wx = none :: none | wx:wx_object()}).
|
|
||||||
|
|
||||||
-record(h,
|
-record(h,
|
||||||
{win = none :: none | wx:wx_object(),
|
{win = none :: none | wx:wx_object(),
|
||||||
sz = none :: none | wx:wx_object()}).
|
sz = none :: none | wx:wx_object()}).
|
||||||
@@ -38,7 +34,7 @@
|
|||||||
accounts = [] :: [gajudesk:poa()],
|
accounts = [] :: [gajudesk:poa()],
|
||||||
picker = none :: none | wx:wx_object(),
|
picker = none :: none | wx:wx_object(),
|
||||||
id = {#w{}, #w{}} :: labeled(),
|
id = {#w{}, #w{}} :: labeled(),
|
||||||
balance = {#w{}, #w{}} :: labeled(),
|
balance = #w{} :: #w{},
|
||||||
buttons = [] :: [widget()],
|
buttons = [] :: [widget()],
|
||||||
history = #h{} :: #h{}}).
|
history = #h{} :: #h{}}).
|
||||||
|
|
||||||
@@ -92,21 +88,24 @@ init(Prefs) ->
|
|||||||
VSN = proplists:get_value(vsn, ?MODULE:module_info(attributes)),
|
VSN = proplists:get_value(vsn, ?MODULE:module_info(attributes)),
|
||||||
Wx = wx:new(),
|
Wx = wx:new(),
|
||||||
Frame = wxFrame:new(Wx, ?wxID_ANY, AppName ++ " v" ++ VSN),
|
Frame = wxFrame:new(Wx, ?wxID_ANY, AppName ++ " v" ++ VSN),
|
||||||
|
Panel = wxWindow:new(Frame, ?wxID_ANY),
|
||||||
|
TopSz = wxBoxSizer:new(?wxVERTICAL),
|
||||||
|
_ = wxBoxSizer:add(TopSz, Panel, zxw:flags(wide)),
|
||||||
MainSz = wxBoxSizer:new(?wxVERTICAL),
|
MainSz = wxBoxSizer:new(?wxVERTICAL),
|
||||||
Picker = wxListBox:new(Frame, ?wxID_ANY, [{style, ?wxLC_SINGLE_SEL}]),
|
Picker = wxListBox:new(Panel, ?wxID_ANY, [{style, ?wxLC_SINGLE_SEL}]),
|
||||||
|
|
||||||
WallB = wxButton:new(Frame, ?wxID_ANY, [{label, "[none]"}, {style, ?wxBORDER_NONE}]),
|
WallB = wxButton:new(Panel, ?wxID_ANY, [{label, "[none]"}, {style, ?wxBORDER_NONE}]),
|
||||||
WallW = #w{name = wallet, id = wxButton:getId(WallB), wx = WallB},
|
WallW = #w{name = wallet, id = wxButton:getId(WallB), wx = WallB},
|
||||||
ChainB = wxButton:new(Frame, ?wxID_ANY, [{label, "[ChainID]"}, {style, ?wxBORDER_NONE}]),
|
ChainB = wxButton:new(Panel, ?wxID_ANY, [{label, "[ChainID]"}, {style, ?wxBORDER_NONE}]),
|
||||||
_ = wxButton:disable(ChainB),
|
_ = wxButton:disable(ChainB),
|
||||||
ChainW = #w{name = chain, id = wxButton:getId(ChainB), wx = ChainB},
|
ChainW = #w{name = chain, id = wxButton:getId(ChainB), wx = ChainB},
|
||||||
NodeB = wxButton:new(Frame, ?wxID_ANY, [{label, "[Node]"}, {style, ?wxBORDER_NONE}]),
|
NodeB = wxButton:new(Panel, ?wxID_ANY, [{label, "[Node]"}, {style, ?wxBORDER_NONE}]),
|
||||||
NodeW = #w{name = node, id = wxButton:getId(NodeB), wx = NodeB},
|
NodeW = #w{name = node, id = wxButton:getId(NodeB), wx = NodeB},
|
||||||
DevB = wxButton:new(Frame, ?wxID_ANY, [{label, "𝑓 () →"}]),
|
DevB = wxButton:new(Panel, ?wxID_ANY, [{label, "𝑓 () →"}]),
|
||||||
DevW = #w{name = dev, id = wxButton:getId(DevB), wx = DevB},
|
DevW = #w{name = dev, id = wxButton:getId(DevB), wx = DevB},
|
||||||
|
|
||||||
ID_L = wxStaticText:new(Frame, ?wxID_ANY, J("Account ID: ")),
|
ID_L = wxStaticText:new(Panel, ?wxID_ANY, J("Account ID: ")),
|
||||||
ID_T = wxStaticText:new(Frame, ?wxID_ANY, ""),
|
ID_T = wxStaticText:new(Panel, ?wxID_ANY, ""),
|
||||||
ID_W =
|
ID_W =
|
||||||
{#w{id = wxStaticText:getId(ID_L), wx = ID_L},
|
{#w{id = wxStaticText:getId(ID_L), wx = ID_L},
|
||||||
#w{id = wxStaticText:getId(ID_T), wx = ID_T}},
|
#w{id = wxStaticText:getId(ID_T), wx = ID_T}},
|
||||||
@@ -114,13 +113,9 @@ init(Prefs) ->
|
|||||||
_ = wxSizer:add(ID_Sz, ID_L, zxw:flags(base)),
|
_ = wxSizer:add(ID_Sz, ID_L, zxw:flags(base)),
|
||||||
_ = wxSizer:add(ID_Sz, ID_T, zxw:flags(wide)),
|
_ = wxSizer:add(ID_Sz, ID_T, zxw:flags(wide)),
|
||||||
|
|
||||||
BalanceL = wxStaticText:new(Frame, ?wxID_ANY, "木"),
|
BalanceT = wxStaticText:new(Panel, ?wxID_ANY, hz_format:amount(0)),
|
||||||
BalanceT = wxStaticText:new(Frame, ?wxID_ANY, price_to_string(0)),
|
Balance = #w{id = wxStaticText:getId(BalanceT), wx = BalanceT},
|
||||||
Balance =
|
|
||||||
{#w{id = wxStaticText:getId(BalanceL), wx = BalanceL},
|
|
||||||
#w{id = wxStaticText:getId(BalanceT), wx = BalanceT}},
|
|
||||||
BalanceSz = wxBoxSizer:new(?wxHORIZONTAL),
|
BalanceSz = wxBoxSizer:new(?wxHORIZONTAL),
|
||||||
_ = wxSizer:add(BalanceSz, BalanceL, zxw:flags(base)),
|
|
||||||
_ = wxSizer:add(BalanceSz, BalanceT, zxw:flags(wide)),
|
_ = wxSizer:add(BalanceSz, BalanceT, zxw:flags(wide)),
|
||||||
|
|
||||||
NumbersSz = wxBoxSizer:new(?wxVERTICAL),
|
NumbersSz = wxBoxSizer:new(?wxVERTICAL),
|
||||||
@@ -142,7 +137,7 @@ init(Prefs) ->
|
|||||||
|
|
||||||
MakeButton =
|
MakeButton =
|
||||||
fun({Name, Label}) ->
|
fun({Name, Label}) ->
|
||||||
B = wxButton:new(Frame, ?wxID_ANY, [{label, Label}]),
|
B = wxButton:new(Panel, ?wxID_ANY, [{label, Label}]),
|
||||||
#w{name = Name, id = wxButton:getId(B), wx = B}
|
#w{name = Name, id = wxButton:getId(B), wx = B}
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@@ -190,7 +185,7 @@ init(Prefs) ->
|
|||||||
|
|
||||||
#w{wx = Refresh} = lists:keyfind(refresh, #w.name, Buttons),
|
#w{wx = Refresh} = lists:keyfind(refresh, #w.name, Buttons),
|
||||||
|
|
||||||
% HistoryWin = wxScrolledWindow:new(Frame),
|
% HistoryWin = wxScrolledWindow:new(Panel),
|
||||||
% HistorySz = wxBoxSizer:new(?wxVERTICAL),
|
% HistorySz = wxBoxSizer:new(?wxVERTICAL),
|
||||||
% ok = wxScrolledWindow:setSizerAndFit(HistoryWin, HistorySz),
|
% ok = wxScrolledWindow:setSizerAndFit(HistoryWin, HistorySz),
|
||||||
% ok = wxScrolledWindow:setScrollRate(HistoryWin, 5, 5),
|
% ok = wxScrolledWindow:setScrollRate(HistoryWin, 5, 5),
|
||||||
@@ -202,7 +197,8 @@ init(Prefs) ->
|
|||||||
_ = wxSizer:add(MainSz, ActionsSz, zxw:flags(base)),
|
_ = wxSizer:add(MainSz, ActionsSz, zxw:flags(base)),
|
||||||
_ = wxSizer:add(MainSz, Refresh, zxw:flags(base)),
|
_ = wxSizer:add(MainSz, Refresh, zxw:flags(base)),
|
||||||
% _ = wxSizer:add(MainSz, HistoryWin, zxw:flags(wide)),
|
% _ = wxSizer:add(MainSz, HistoryWin, zxw:flags(wide)),
|
||||||
ok = wxFrame:setSizer(Frame, MainSz),
|
ok = wxWindow:setSizer(Panel, MainSz),
|
||||||
|
ok = wxFrame:setSizer(Frame, TopSz),
|
||||||
ok = wxSizer:layout(MainSz),
|
ok = wxSizer:layout(MainSz),
|
||||||
|
|
||||||
ok = gd_v:safe_size(Frame, Prefs),
|
ok = gd_v:safe_size(Frame, Prefs),
|
||||||
@@ -302,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);
|
||||||
@@ -337,6 +333,7 @@ handle_event(Event, State) ->
|
|||||||
|
|
||||||
|
|
||||||
handle_troubling(#s{frame = Frame}, Info) ->
|
handle_troubling(#s{frame = Frame}, Info) ->
|
||||||
|
ok = wxFrame:raise(Frame),
|
||||||
zxw:show_message(Frame, Info).
|
zxw:show_message(Frame, Info).
|
||||||
|
|
||||||
|
|
||||||
@@ -591,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.
|
||||||
@@ -607,33 +604,15 @@ rename_key(State = #s{picker = Picker}) ->
|
|||||||
|
|
||||||
rename_key(Selected, State = #s{frame = Frame, j = J, accounts = Accounts}) ->
|
rename_key(Selected, State = #s{frame = Frame, j = J, accounts = Accounts}) ->
|
||||||
#poa{id = ID, name = Name} = lists:nth(Selected, Accounts),
|
#poa{id = ID, name = Name} = lists:nth(Selected, Accounts),
|
||||||
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("New Key")),
|
Title = J("Rename Key"),
|
||||||
Sizer = wxBoxSizer:new(?wxVERTICAL),
|
Label = J("New Name"),
|
||||||
NameSz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("Name (Optional)")}]),
|
Options = [{label, Label}, {init, Name}, selected, empty],
|
||||||
NameTx = wxTextCtrl:new(Dialog, ?wxID_ANY),
|
|
||||||
ok = wxTextCtrl:setValue(NameTx, Name),
|
|
||||||
_ = wxStaticBoxSizer:add(NameSz, NameTx, zxw:flags(base)),
|
|
||||||
ButtSz = wxBoxSizer:new(?wxHORIZONTAL),
|
|
||||||
Affirm = wxButton:new(Dialog, ?wxID_OK),
|
|
||||||
Cancel = wxButton:new(Dialog, ?wxID_CANCEL),
|
|
||||||
_ = wxBoxSizer:add(ButtSz, Affirm, zxw:flags(wide)),
|
|
||||||
_ = wxBoxSizer:add(ButtSz, Cancel, zxw:flags(wide)),
|
|
||||||
_ = wxBoxSizer:add(Sizer, NameSz, zxw:flags(base)),
|
|
||||||
_ = wxBoxSizer:add(Sizer, ButtSz, zxw:flags(wide)),
|
|
||||||
ok = wxDialog:setSizer(Dialog, Sizer),
|
|
||||||
ok = wxBoxSizer:layout(Sizer),
|
|
||||||
ok = wxDialog:setSize(Dialog, {500, 130}),
|
|
||||||
ok = wxDialog:center(Dialog),
|
|
||||||
ok = wxStyledTextCtrl:setFocus(NameTx),
|
|
||||||
ok =
|
ok =
|
||||||
case wxDialog:showModal(Dialog) of
|
case zxw_modal_text:show(Frame, Title, Options) of
|
||||||
?wxID_OK ->
|
{ok, ""} -> gd_con:rename_key(ID, binary_to_list(ID));
|
||||||
NewName = wxTextCtrl:getValue(NameTx),
|
{ok, NewName} -> gd_con:rename_key(ID, NewName);
|
||||||
gd_con:rename_key(ID, NewName);
|
cancel -> ok
|
||||||
?wxID_CANCEL ->
|
|
||||||
ok
|
|
||||||
end,
|
end,
|
||||||
ok = wxDialog:destroy(Dialog),
|
|
||||||
State.
|
State.
|
||||||
|
|
||||||
|
|
||||||
@@ -677,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
|
||||||
@@ -743,133 +705,29 @@ spend(Selected, State = #s{accounts = Accounts}) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
spend2(#poa{id = ID, name = Name}, Nonce, Height, State = #s{frame = Frame, j = J}) ->
|
spend2(#poa{id = ID, name = Name}, Nonce, Height, State = #s{frame = Frame, j = J}) ->
|
||||||
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("Transfer"), [{size, {500, 400}}]),
|
|
||||||
Sizer = wxBoxSizer:new(?wxVERTICAL),
|
|
||||||
|
|
||||||
Account = [Name, " (", ID, ")"],
|
Account = [Name, " (", ID, ")"],
|
||||||
FromTx = wxStaticText:new(Dialog, ?wxID_ANY, Account),
|
Args = {Account, J},
|
||||||
FromSz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("From")}]),
|
|
||||||
_ = wxStaticBoxSizer:add(FromSz, FromTx, zxw:flags(wide)),
|
|
||||||
|
|
||||||
ToTx = wxTextCtrl:new(Dialog, ?wxID_ANY),
|
|
||||||
ToSz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("To")}]),
|
|
||||||
_ = wxStaticBoxSizer:add(ToSz, ToTx, zxw:flags(wide)),
|
|
||||||
|
|
||||||
AmtTx = wxTextCtrl:new(Dialog, ?wxID_ANY),
|
|
||||||
AmtSz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("Amount")}]),
|
|
||||||
AmtInSz = wxBoxSizer:new(?wxHORIZONTAL),
|
|
||||||
AmtLabel = wxStaticText:new(Dialog, ?wxID_ANY, "木"),
|
|
||||||
_ = wxStaticBoxSizer:add(AmtInSz, AmtLabel, zxw:flags(base)),
|
|
||||||
_ = wxStaticBoxSizer:add(AmtInSz, AmtTx, zxw:flags(wide)),
|
|
||||||
_ = wxStaticBoxSizer:add(AmtSz, AmtInSz, zxw:flags(wide)),
|
|
||||||
|
|
||||||
DataTx = wxTextCtrl:new(Dialog, ?wxID_ANY, [{style, ?wxTE_MULTILINE}]),
|
|
||||||
DataSz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("Message (optional)")}]),
|
|
||||||
_ = wxStaticBoxSizer:add(DataSz, DataTx, zxw:flags(wide)),
|
|
||||||
|
|
||||||
Style = [{style, ?wxSL_HORIZONTAL bor ?wxSL_LABELS}],
|
|
||||||
|
|
||||||
TTL_Sl = wxSlider:new(Dialog, ?wxID_ANY, 100, 10, 1000, Style),
|
|
||||||
TTL_Sz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("TTL")}]),
|
|
||||||
_ = wxStaticBoxSizer:add(TTL_Sz, TTL_Sl, zxw:flags(wide)),
|
|
||||||
|
|
||||||
Min = hz:min_gas_price(),
|
|
||||||
Max = Min * 2,
|
|
||||||
GasSl = wxSlider:new(Dialog, ?wxID_ANY, Min, Min, Max, Style),
|
|
||||||
GasSz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("Gas Price")}]),
|
|
||||||
_ = wxStaticBoxSizer:add(GasSz, GasSl, zxw:flags(wide)),
|
|
||||||
|
|
||||||
ButtSz = wxBoxSizer:new(?wxHORIZONTAL),
|
|
||||||
Affirm = wxButton:new(Dialog, ?wxID_OK),
|
|
||||||
Cancel = wxButton:new(Dialog, ?wxID_CANCEL),
|
|
||||||
_ = wxBoxSizer:add(ButtSz, Affirm, zxw:flags(wide)),
|
|
||||||
_ = wxBoxSizer:add(ButtSz, Cancel, zxw:flags(wide)),
|
|
||||||
|
|
||||||
_ = wxBoxSizer:add(Sizer, FromSz, zxw:flags(base)),
|
|
||||||
_ = wxBoxSizer:add(Sizer, ToSz, zxw:flags(base)),
|
|
||||||
_ = wxBoxSizer:add(Sizer, AmtSz, zxw:flags(base)),
|
|
||||||
_ = wxBoxSizer:add(Sizer, DataSz, zxw:flags(wide)),
|
|
||||||
_ = wxBoxSizer:add(Sizer, TTL_Sz, zxw:flags(wide)),
|
|
||||||
_ = wxBoxSizer:add(Sizer, GasSz, zxw:flags(base)),
|
|
||||||
_ = wxBoxSizer:add(Sizer, ButtSz, zxw:flags(base)),
|
|
||||||
ok = wxDialog:setSizer(Dialog, Sizer),
|
|
||||||
ok = wxBoxSizer:layout(Sizer),
|
|
||||||
ok = wxFrame:setSize(Dialog, {500, 450}),
|
|
||||||
ok = wxFrame:center(Dialog),
|
|
||||||
ok =
|
ok =
|
||||||
case wxDialog:showModal(Dialog) of
|
case gd_m_spend:show(Frame, Args) of
|
||||||
?wxID_OK ->
|
{ok, Partial = #spend_tx{ttl = TTL}} ->
|
||||||
TX =
|
TX =
|
||||||
#spend_tx{sender_id = ID,
|
Partial#spend_tx{sender_id = ID,
|
||||||
recipient_id = wxTextCtrl:getValue(ToTx),
|
|
||||||
amount = wxTextCtrl:getValue(AmtTx),
|
|
||||||
gas_price = wxSlider:getValue(GasSl),
|
|
||||||
gas = 20000,
|
gas = 20000,
|
||||||
ttl = Height + wxSlider:getValue(TTL_Sl),
|
ttl = Height + TTL,
|
||||||
nonce = Nonce,
|
nonce = Nonce},
|
||||||
payload = wxTextCtrl:getValue(DataTx)},
|
gd_con:spend(TX);
|
||||||
clean_spend(TX);
|
cancel ->
|
||||||
?wxID_CANCEL ->
|
|
||||||
ok
|
ok
|
||||||
end,
|
end,
|
||||||
ok = wxDialog:destroy(Dialog),
|
|
||||||
State.
|
State.
|
||||||
|
|
||||||
clean_spend(#spend_tx{recipient_id = ""}) ->
|
|
||||||
ok;
|
|
||||||
clean_spend( TX = #spend_tx{amount = S}) when is_list(S) ->
|
|
||||||
case string_to_price(S) of
|
|
||||||
{ok, Amount} -> clean_spend(TX#spend_tx{amount = Amount});
|
|
||||||
{error, _} -> ok
|
|
||||||
end;
|
|
||||||
clean_spend(TX = #spend_tx{gas_price = S}) when is_list(S) ->
|
|
||||||
case is_int(S) of
|
|
||||||
true -> clean_spend(TX#spend_tx{gas_price = list_to_integer(S)});
|
|
||||||
false -> ok
|
|
||||||
end;
|
|
||||||
clean_spend(TX = #spend_tx{gas = S}) when is_list(S) ->
|
|
||||||
case is_int(S) of
|
|
||||||
true -> clean_spend(TX#spend_tx{gas = list_to_integer(S)});
|
|
||||||
false -> ok
|
|
||||||
end;
|
|
||||||
clean_spend(TX = #spend_tx{payload = S}) when is_list(S) ->
|
|
||||||
clean_spend(TX#spend_tx{payload = list_to_binary(S)});
|
|
||||||
clean_spend(TX) ->
|
|
||||||
gd_con:spend(TX).
|
|
||||||
|
|
||||||
|
|
||||||
is_int(S) ->
|
|
||||||
lists:all(fun(C) -> $0 =< C andalso C =< $9 end, S).
|
|
||||||
|
|
||||||
|
|
||||||
grids_dialogue(State = #s{frame = Frame, j = J}) ->
|
grids_dialogue(State = #s{frame = Frame, j = J}) ->
|
||||||
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("GRIDS URL")),
|
Title = J("GRIDS URL"),
|
||||||
Sizer = wxBoxSizer:new(?wxVERTICAL),
|
|
||||||
Label = J("GRIDS URL"),
|
|
||||||
URL_Sz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J(Label)}]),
|
|
||||||
URL_Tx = wxTextCtrl:new(Dialog, ?wxID_ANY),
|
|
||||||
_ = wxStaticBoxSizer:add(URL_Sz, URL_Tx, zxw:flags(wide)),
|
|
||||||
ButtSz = wxBoxSizer:new(?wxHORIZONTAL),
|
|
||||||
Affirm = wxButton:new(Dialog, ?wxID_OK),
|
|
||||||
Cancel = wxButton:new(Dialog, ?wxID_CANCEL),
|
|
||||||
_ = wxBoxSizer:add(ButtSz, Affirm, zxw:flags(wide)),
|
|
||||||
_ = wxBoxSizer:add(ButtSz, Cancel, zxw:flags(wide)),
|
|
||||||
_ = wxBoxSizer:add(Sizer, URL_Sz, zxw:flags(base)),
|
|
||||||
_ = wxBoxSizer:add(Sizer, ButtSz, zxw:flags(wide)),
|
|
||||||
ok = wxDialog:setSizer(Dialog, Sizer),
|
|
||||||
ok = wxBoxSizer:layout(Sizer),
|
|
||||||
ok = wxDialog:setSize(Dialog, {500, 130}),
|
|
||||||
ok = wxDialog:center(Dialog),
|
|
||||||
ok = wxStyledTextCtrl:setFocus(URL_Tx),
|
|
||||||
ok =
|
ok =
|
||||||
case wxDialog:showModal(Dialog) of
|
case zxw_modal_text:show(Frame, Title) of
|
||||||
?wxID_OK ->
|
{ok, String} -> gd_con:grids(String);
|
||||||
case wxTextCtrl:getValue(URL_Tx) of
|
cancel -> ok
|
||||||
"" -> ok;
|
|
||||||
String -> gd_con:grids(String)
|
|
||||||
end;
|
|
||||||
?wxID_CANCEL ->
|
|
||||||
ok
|
|
||||||
end,
|
end,
|
||||||
State.
|
State.
|
||||||
|
|
||||||
@@ -882,13 +740,13 @@ handle_button(Name, State) ->
|
|||||||
|
|
||||||
do_selection(Selected,
|
do_selection(Selected,
|
||||||
State = #s{prefs = Prefs, accounts = Accounts,
|
State = #s{prefs = Prefs, accounts = Accounts,
|
||||||
balance = {_, #w{wx = B}}, id = {_, #w{wx = I}}})
|
balance = #w{wx = B}, id = {_, #w{wx = I}}})
|
||||||
when Selected < length(Accounts) ->
|
when Selected < length(Accounts) ->
|
||||||
OneBasedIndex = Selected + 1,
|
OneBasedIndex = Selected + 1,
|
||||||
#poa{id = ID, balances = Balances} = lists:nth(OneBasedIndex, Accounts),
|
#poa{id = ID, balances = Balances} = lists:nth(OneBasedIndex, Accounts),
|
||||||
[#balance{total = Pucks}] = Balances,
|
[#balance{total = Pucks}] = Balances,
|
||||||
ok = wxStaticText:setLabel(I, ID),
|
ok = wxStaticText:setLabel(I, ID),
|
||||||
ok = wxStaticText:setLabel(B, price_to_string(Pucks)),
|
ok = wxStaticText:setLabel(B, hz_format:amount(Pucks)),
|
||||||
ok = gd_con:selected(OneBasedIndex),
|
ok = gd_con:selected(OneBasedIndex),
|
||||||
NewPrefs = maps:put(selected, Selected, Prefs),
|
NewPrefs = maps:put(selected, Selected, Prefs),
|
||||||
State#s{prefs = NewPrefs};
|
State#s{prefs = NewPrefs};
|
||||||
@@ -915,7 +773,7 @@ do_show(Accounts, State = #s{sizer = Sizer, prefs = Prefs, picker = Picker}) ->
|
|||||||
ok = wxSizer:layout(Sizer),
|
ok = wxSizer:layout(Sizer),
|
||||||
NewState.
|
NewState.
|
||||||
|
|
||||||
clear_account(State = #s{balance = {_, #w{wx = B}}, id = {_, #w{wx = I}}}) ->
|
clear_account(State = #s{balance = #w{wx = B}, id = {_, #w{wx = I}}}) ->
|
||||||
ok = wxStaticText:setLabel(I, ""),
|
ok = wxStaticText:setLabel(I, ""),
|
||||||
ok = wxStaticText:setLabel(B, ""),
|
ok = wxStaticText:setLabel(B, ""),
|
||||||
State.
|
State.
|
||||||
@@ -1060,6 +918,48 @@ do_grids_mess_sig2(Request = #{"grids" := 1,
|
|||||||
?wxID_CANCEL -> ok
|
?wxID_CANCEL -> ok
|
||||||
end,
|
end,
|
||||||
wxDialog:destroy(Dialog);
|
wxDialog:destroy(Dialog);
|
||||||
|
do_grids_mess_sig2(Request = #{"grids" := 1,
|
||||||
|
"type" := "binary",
|
||||||
|
"url" := URL,
|
||||||
|
"public_id" := ID,
|
||||||
|
"payload" := Base64},
|
||||||
|
#s{frame = Frame, j = J}) ->
|
||||||
|
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("Binary Data Signature Request")),
|
||||||
|
Sizer = wxBoxSizer:new(?wxVERTICAL),
|
||||||
|
Instruction =
|
||||||
|
J("The server at the URL below is requesting you sign the following binary data."),
|
||||||
|
InstTx = wxStaticText:new(Dialog, ?wxID_ANY, Instruction),
|
||||||
|
AcctSz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("Signature Account")}]),
|
||||||
|
AcctTx = wxStaticText:new(Dialog, ?wxID_ANY, ID),
|
||||||
|
_ = wxStaticBoxSizer:add(AcctSz, AcctTx, zxw:flags(wide)),
|
||||||
|
URL_Label = J("Originating URL"),
|
||||||
|
URL_Sz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, URL_Label}]),
|
||||||
|
URL_Tx = wxStaticText:new(Dialog, ?wxID_ANY, URL),
|
||||||
|
_ = wxStaticBoxSizer:add(URL_Sz, URL_Tx, zxw:flags(wide)),
|
||||||
|
MessSz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("Base-64 Data")}]),
|
||||||
|
MessStyle = ?wxTE_MULTILINE bor ?wxTE_READONLY,
|
||||||
|
MessTx = wxTextCtrl:new(Dialog, ?wxID_ANY, [{value, Base64}, {style, MessStyle}]),
|
||||||
|
_ = wxStaticBoxSizer:add(MessSz, MessTx, zxw:flags(wide)),
|
||||||
|
ButtSz = wxBoxSizer:new(?wxHORIZONTAL),
|
||||||
|
Affirm = wxButton:new(Dialog, ?wxID_OK),
|
||||||
|
Cancel = wxButton:new(Dialog, ?wxID_CANCEL),
|
||||||
|
_ = wxBoxSizer:add(ButtSz, Affirm, zxw:flags(wide)),
|
||||||
|
_ = wxBoxSizer:add(ButtSz, Cancel, zxw:flags(wide)),
|
||||||
|
_ = wxBoxSizer:add(Sizer, InstTx, zxw:flags(wide)),
|
||||||
|
_ = wxBoxSizer:add(Sizer, AcctSz, zxw:flags(wide)),
|
||||||
|
_ = wxBoxSizer:add(Sizer, URL_Sz, zxw:flags(wide)),
|
||||||
|
_ = wxBoxSizer:add(Sizer, MessSz, zxw:flags(wide)),
|
||||||
|
_ = wxBoxSizer:add(Sizer, ButtSz, zxw:flags(base)),
|
||||||
|
ok = wxDialog:setSizer(Dialog, Sizer),
|
||||||
|
ok = wxDialog:setSize(Dialog, {500, 500}),
|
||||||
|
ok = wxBoxSizer:layout(Sizer),
|
||||||
|
ok = wxFrame:center(Dialog),
|
||||||
|
ok =
|
||||||
|
case wxDialog:showModal(Dialog) of
|
||||||
|
?wxID_OK -> gd_con:sign_binary(Request);
|
||||||
|
?wxID_CANCEL -> ok
|
||||||
|
end,
|
||||||
|
wxDialog:destroy(Dialog);
|
||||||
do_grids_mess_sig2(Request = #{"grids" := 1,
|
do_grids_mess_sig2(Request = #{"grids" := 1,
|
||||||
"type" := "tx",
|
"type" := "tx",
|
||||||
"url" := URL,
|
"url" := URL,
|
||||||
@@ -1118,37 +1018,3 @@ do_grids_mess_sig2(Request = #{"grids" := 1,
|
|||||||
wxDialog:destroy(Dialog);
|
wxDialog:destroy(Dialog);
|
||||||
do_grids_mess_sig2(BadRequest, _) ->
|
do_grids_mess_sig2(BadRequest, _) ->
|
||||||
tell("Bad request: ~tp", [BadRequest]).
|
tell("Bad request: ~tp", [BadRequest]).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%%% Helpers
|
|
||||||
|
|
||||||
|
|
||||||
price_to_string(Pucks) ->
|
|
||||||
Gaju = 1_000_000_000_000_000_000,
|
|
||||||
H = integer_to_list(Pucks div Gaju),
|
|
||||||
R = Pucks rem Gaju,
|
|
||||||
case string:strip(lists:flatten(io_lib:format("~18..0w", [R])), right, $0) of
|
|
||||||
[] -> H;
|
|
||||||
T -> string:join([H, T], ".")
|
|
||||||
end.
|
|
||||||
|
|
||||||
string_to_price(String) ->
|
|
||||||
case string:split(String, ".") of
|
|
||||||
[H] -> join_price(H, "0");
|
|
||||||
[H, T] -> join_price(H, T);
|
|
||||||
_ -> {error, bad_price}
|
|
||||||
end.
|
|
||||||
|
|
||||||
join_price(H, T) ->
|
|
||||||
try
|
|
||||||
Parts = [H, string:pad(T, 18, trailing, $0)],
|
|
||||||
Price = list_to_integer(unicode:characters_to_list(Parts)),
|
|
||||||
case Price < 0 of
|
|
||||||
false -> {ok, Price};
|
|
||||||
true -> {error, negative_price}
|
|
||||||
end
|
|
||||||
catch
|
|
||||||
error:R -> {error, R}
|
|
||||||
end.
|
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@
|
|||||||
%%% translation library is retained).
|
%%% translation library is retained).
|
||||||
|
|
||||||
-module(gd_jt).
|
-module(gd_jt).
|
||||||
-vsn("0.7.0").
|
-vsn("0.9.0").
|
||||||
-export([read_translations/1, j/2, oneshot_j/2]).
|
-export([read_translations/1, j/2, oneshot_j/2]).
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+104
@@ -0,0 +1,104 @@
|
|||||||
|
%%% @doc
|
||||||
|
%%% GajuDesk Helper Functions
|
||||||
|
%%% @end
|
||||||
|
|
||||||
|
-module(gd_lib).
|
||||||
|
-vsn("0.9.0").
|
||||||
|
|
||||||
|
-include_lib("wx/include/wx.hrl").
|
||||||
|
-export([is_int/1,
|
||||||
|
mono_text/2, mono_text/3, mono_text/4,
|
||||||
|
button/2, button/3,
|
||||||
|
copy_to_clipboard/1]).
|
||||||
|
|
||||||
|
-include("$zx_include/zx_logger.hrl").
|
||||||
|
-include("gd.hrl").
|
||||||
|
-include("gdl.hrl").
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-spec is_int(string()) -> boolean().
|
||||||
|
%% @doc
|
||||||
|
%% A simple boolean check over whether every character in a string is part of an integer value
|
||||||
|
%% without the trashy `try .. catch' way.
|
||||||
|
|
||||||
|
is_int(S) ->
|
||||||
|
lists:all(fun(C) -> $0 =< C andalso C =< $9 end, S).
|
||||||
|
|
||||||
|
|
||||||
|
-spec mono_text(Parent, Name) -> StaticText
|
||||||
|
when Parent :: wxWindow:wxWindow(),
|
||||||
|
Name :: term(),
|
||||||
|
StaticText :: #wx{}.
|
||||||
|
%% @doc
|
||||||
|
%% Creates a blank monospace font static text field.
|
||||||
|
%% @equiv mono_text(Parent, Name, "").
|
||||||
|
|
||||||
|
mono_text(Parent, Name) ->
|
||||||
|
mono_text(Parent, Name, "").
|
||||||
|
|
||||||
|
|
||||||
|
-spec mono_text(Parent, Name, Value) -> StaticText
|
||||||
|
when Parent :: wxWindow:wxWindow(),
|
||||||
|
Name :: term(),
|
||||||
|
Value :: string(),
|
||||||
|
StaticText :: #w{}.
|
||||||
|
%% @doc
|
||||||
|
%% Creats a monospace font static text field with the given value.
|
||||||
|
%% This exists so that I don't have to remember the difference between how to create a styled
|
||||||
|
%% wxStaticText vs wxTextCtrl (which has to do it in a weird way because it has a much richer
|
||||||
|
%% notion of text styling).
|
||||||
|
|
||||||
|
mono_text(Parent, Name, Value) ->
|
||||||
|
mono_text(Parent, Name, Value, []).
|
||||||
|
|
||||||
|
mono_text(Parent, Name, Value, Options) ->
|
||||||
|
Text = wxTextCtrl:new(Parent, ?wxID_ANY, [{value, Value} | Options]),
|
||||||
|
Font = wxFont:new(10, ?wxFONTFAMILY_TELETYPE, ?wxFONTSTYLE_NORMAL, ?wxFONTWEIGHT_NORMAL),
|
||||||
|
ok =
|
||||||
|
case wxTextCtrl:setFont(Text, Font) of
|
||||||
|
true -> ok;
|
||||||
|
false -> tell(info, "wxStaticText ~p is already monospace.", [Text])
|
||||||
|
end,
|
||||||
|
#w{name = Name, id = wxTextCtrl:getId(Text), wx = Text}.
|
||||||
|
|
||||||
|
|
||||||
|
-spec button(Parent, Label) -> Button
|
||||||
|
when Parent :: wxWindow:wxWindow(),
|
||||||
|
Label :: string(),
|
||||||
|
Button :: #w{}.
|
||||||
|
|
||||||
|
button(Parent, Label) ->
|
||||||
|
button(Parent, Label, Label).
|
||||||
|
|
||||||
|
|
||||||
|
-spec button(Parent, Name, Label) -> Button
|
||||||
|
when Parent :: wxWindow:wxWindow(),
|
||||||
|
Name :: term(),
|
||||||
|
Label :: string(),
|
||||||
|
Button :: #wx{}.
|
||||||
|
|
||||||
|
button(Parent, Name, Label) ->
|
||||||
|
Button = wxButton:new(Parent, ?wxID_ANY, [{label, Label}]),
|
||||||
|
#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.
|
||||||
@@ -0,0 +1,284 @@
|
|||||||
|
%%% @doc
|
||||||
|
%%% A live modal for creating a SpendTX
|
||||||
|
%%% @end
|
||||||
|
|
||||||
|
-module(gd_m_spend).
|
||||||
|
-vsn("0.9.0").
|
||||||
|
-author("Craig Everett <zxq9@zxq9.com>").
|
||||||
|
-copyright("Craig Everett <zxq9@zxq9.com>").
|
||||||
|
-license("GPL-3.0-or-later").
|
||||||
|
|
||||||
|
%-behavior(zxw_modal).
|
||||||
|
|
||||||
|
-export([show/2]).
|
||||||
|
-export([init/1, handle_info/2, handle_event/2]).
|
||||||
|
|
||||||
|
-include_lib("wx/include/wx.hrl").
|
||||||
|
-include("$zx_include/zx_logger.hrl").
|
||||||
|
-include("gd.hrl").
|
||||||
|
|
||||||
|
-record(s,
|
||||||
|
{frame = none :: none | wx:wx_object(),
|
||||||
|
parent = none :: none | wx:wx_object(),
|
||||||
|
caller = none :: none | pid(),
|
||||||
|
j = j() :: fun(),
|
||||||
|
to_tx = none :: none | wx:wx_object(),
|
||||||
|
amount_tx = none :: none | wx:wx_object(),
|
||||||
|
payload_tx = none :: none | wx:wx_object(),
|
||||||
|
ttl_sl = none :: none | wx:wx_object(),
|
||||||
|
gas_sl = none :: none | wx:wx_object(),
|
||||||
|
affirm = none :: none | wx:wx_object(),
|
||||||
|
cancel = none :: none | wx:wx_object()}).
|
||||||
|
|
||||||
|
j() ->
|
||||||
|
fun(X) -> X end.
|
||||||
|
|
||||||
|
|
||||||
|
%%% Interface
|
||||||
|
|
||||||
|
-spec show(Parent, Args) -> {ok, #spend_tx{}} | cancel
|
||||||
|
when Parent :: wxFrame:wxFrame(),
|
||||||
|
Args :: {Account :: iolist(),
|
||||||
|
Nonce :: pos_integer(),
|
||||||
|
Height :: pos_integer(),
|
||||||
|
J :: fun()}.
|
||||||
|
|
||||||
|
show(Parent, Args) ->
|
||||||
|
zxw_modal:show(Parent, ?MODULE, Args).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%% Init
|
||||||
|
|
||||||
|
init({Parent, Caller, {Account, J}}) ->
|
||||||
|
Frame = wxFrame:new(Parent, ?wxID_ANY, J("Transfer Gajus")),
|
||||||
|
Panel = wxWindow:new(Frame, ?wxID_ANY),
|
||||||
|
TopSz = wxBoxSizer:new(?wxVERTICAL),
|
||||||
|
_ = wxBoxSizer:add(TopSz, Panel, zxw:flags(wide)),
|
||||||
|
MainSz = wxBoxSizer:new(?wxVERTICAL),
|
||||||
|
|
||||||
|
FromTx = wxStaticText:new(Panel, ?wxID_ANY, Account),
|
||||||
|
FromSz = wxStaticBoxSizer:new(?wxVERTICAL, Panel, [{label, J("From")}]),
|
||||||
|
_ = wxStaticBoxSizer:add(FromSz, FromTx, zxw:flags({wide, 5})),
|
||||||
|
ToTx = wxTextCtrl:new(Panel, ?wxID_ANY),
|
||||||
|
ToSz = wxStaticBoxSizer:new(?wxVERTICAL, Panel, [{label, J("To")}]),
|
||||||
|
_ = wxStaticBoxSizer:add(ToSz, ToTx, zxw:flags({wide, 5})),
|
||||||
|
AmtTx = wxTextCtrl:new(Panel, ?wxID_ANY),
|
||||||
|
AmtSz = wxStaticBoxSizer:new(?wxVERTICAL, Panel, [{label, J("Amount")}]),
|
||||||
|
AmtInSz = wxBoxSizer:new(?wxHORIZONTAL),
|
||||||
|
_ = wxStaticBoxSizer:add(AmtInSz, AmtTx, zxw:flags({wide, 5})),
|
||||||
|
_ = wxStaticBoxSizer:add(AmtSz, AmtInSz, zxw:flags({wide, 5})),
|
||||||
|
PayloadTx = wxTextCtrl:new(Panel, ?wxID_ANY, [{style, ?wxTE_MULTILINE}]),
|
||||||
|
PayloadSz = wxStaticBoxSizer:new(?wxVERTICAL, Panel, [{label, J("Message")}]),
|
||||||
|
_ = wxStaticBoxSizer:add(PayloadSz, PayloadTx, zxw:flags({wide, 5})),
|
||||||
|
Style = [{style, ?wxSL_HORIZONTAL bor ?wxSL_LABELS}],
|
||||||
|
TTL_Sl = wxSlider:new(Panel, ?wxID_ANY, 100, 10, 1000, Style),
|
||||||
|
TTL_Sz = wxStaticBoxSizer:new(?wxVERTICAL, Panel, [{label, J("TTL")}]),
|
||||||
|
_ = wxStaticBoxSizer:add(TTL_Sz, TTL_Sl, zxw:flags({wide, 5})),
|
||||||
|
Min = hz:min_gas_price(),
|
||||||
|
Max = Min * 2,
|
||||||
|
GasSl = wxSlider:new(Panel, ?wxID_ANY, Min, Min, Max, Style),
|
||||||
|
GasSz = wxStaticBoxSizer:new(?wxVERTICAL, Panel, [{label, J("Gas Price")}]),
|
||||||
|
_ = wxStaticBoxSizer:add(GasSz, GasSl, zxw:flags({wide, 5})),
|
||||||
|
ButtSz = wxBoxSizer:new(?wxHORIZONTAL),
|
||||||
|
Affirm = wxButton:new(Panel, ?wxID_ANY, [{label, J("OK")}]),
|
||||||
|
Cancel = wxButton:new(Panel, ?wxID_ANY, [{label, J("Cancel")}]),
|
||||||
|
_ = wxBoxSizer:add(ButtSz, Affirm, zxw:flags({wide, 5})),
|
||||||
|
_ = wxBoxSizer:add(ButtSz, Cancel, zxw:flags({wide, 5})),
|
||||||
|
_ = wxBoxSizer:add(MainSz, FromSz, zxw:flags({base, 5})),
|
||||||
|
_ = wxBoxSizer:add(MainSz, ToSz, zxw:flags({base, 5})),
|
||||||
|
_ = wxBoxSizer:add(MainSz, AmtSz, zxw:flags({base, 5})),
|
||||||
|
_ = wxBoxSizer:add(MainSz, PayloadSz, zxw:flags({wide, 5})),
|
||||||
|
_ = wxBoxSizer:add(MainSz, TTL_Sz, zxw:flags({base, 5})),
|
||||||
|
_ = wxBoxSizer:add(MainSz, GasSz, zxw:flags({base, 5})),
|
||||||
|
_ = wxBoxSizer:add(MainSz, ButtSz, zxw:flags({base, 5})),
|
||||||
|
HandleKey = key_handler(ToTx, AmtTx, PayloadTx, TTL_Sl, GasSl, Affirm, Cancel),
|
||||||
|
ok = wxFrame:connect(Frame, key_down, [{callback, HandleKey}]),
|
||||||
|
ok = wxTextCtrl:connect(ToTx, key_down, [{callback, HandleKey}]),
|
||||||
|
ok = wxTextCtrl:connect(AmtTx, key_down, [{callback, HandleKey}]),
|
||||||
|
ok = wxTextCtrl:connect(PayloadTx, key_down, [{callback, HandleKey}]),
|
||||||
|
ok = wxTextCtrl:connect(TTL_Sl, key_down, [{callback, HandleKey}]),
|
||||||
|
ok = wxTextCtrl:connect(GasSl, key_down, [{callback, HandleKey}]),
|
||||||
|
ok = wxTextCtrl:connect(Affirm, key_down, [{callback, HandleKey}]),
|
||||||
|
ok = wxTextCtrl:connect(Cancel, key_down, [{callback, HandleKey}]),
|
||||||
|
ok = wxFrame:connect(Frame, command_button_clicked),
|
||||||
|
ok = wxFrame:connect(Frame, close_window),
|
||||||
|
ok = wxFrame:setSize(Frame, {500, 650}),
|
||||||
|
ok = wxFrame:center(Frame),
|
||||||
|
ok = wxWindow:setSizer(Panel, MainSz),
|
||||||
|
ok = wxFrame:setSizer(Frame, TopSz),
|
||||||
|
ok = wxBoxSizer:layout(MainSz),
|
||||||
|
ok = wxFrame:centerOnParent(Frame),
|
||||||
|
true = wxFrame:show(Frame),
|
||||||
|
self() ! {focus, to_tx},
|
||||||
|
State =
|
||||||
|
#s{frame = Frame, parent = Parent, caller = Caller,
|
||||||
|
to_tx = ToTx, amount_tx = AmtTx, payload_tx = PayloadTx,
|
||||||
|
ttl_sl = TTL_Sl, gas_sl = GasSl,
|
||||||
|
affirm = Affirm, cancel = Cancel},
|
||||||
|
{Frame, State}.
|
||||||
|
|
||||||
|
|
||||||
|
key_handler(ToTx, AmtTx, PayloadTx, TTL_Sl, GasSl, Affirm, Cancel) ->
|
||||||
|
Me = self(),
|
||||||
|
ToID = wxTextCtrl:getId(ToTx),
|
||||||
|
AmtID = wxTextCtrl:getId(AmtTx),
|
||||||
|
PL_ID = wxTextCtrl:getId(PayloadTx),
|
||||||
|
TTL_ID = wxSlider:getId(TTL_Sl),
|
||||||
|
GasID = wxSlider:getId(GasSl),
|
||||||
|
AffirmID = wxButton:getId(Affirm),
|
||||||
|
CancelID = wxButton:getId(Cancel),
|
||||||
|
fun(#wx{id = ID, event = #wxKey{type = key_down, keyCode = Code}}, KeyPress) ->
|
||||||
|
case {Code, wxKeyEvent:shiftDown(KeyPress)} of
|
||||||
|
{9, false} ->
|
||||||
|
case ID of
|
||||||
|
ToID -> Me ! {focus, amount_tx};
|
||||||
|
AmtID -> Me ! {focus, payload_tx};
|
||||||
|
PL_ID -> Me ! {focus, ttl_sl};
|
||||||
|
TTL_ID -> Me ! {focus, gas_sl};
|
||||||
|
GasID -> Me ! {focus, affirm};
|
||||||
|
AffirmID -> Me ! {focus, cancel};
|
||||||
|
CancelID -> Me ! {focus, to_tx};
|
||||||
|
_ -> wxEvent:skip(KeyPress)
|
||||||
|
end;
|
||||||
|
{9, true} ->
|
||||||
|
case ID of
|
||||||
|
ToID -> Me ! {focus, cancel};
|
||||||
|
AmtID -> Me ! {focus, to_tx};
|
||||||
|
PL_ID -> Me ! {focus, amount_tx};
|
||||||
|
TTL_ID -> Me ! {focus, payload_tx};
|
||||||
|
GasID -> Me ! {focus, ttl_sl};
|
||||||
|
AffirmID -> Me ! {focus, gas_sl};
|
||||||
|
CancelID -> Me ! {focus, affirm};
|
||||||
|
_ -> wxEvent:skip(KeyPress)
|
||||||
|
end;
|
||||||
|
{13, _} ->
|
||||||
|
case ID of
|
||||||
|
ToID -> Me ! {tab, to_tx};
|
||||||
|
AmtID -> Me ! {tab, amount_tx};
|
||||||
|
PL_ID -> Me ! {tab, payload_tx};
|
||||||
|
TTL_ID -> Me ! {tab, ttl_sl};
|
||||||
|
GasID -> Me ! {tab, gas_sl};
|
||||||
|
AffirmID -> Me ! {enter, affirm};
|
||||||
|
CancelID -> Me ! {enter, cancel};
|
||||||
|
_ -> wxEvent:skip(KeyPress)
|
||||||
|
end;
|
||||||
|
{27, _} ->
|
||||||
|
Me ! esc;
|
||||||
|
{_, _} ->
|
||||||
|
wxEvent:skip(KeyPress)
|
||||||
|
end
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
handle_info({focus, Element}, State) ->
|
||||||
|
ok = focus(Element, State),
|
||||||
|
{noreply, State};
|
||||||
|
handle_info({enter, affirm}, State) ->
|
||||||
|
check(State);
|
||||||
|
handle_info({enter, cancel}, State) ->
|
||||||
|
cancel(State);
|
||||||
|
handle_info(esc, State) ->
|
||||||
|
ok = cancel(State),
|
||||||
|
{noreply, State};
|
||||||
|
handle_info(Message, State) ->
|
||||||
|
ok = log(warning, "Message: ~p~nState: ~p~n", [Message, State]),
|
||||||
|
{noreply, State}.
|
||||||
|
|
||||||
|
|
||||||
|
handle_event(#wx{event = #wxCommand{type = command_button_clicked}, id = ID},
|
||||||
|
State = #s{affirm = Affirm, cancel = Cancel}) ->
|
||||||
|
AffirmID = wxButton:getId(Affirm),
|
||||||
|
CancelID = wxButton:getId(Cancel),
|
||||||
|
NewState =
|
||||||
|
case ID of
|
||||||
|
AffirmID -> check(State);
|
||||||
|
CancelID -> cancel(State)
|
||||||
|
end,
|
||||||
|
{noreply, NewState};
|
||||||
|
handle_event(#wx{event = #wxClose{}}, State) ->
|
||||||
|
NewState = cancel(State),
|
||||||
|
{noreply, NewState};
|
||||||
|
handle_event(Event, State) ->
|
||||||
|
ok = log(warning, "Unexpected event ~tp State: ~tp~n", [Event, State]),
|
||||||
|
{noreply, State}.
|
||||||
|
|
||||||
|
|
||||||
|
%%% Doers
|
||||||
|
|
||||||
|
focus(to_tx, #s{to_tx = ToTX}) -> wxTextCtrl:setFocus(ToTX);
|
||||||
|
focus(amount_tx, #s{amount_tx = AmountTX}) -> wxTextCtrl:setFocus(AmountTX);
|
||||||
|
focus(payload_tx, #s{payload_tx = PayloadTX}) -> wxTextCtrl:setFocus(PayloadTX);
|
||||||
|
focus(ttl_sl, #s{ttl_sl = TTL_SL}) -> wxSlider:setFocus(TTL_SL);
|
||||||
|
focus(gas_sl, #s{gas_sl = GasSL}) -> wxSlider:setFocus(GasSL);
|
||||||
|
focus(affirm, #s{affirm = Affirm}) -> wxButton:setFocus(Affirm);
|
||||||
|
focus(cancel, #s{cancel = Cancel}) -> wxButton:setFocus(Cancel).
|
||||||
|
|
||||||
|
|
||||||
|
cancel(#s{frame = Frame, caller = Caller}) ->
|
||||||
|
ok = wxFrame:destroy(Frame),
|
||||||
|
zxw_modal:done(Caller, cancel).
|
||||||
|
|
||||||
|
|
||||||
|
check(State =#s{frame = Frame, caller = Caller, j = J,
|
||||||
|
to_tx = ToTx, amount_tx = AmountTx, payload_tx = PayloadTx,
|
||||||
|
ttl_sl = TTL_Sl, gas_sl = GasSl}) ->
|
||||||
|
DirtyTX =
|
||||||
|
[{recipient_id, wxTextCtrl:getValue(ToTx)},
|
||||||
|
{amount, wxTextCtrl:getValue(AmountTx)},
|
||||||
|
{gas_price, wxSlider:getValue(GasSl)},
|
||||||
|
{ttl, wxSlider:getValue(TTL_Sl)},
|
||||||
|
{payload, wxTextCtrl:getValue(PayloadTx)}],
|
||||||
|
ok =
|
||||||
|
case clean_spend(DirtyTX, #spend_tx{}, J, []) of
|
||||||
|
{ok, CleanTX} ->
|
||||||
|
ok = wxFrame:destroy(Frame),
|
||||||
|
zxw_modal:done(Caller, {ok, CleanTX});
|
||||||
|
{error, Errors} ->
|
||||||
|
DerpyDerpDerp = form_message(Errors, J),
|
||||||
|
ok = zxw:show_message(Frame, DerpyDerpDerp),
|
||||||
|
State
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
% TODO: There should be some suggestive logic around gas prices, both based on how large
|
||||||
|
% the payload and TTL are, but also the ingoing current common gas rate. This will require
|
||||||
|
% a "gas station" sort of analysis app to query, though.
|
||||||
|
clean_spend([{recipient_id, ""} | Rest], TX, J, Errors) ->
|
||||||
|
NewErrors = [{recipient_id, J("Recipient field is empty.")} | Errors],
|
||||||
|
clean_spend(Rest, TX, J, NewErrors);
|
||||||
|
clean_spend([{recipient_id, Recipient} | Rest], TX, J, Errors) ->
|
||||||
|
clean_spend(Rest, TX#spend_tx{recipient_id = list_to_binary(Recipient)}, J, Errors);
|
||||||
|
clean_spend([{amount, ""} | Rest], TX, J, Errors) ->
|
||||||
|
clean_spend(Rest, TX#spend_tx{amount = 0}, J, Errors);
|
||||||
|
clean_spend([{amount, S} | Rest], TX, J, Errors) ->
|
||||||
|
{NewTX, NewErrors} =
|
||||||
|
case hz_format:read(S) of
|
||||||
|
{ok, Amount} ->
|
||||||
|
{TX#spend_tx{amount = Amount}, Errors};
|
||||||
|
error ->
|
||||||
|
Derp = J("Amount field is not properly formatted."),
|
||||||
|
{TX, [{amount, Derp} | Errors]}
|
||||||
|
end,
|
||||||
|
clean_spend(Rest, NewTX, J, NewErrors);
|
||||||
|
clean_spend([{gas_price, GasPrice} | Rest], TX, J, Errors) ->
|
||||||
|
clean_spend(Rest, TX#spend_tx{gas_price = GasPrice}, J, Errors);
|
||||||
|
clean_spend([{ttl, TTL} | Rest], TX, J, Errors) ->
|
||||||
|
clean_spend(Rest, TX#spend_tx{ttl = TTL}, J, Errors);
|
||||||
|
clean_spend([{payload, S} | Rest], TX, J, Errors) ->
|
||||||
|
clean_spend(Rest, TX#spend_tx{payload = list_to_binary(S)}, J, Errors);
|
||||||
|
clean_spend([], TX, _, []) ->
|
||||||
|
{ok, TX};
|
||||||
|
clean_spend([], _, _, Errors) ->
|
||||||
|
{error, Errors}.
|
||||||
|
|
||||||
|
|
||||||
|
form_message(Errors, J) ->
|
||||||
|
Header = J("The following errors were encountered:"),
|
||||||
|
unicode:characters_to_list([Header, "\n", assemble(Errors)]).
|
||||||
|
|
||||||
|
% TODO: Highlight the fields since we know them.
|
||||||
|
assemble([{_, M} | T]) -> [M, "\n" | assemble(T)];
|
||||||
|
assemble([]) -> [].
|
||||||
|
|
||||||
@@ -0,0 +1,184 @@
|
|||||||
|
%%% @doc
|
||||||
|
%%% A live modal for importing a wallet.
|
||||||
|
%%%
|
||||||
|
%%% Interprets [ENTER] as an "OK" button click and [ESC] as a "Cancel" button click.
|
||||||
|
%%% @end
|
||||||
|
|
||||||
|
-module(gd_m_wallet_importer).
|
||||||
|
-vsn("0.9.0").
|
||||||
|
-author("Craig Everett <zxq9@zxq9.com>").
|
||||||
|
-copyright("Craig Everett <zxq9@zxq9.com>").
|
||||||
|
-license("GPL-3.0-or-later").
|
||||||
|
|
||||||
|
-behavior(zxw_modal).
|
||||||
|
|
||||||
|
-export([show/6]).
|
||||||
|
-export([init/1, handle_info/2, handle_event/2]).
|
||||||
|
|
||||||
|
-include_lib("wx/include/wx.hrl").
|
||||||
|
-include("$zx_include/zx_logger.hrl").
|
||||||
|
|
||||||
|
-record(s,
|
||||||
|
{frame = none :: none | wx:wx_object(),
|
||||||
|
parent = none :: none | wx:wx_object(),
|
||||||
|
caller = none :: none | pid(),
|
||||||
|
name_tx = none :: none | wx:wx_object(),
|
||||||
|
pass_tx = none :: none | wx:wx_object(),
|
||||||
|
ok = none :: none | wx:wx_object(),
|
||||||
|
cancel = none :: none | wx:wx_object()}).
|
||||||
|
|
||||||
|
|
||||||
|
%%% Interface
|
||||||
|
|
||||||
|
-spec show(Parent, Title, NameLabel, PassLabel, OK_L, Cancel_L) -> {ok, Name, Pass} | cancel
|
||||||
|
when Parent :: wxFrame:wxFrame(),
|
||||||
|
Title :: string(),
|
||||||
|
NameLabel :: string(),
|
||||||
|
PassLabel :: string(),
|
||||||
|
OK_L :: string(),
|
||||||
|
Cancel_L :: string(),
|
||||||
|
Name :: string(),
|
||||||
|
Pass :: string() | none.
|
||||||
|
|
||||||
|
show(Parent, Title, NameLabel, PassLabel, OK_L, Cancel_L) ->
|
||||||
|
zxw_modal:show(Parent, ?MODULE, {Title, NameLabel, PassLabel, OK_L, Cancel_L}).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%% Init
|
||||||
|
|
||||||
|
init({Parent, Caller, {Title, NameLabel, PassLabel, OK_L, Cancel_L}}) ->
|
||||||
|
Frame = wxFrame:new(Parent, ?wxID_ANY, Title),
|
||||||
|
Panel = wxWindow:new(Frame, ?wxID_ANY),
|
||||||
|
TopSz = wxBoxSizer:new(?wxVERTICAL),
|
||||||
|
_ = wxBoxSizer:add(TopSz, Panel, zxw:flags(wide)),
|
||||||
|
MainSz = wxBoxSizer:new(?wxVERTICAL),
|
||||||
|
NameSz = wxStaticBoxSizer:new(?wxVERTICAL, Panel, [{label, NameLabel}]),
|
||||||
|
NameTx = wxTextCtrl:new(Panel, ?wxID_ANY, [{style, ?wxTE_PROCESS_TAB}]),
|
||||||
|
_ = wxSizer:add(NameSz, NameTx, zxw:flags({wide, 5})),
|
||||||
|
PassSz = wxStaticBoxSizer:new(?wxVERTICAL, Panel, [{label, PassLabel}]),
|
||||||
|
PassTx = wxTextCtrl:new(Panel, ?wxID_ANY, [{style, ?wxTE_PROCESS_TAB bor ?wxTE_PASSWORD}]),
|
||||||
|
_ = wxSizer:add(PassSz, PassTx, zxw:flags({wide, 5})),
|
||||||
|
OK = wxButton:new(Panel, ?wxID_ANY, [{label, OK_L}]),
|
||||||
|
Cancel = wxButton:new(Panel, ?wxID_ANY, [{label, Cancel_L}]),
|
||||||
|
ButtSz = wxBoxSizer:new(?wxHORIZONTAL),
|
||||||
|
_ = wxBoxSizer:add(ButtSz, OK, zxw:flags({wide, 5})),
|
||||||
|
_ = wxBoxSizer:add(ButtSz, Cancel, zxw:flags({wide, 5})),
|
||||||
|
_ = wxBoxSizer:add(MainSz, NameSz, zxw:flags({wide, 5})),
|
||||||
|
_ = wxBoxSizer:add(MainSz, PassSz, zxw:flags({wide, 5})),
|
||||||
|
_ = wxBoxSizer:add(MainSz, ButtSz, zxw:flags({wide, 5})),
|
||||||
|
HandleKey = key_handler(NameTx, PassTx, OK, Cancel),
|
||||||
|
ok = wxFrame:connect(Frame, key_down, [{callback, HandleKey}]),
|
||||||
|
ok = wxTextCtrl:connect(NameTx, key_down, [{callback, HandleKey}]),
|
||||||
|
ok = wxTextCtrl:connect(PassTx, key_down, [{callback, HandleKey}]),
|
||||||
|
ok = wxTextCtrl:connect(OK, key_down, [{callback, HandleKey}]),
|
||||||
|
ok = wxTextCtrl:connect(Cancel, key_down, [{callback, HandleKey}]),
|
||||||
|
ok = wxFrame:connect(Frame, command_button_clicked),
|
||||||
|
ok = wxFrame:connect(Frame, close_window),
|
||||||
|
ok = wxFrame:setSize(Frame, {500, 220}),
|
||||||
|
ok = wxWindow:setSizer(Panel, MainSz),
|
||||||
|
ok = wxFrame:setSizer(Frame, TopSz),
|
||||||
|
ok = wxBoxSizer:layout(MainSz),
|
||||||
|
ok = wxFrame:centerOnParent(Frame),
|
||||||
|
ok = wxTextCtrl:setFocus(NameTx),
|
||||||
|
true = wxFrame:show(Frame),
|
||||||
|
State =
|
||||||
|
#s{frame = Frame, parent = Parent, caller = Caller,
|
||||||
|
name_tx = NameTx, pass_tx = PassTx,
|
||||||
|
ok = OK, cancel = Cancel},
|
||||||
|
{Frame, State}.
|
||||||
|
|
||||||
|
|
||||||
|
key_handler(NameTx, PassTx, OK, Cancel) ->
|
||||||
|
Me = self(),
|
||||||
|
NameID = wxTextCtrl:getId(NameTx),
|
||||||
|
PassID = wxTextCtrl:getId(PassTx),
|
||||||
|
OK_ID = wxButton:getId(OK),
|
||||||
|
CancelID = wxButton:getId(Cancel),
|
||||||
|
fun(#wx{id = ID, event = #wxKey{type = key_down, keyCode = Code}}, KeyPress) ->
|
||||||
|
case Code of
|
||||||
|
9 ->
|
||||||
|
case ID of
|
||||||
|
NameID -> Me ! {tab, name};
|
||||||
|
PassID -> Me ! {tab, pass};
|
||||||
|
OK_ID -> Me ! {tab, ok};
|
||||||
|
CancelID -> Me ! {tab, cancel};
|
||||||
|
_ -> wxEvent:skip(KeyPress)
|
||||||
|
end;
|
||||||
|
13 ->
|
||||||
|
case ID of
|
||||||
|
NameID -> Me ! {enter, name};
|
||||||
|
PassID -> Me ! {enter, pass};
|
||||||
|
_ -> wxEvent:skip(KeyPress)
|
||||||
|
end;
|
||||||
|
27 ->
|
||||||
|
Me ! esc;
|
||||||
|
_ ->
|
||||||
|
wxEvent:skip(KeyPress)
|
||||||
|
end
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
handle_info({tab, Element}, State) ->
|
||||||
|
ok = tab_traverse(Element, State),
|
||||||
|
{noreply, State};
|
||||||
|
handle_info({enter, name}, State = #s{pass_tx = PassTx}) ->
|
||||||
|
ok = wxTextCtrl:setFocus(PassTx),
|
||||||
|
{noreply, State};
|
||||||
|
handle_info({enter, pass}, State) ->
|
||||||
|
done(State);
|
||||||
|
handle_info(esc, State) ->
|
||||||
|
ok = cancel(State),
|
||||||
|
{noreply, State};
|
||||||
|
handle_info(Message, State) ->
|
||||||
|
ok = log(warning, "Message: ~p~nState: ~p~n", [Message, State]),
|
||||||
|
{noreply, State}.
|
||||||
|
|
||||||
|
|
||||||
|
handle_event(#wx{event = #wxCommand{type = command_button_clicked}, id = ID},
|
||||||
|
State = #s{ok = OK, cancel = Cancel}) ->
|
||||||
|
OK_ID = wxButton:getId(OK),
|
||||||
|
CancelID = wxButton:getId(Cancel),
|
||||||
|
case ID of
|
||||||
|
OK_ID -> done(State);
|
||||||
|
CancelID -> cancel(State)
|
||||||
|
end;
|
||||||
|
handle_event(#wx{event = #wxClose{}}, State) ->
|
||||||
|
NewState = cancel(State),
|
||||||
|
{noreply, NewState};
|
||||||
|
handle_event(Event, State) ->
|
||||||
|
ok = log(warning, "Unexpected event ~tp State: ~tp~n", [Event, State]),
|
||||||
|
{noreply, State}.
|
||||||
|
|
||||||
|
|
||||||
|
%%% Doers
|
||||||
|
|
||||||
|
tab_traverse(name, #s{pass_tx = PassTx}) ->
|
||||||
|
wxTextCtrl:setFocus(PassTx);
|
||||||
|
tab_traverse(pass, #s{ok = OK}) ->
|
||||||
|
wxButton:setFocus(OK);
|
||||||
|
tab_traverse(ok, #s{cancel = Cancel}) ->
|
||||||
|
wxButton:setFocus(Cancel);
|
||||||
|
tab_traverse(cancel, #s{name_tx = NameTx}) ->
|
||||||
|
wxTextCtrl:setFocus(NameTx).
|
||||||
|
|
||||||
|
|
||||||
|
cancel(#s{frame = Frame, caller = Caller}) ->
|
||||||
|
ok = wxFrame:destroy(Frame),
|
||||||
|
zxw_modal:done(Caller, cancel).
|
||||||
|
|
||||||
|
|
||||||
|
done(#s{frame = Frame, caller = Caller, name_tx = NameTx, pass_tx = PassTx}) ->
|
||||||
|
Result =
|
||||||
|
case wxTextCtrl:getValue(NameTx) of
|
||||||
|
"" ->
|
||||||
|
cancel;
|
||||||
|
Name ->
|
||||||
|
case wxTextCtrl:getValue(PassTx) of
|
||||||
|
"" -> {ok, Name, none};
|
||||||
|
Pass -> {ok, Name, Pass}
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
ok = wxFrame:destroy(Frame),
|
||||||
|
zxw_modal:done(Caller, Result).
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
-module(gd_sophia_editor).
|
-module(gd_sophia_editor).
|
||||||
-vsn("0.7.0").
|
-vsn("0.9.0").
|
||||||
-export([new/1, update/2,
|
-export([new/1, update/1, update/2,
|
||||||
get_text/1, set_text/2]).
|
get_text/1, set_text/2]).
|
||||||
|
|
||||||
-include("$zx_include/zx_logger.hrl").
|
-include("$zx_include/zx_logger.hrl").
|
||||||
@@ -26,6 +26,7 @@
|
|||||||
-define(H, 255). % High
|
-define(H, 255). % High
|
||||||
-define(M, 192). % Medium
|
-define(M, 192). % Medium
|
||||||
-define(L, 128). % Low
|
-define(L, 128). % Low
|
||||||
|
-define(D, 64). % Deep-Low
|
||||||
-define(X, 32). % X-Low
|
-define(X, 32). % X-Low
|
||||||
-define(Z, 0). % Zilch
|
-define(Z, 0). % Zilch
|
||||||
|
|
||||||
@@ -46,8 +47,9 @@
|
|||||||
-define(brown, {?L, ?L, ?Z}).
|
-define(brown, {?L, ?L, ?Z}).
|
||||||
-define(magenta, {?L, ?Z, ?L}).
|
-define(magenta, {?L, ?Z, ?L}).
|
||||||
-define(cyan, {?Z, ?L, ?L}).
|
-define(cyan, {?Z, ?L, ?L}).
|
||||||
-define(not_black, {?X, ?X, ?X}).
|
|
||||||
-define(grey, {?L, ?L, ?L}).
|
-define(grey, {?L, ?L, ?L}).
|
||||||
|
-define(dark_grey, {?D, ?D, ?D}).
|
||||||
|
-define(not_black, {?X, ?X, ?X}).
|
||||||
-define(white, {?M, ?M, ?M}).
|
-define(white, {?M, ?M, ?M}).
|
||||||
|
|
||||||
styles() ->
|
styles() ->
|
||||||
@@ -67,6 +69,9 @@ palette(light) ->
|
|||||||
?STRING => ?red,
|
?STRING => ?red,
|
||||||
?NUMBER => ?magenta,
|
?NUMBER => ?magenta,
|
||||||
?OPERATOR => ?brown,
|
?OPERATOR => ?brown,
|
||||||
|
sel_back => ?grey,
|
||||||
|
line_num => ?brown,
|
||||||
|
cursor => ?black,
|
||||||
bg => ?high_white};
|
bg => ?high_white};
|
||||||
palette(dark) ->
|
palette(dark) ->
|
||||||
#{?DEFAULT => ?white,
|
#{?DEFAULT => ?white,
|
||||||
@@ -76,6 +81,9 @@ palette(dark) ->
|
|||||||
?STRING => ?light_red,
|
?STRING => ?light_red,
|
||||||
?NUMBER => ?light_magenta,
|
?NUMBER => ?light_magenta,
|
||||||
?OPERATOR => ?yellow,
|
?OPERATOR => ?yellow,
|
||||||
|
sel_back => ?dark_grey,
|
||||||
|
line_num => ?yellow,
|
||||||
|
cursor => ?white,
|
||||||
bg => ?not_black}.
|
bg => ?not_black}.
|
||||||
|
|
||||||
color_mode() ->
|
color_mode() ->
|
||||||
@@ -97,6 +105,8 @@ new(Parent) ->
|
|||||||
[{face, "Monospace"}]),
|
[{face, "Monospace"}]),
|
||||||
SetMonospace = fun(Style) -> wxStyledTextCtrl:styleSetFont(STC, Style, Mono) end,
|
SetMonospace = fun(Style) -> wxStyledTextCtrl:styleSetFont(STC, Style, Mono) end,
|
||||||
ok = lists:foreach(SetMonospace, styles()),
|
ok = lists:foreach(SetMonospace, styles()),
|
||||||
|
ok = wxStyledTextCtrl:setMarginType(STC, 0, ?wxSTC_MARGIN_NUMBER),
|
||||||
|
ok = wxStyledTextCtrl:setMarginWidth(STC, 0, 40),
|
||||||
ok = wxStyledTextCtrl:styleSetFont(STC, ?wxSTC_STYLE_DEFAULT, Mono),
|
ok = wxStyledTextCtrl:styleSetFont(STC, ?wxSTC_STYLE_DEFAULT, Mono),
|
||||||
ok = set_colors(STC),
|
ok = set_colors(STC),
|
||||||
STC.
|
STC.
|
||||||
@@ -112,18 +122,25 @@ set_text(STC, Text) ->
|
|||||||
|
|
||||||
set_colors(STC) ->
|
set_colors(STC) ->
|
||||||
ok = wxStyledTextCtrl:styleClearAll(STC),
|
ok = wxStyledTextCtrl:styleClearAll(STC),
|
||||||
Palette = #{bg := BGC} = palette(color_mode()),
|
Palette = palette(color_mode()),
|
||||||
|
#{bg := BGC, cursor := CC, line_num := LNC, sel_back := SFB} = Palette,
|
||||||
Colorize =
|
Colorize =
|
||||||
fun(Style) ->
|
fun(Style) ->
|
||||||
Color = maps:get(Style, Palette),
|
Color = maps:get(Style, Palette),
|
||||||
ok = wxStyledTextCtrl:styleSetForeground(STC, Style, Color),
|
ok = wxStyledTextCtrl:styleSetForeground(STC, Style, Color),
|
||||||
ok = wxStyledTextCtrl:styleSetBackground(STC, Style, BGC)
|
ok = wxStyledTextCtrl:styleSetBackground(STC, Style, BGC)
|
||||||
end,
|
end,
|
||||||
|
ok = wxStyledTextCtrl:setCaretForeground(STC, CC),
|
||||||
|
ok = wxStyledTextCtrl:setSelBackground(STC, true, SFB),
|
||||||
|
ok = wxStyledTextCtrl:styleSetForeground(STC, ?wxSTC_STYLE_LINENUMBER, LNC),
|
||||||
ok = wxStyledTextCtrl:styleSetBackground(STC, ?wxSTC_STYLE_DEFAULT, BGC),
|
ok = wxStyledTextCtrl:styleSetBackground(STC, ?wxSTC_STYLE_DEFAULT, BGC),
|
||||||
lists:foreach(Colorize, styles()).
|
lists:foreach(Colorize, styles()).
|
||||||
|
|
||||||
|
|
||||||
update(_Event, STC) ->
|
update(_Event, STC) ->
|
||||||
|
update(STC).
|
||||||
|
|
||||||
|
update(STC) ->
|
||||||
Text = wxStyledTextCtrl:getText(STC),
|
Text = wxStyledTextCtrl:getText(STC),
|
||||||
case so_scan:scan(Text) of
|
case so_scan:scan(Text) of
|
||||||
{ok, Tokens} ->
|
{ok, Tokens} ->
|
||||||
|
|||||||
+1
-1
@@ -12,7 +12,7 @@
|
|||||||
%%% @end
|
%%% @end
|
||||||
|
|
||||||
-module(gd_sup).
|
-module(gd_sup).
|
||||||
-vsn("0.7.0").
|
-vsn("0.9.0").
|
||||||
-behaviour(supervisor).
|
-behaviour(supervisor).
|
||||||
-author("Craig Everett <craigeverett@qpq.swiss>").
|
-author("Craig Everett <craigeverett@qpq.swiss>").
|
||||||
-copyright("QPQ AG <info@qpq.swiss>").
|
-copyright("QPQ AG <info@qpq.swiss>").
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
-module(gd_v).
|
-module(gd_v).
|
||||||
-vsn("0.7.0").
|
-vsn("0.9.0").
|
||||||
-author("Craig Everett <craigeverett@qpq.swiss>").
|
-author("Craig Everett <craigeverett@qpq.swiss>").
|
||||||
-copyright("QPQ AG <info@qpq.swiss>").
|
-copyright("QPQ AG <info@qpq.swiss>").
|
||||||
-license("GPL-3.0-or-later").
|
-license("GPL-3.0-or-later").
|
||||||
|
|||||||
@@ -0,0 +1,596 @@
|
|||||||
|
-module(gd_v_call).
|
||||||
|
-vsn("0.9.0").
|
||||||
|
-author("Craig Everett <craigeverett@qpq.swiss>").
|
||||||
|
-copyright("QPQ AG <info@qpq.swiss>").
|
||||||
|
-license("GPL-3.0-or-later").
|
||||||
|
|
||||||
|
-behavior(wx_object).
|
||||||
|
%-behavior(gd_v).
|
||||||
|
-include_lib("wx/include/wx.hrl").
|
||||||
|
-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]).
|
||||||
|
-include("$zx_include/zx_logger.hrl").
|
||||||
|
-include("gd.hrl").
|
||||||
|
-include("gdl.hrl").
|
||||||
|
|
||||||
|
|
||||||
|
% State
|
||||||
|
-record(s,
|
||||||
|
{wx = none :: none | wx:wx_object(),
|
||||||
|
frame = none :: none | wx:wx_object(),
|
||||||
|
lang = en :: en | jp,
|
||||||
|
j = none :: none | fun(),
|
||||||
|
prefs = #{} :: map(),
|
||||||
|
con_id = <<"">> :: binary(),
|
||||||
|
fundef = none :: none | fun_def(),
|
||||||
|
funret = none :: none | term(), % FIXME
|
||||||
|
build = none :: none | map(),
|
||||||
|
args = [] :: [#w{}],
|
||||||
|
kp = #w{} :: #w{},
|
||||||
|
params = [] :: [param()],
|
||||||
|
return = #w{} :: #w{}, % wxTextCtrl, single-line
|
||||||
|
copy = #w{} :: #w{},
|
||||||
|
status = none :: status(),
|
||||||
|
action = #w{} :: #w{},
|
||||||
|
tx_data = none :: none | map(),
|
||||||
|
tx_info = none :: none | map(),
|
||||||
|
hash = #w{} :: #w{}, % wxTextCtrl, single-line
|
||||||
|
info = #w{} :: #w{}}). % wxTextCtrl, multi-line
|
||||||
|
|
||||||
|
|
||||||
|
-type fun_name() :: string().
|
||||||
|
-type fun_ilk() :: call | dryr | init.
|
||||||
|
-type fun_def() :: {fun_name(), fun_ilk()}.
|
||||||
|
-type param() :: {Label :: string(), Check :: fun(), #w{}}.
|
||||||
|
-type status() :: none
|
||||||
|
| submitted
|
||||||
|
| rejected
|
||||||
|
| included.
|
||||||
|
|
||||||
|
|
||||||
|
%%% Interface
|
||||||
|
|
||||||
|
-spec to_front(Win) -> ok
|
||||||
|
when Win :: wx:wx_object().
|
||||||
|
|
||||||
|
to_front(Win) ->
|
||||||
|
wx_object:cast(Win, to_front).
|
||||||
|
|
||||||
|
|
||||||
|
-spec tx_hash(Win) -> Result
|
||||||
|
when Win :: pid() | wx:wx_object(),
|
||||||
|
Result :: none | string().
|
||||||
|
|
||||||
|
tx_hash(Win) ->
|
||||||
|
wx_object:call(Win, tx_hash).
|
||||||
|
|
||||||
|
|
||||||
|
-spec tx_data(Win) -> Result
|
||||||
|
when Win :: pid() | wx:wx_object(),
|
||||||
|
Result :: none | map().
|
||||||
|
|
||||||
|
tx_data(Win) ->
|
||||||
|
wx_object:call(Win, tx_data).
|
||||||
|
|
||||||
|
|
||||||
|
-spec tx_info(Win) -> Result
|
||||||
|
when Win :: pid() | wx:wx_object(),
|
||||||
|
Result :: none | map().
|
||||||
|
|
||||||
|
tx_info(Win) ->
|
||||||
|
wx_object:call(Win, tx_info).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%%% Startup Functions
|
||||||
|
|
||||||
|
start_link(Args) ->
|
||||||
|
wx_object:start_link(?MODULE, Args, []).
|
||||||
|
|
||||||
|
|
||||||
|
init({Prefs, FunDef = {FunName, FunIlk}, ConID, Build, Selected, Keys}) ->
|
||||||
|
Lang = maps:get(lang, Prefs, en),
|
||||||
|
Trans = gd_jt:read_translations(?MODULE),
|
||||||
|
J = gd_jt:j(Lang, Trans),
|
||||||
|
{aaci, ConName, FunSpecs, _} = maps:get(aaci, Build),
|
||||||
|
FunSpec = {FunArgs, FunReturn} = maps:get(FunName, FunSpecs),
|
||||||
|
{CallTypeLabel, ActionLabel} =
|
||||||
|
case FunIlk of
|
||||||
|
call -> {J("Contract Call"), J("Submit Call")};
|
||||||
|
dryr -> {J("Dry Run"), J("Submit Dry Run")};
|
||||||
|
init -> {J("Deploy"), J("Deploy")}
|
||||||
|
end,
|
||||||
|
Arity = integer_to_list(length(FunArgs)),
|
||||||
|
Title = [CallTypeLabel, ": ", ConName, ".", FunName, "/", Arity],
|
||||||
|
Wx = wx:new(),
|
||||||
|
Frame = wxFrame:new(Wx, ?wxID_ANY, Title),
|
||||||
|
MainSz = wxBoxSizer:new(?wxVERTICAL),
|
||||||
|
|
||||||
|
KeySz = wxStaticBoxSizer:new(?wxVERTICAL, Frame, [{label, J("Signature Key")}]),
|
||||||
|
KeyBox = wxStaticBoxSizer:getStaticBox(KeySz),
|
||||||
|
KeyPicker = wxChoice:new(KeyBox, ?wxID_ANY, [{choices, Keys}]),
|
||||||
|
KP = #w{name = key_picker, id = wxChoice:getId(KeyPicker), wx = KeyPicker},
|
||||||
|
ZeroBasedSelected = Selected - 1,
|
||||||
|
ok = wxChoice:setSelection(KeyPicker, ZeroBasedSelected),
|
||||||
|
_ = wxStaticBoxSizer:add(KeySz, KeyPicker, zxw:flags(wide)),
|
||||||
|
|
||||||
|
{ArgSz, Args, Return, Copy, HasArgs} = call_arg_sizer(Frame, J, FunIlk, FunSpec),
|
||||||
|
{ParamSz, Params} = call_param_sizer(Frame, J),
|
||||||
|
|
||||||
|
Action = #w{wx = ActionBn} = gd_lib:button(Frame, ActionLabel),
|
||||||
|
|
||||||
|
TX_Sz = wxStaticBoxSizer:new(?wxVERTICAL, Frame, [{label, J("Transaction Info")}]),
|
||||||
|
TX_Sz_Box = wxStaticBoxSizer:getStaticBox(TX_Sz),
|
||||||
|
Single = [{style, ?wxTE_READONLY}],
|
||||||
|
Multi = [{style, ?wxTE_MULTILINE bor ?wxTE_READONLY}],
|
||||||
|
TX_Hash = #w{wx = HashT} = gd_lib:mono_text(TX_Sz_Box, tx_hash, "", Single),
|
||||||
|
TX_Info = #w{wx = InfoT} = gd_lib:mono_text(TX_Sz_Box, tx_info, "", Multi),
|
||||||
|
|
||||||
|
_ = wxStaticBoxSizer:add(TX_Sz, HashT, zxw:flags({base, 5})),
|
||||||
|
_ = wxStaticBoxSizer:add(TX_Sz, InfoT, zxw:flags({wide, 5})),
|
||||||
|
|
||||||
|
ArgSzArgs =
|
||||||
|
case HasArgs of
|
||||||
|
true -> [{proportion, 2}, {flag, ?wxEXPAND bor ?wxALL}, {border, 5}];
|
||||||
|
false -> zxw:flags({base, 5})
|
||||||
|
end,
|
||||||
|
_ = wxSizer:add(MainSz, ArgSz, ArgSzArgs),
|
||||||
|
_ = wxSizer:add(MainSz, KeySz, zxw:flags({base, 5})),
|
||||||
|
_ = wxSizer:add(MainSz, ParamSz, zxw:flags({base, 5})),
|
||||||
|
_ = wxSizer:add(MainSz, ActionBn, zxw:flags({base, 5})),
|
||||||
|
_ = wxSizer:add(MainSz, TX_Sz, [{proportion, 1}, {flag, ?wxEXPAND bor ?wxALL}, {border, 5}]),
|
||||||
|
|
||||||
|
_ = wxFrame:setSizer(Frame, MainSz),
|
||||||
|
_ = wxFrame:setSize(Frame, {900, 900}),
|
||||||
|
_ = wxSizer:layout(MainSz),
|
||||||
|
ok = wxFrame:connect(Frame, close_window),
|
||||||
|
ok = wxFrame:connect(Frame, command_button_clicked),
|
||||||
|
true = wxFrame:show(Frame),
|
||||||
|
State =
|
||||||
|
#s{wx = Wx, frame = Frame, j = J, prefs = Prefs,
|
||||||
|
fundef = FunDef, funret = FunReturn, con_id = ConID, build = Build,
|
||||||
|
args = Args, kp = KP, params = Params,
|
||||||
|
return = Return, copy = Copy,
|
||||||
|
action = Action, status = none,
|
||||||
|
hash = TX_Hash, info = TX_Info},
|
||||||
|
{Frame, State}.
|
||||||
|
|
||||||
|
|
||||||
|
call_arg_sizer(Frame, J, FunIlk, {CallArgs, ReturnType}) ->
|
||||||
|
SpecSz = wxStaticBoxSizer:new(?wxVERTICAL, Frame, [{label, J("Function Spec")}]),
|
||||||
|
SpecBox = wxStaticBoxSizer:getStaticBox(SpecSz),
|
||||||
|
{CallSz, CallControls, HasArgs} = call_sizer(SpecBox, J, CallArgs),
|
||||||
|
{ReturnSz, Return, Copy} = return_sizer(SpecBox, J, FunIlk, ReturnType),
|
||||||
|
_ = wxStaticBoxSizer:add(SpecSz, CallSz, zxw:flags({wide, 5})),
|
||||||
|
_ = wxStaticBoxSizer:add(SpecSz, ReturnSz, zxw:flags({base, 5})),
|
||||||
|
{SpecSz, CallControls, Return, Copy, HasArgs}.
|
||||||
|
|
||||||
|
call_sizer(Parent, J, []) ->
|
||||||
|
CallSz = wxStaticBoxSizer:new(?wxVERTICAL, Parent, [{label, J("Call Args")}]),
|
||||||
|
CallBox = wxStaticBoxSizer:getStaticBox(CallSz),
|
||||||
|
Args = wxStaticText:new(CallBox, ?wxID_ANY, ["[", J("No Args"), "]"]),
|
||||||
|
_ = wxStaticBoxSizer:add(CallSz, Args, zxw:flags({wide, 5})),
|
||||||
|
{CallSz, [], false};
|
||||||
|
call_sizer(Parent, J, CallArgs) ->
|
||||||
|
CallSz = wxStaticBoxSizer:new(?wxVERTICAL, Parent, [{label, J("Call Args")}]),
|
||||||
|
CallBox = wxStaticBoxSizer:getStaticBox(CallSz),
|
||||||
|
ScrollWin = wxScrolledWindow:new(CallBox),
|
||||||
|
ScrollSz = wxBoxSizer:new(?wxVERTICAL),
|
||||||
|
ok = wxScrolledWindow:setSizerAndFit(ScrollWin, ScrollSz),
|
||||||
|
ok = wxScrolledWindow:setScrollRate(ScrollWin, 5, 5),
|
||||||
|
GridSz = wxFlexGridSizer:new(2, [{gap, {4, 4}}]),
|
||||||
|
ok = wxFlexGridSizer:setFlexibleDirection(GridSz, ?wxHORIZONTAL),
|
||||||
|
ok = wxFlexGridSizer:addGrowableCol(GridSz, 1),
|
||||||
|
_ = wxStaticBoxSizer:add(ScrollSz, GridSz, zxw:flags(wide)),
|
||||||
|
_ = wxStaticBoxSizer:add(CallSz, ScrollWin, zxw:flags(wide)),
|
||||||
|
AddArg =
|
||||||
|
fun({Name, Type}) ->
|
||||||
|
L = wxStaticText:new(ScrollWin, ?wxID_ANY, [Name, " : ", textify(Type)]),
|
||||||
|
C = #w{wx = T} = gd_lib:mono_text(ScrollWin, Name),
|
||||||
|
_ = wxFlexGridSizer:add(GridSz, L, zxw:flags({base, 5})),
|
||||||
|
_ = wxFlexGridSizer:add(GridSz, T, zxw:flags({wide, 5})),
|
||||||
|
C
|
||||||
|
end,
|
||||||
|
Controls = lists:map(AddArg, CallArgs),
|
||||||
|
{CallSz, Controls, true}.
|
||||||
|
|
||||||
|
return_sizer(Parent, J, FunIlk, ReturnType) ->
|
||||||
|
IlkLabel =
|
||||||
|
case FunIlk =:= init of
|
||||||
|
false -> textify(ReturnType);
|
||||||
|
true -> J("Contract Address")
|
||||||
|
end,
|
||||||
|
ReturnSz = wxStaticBoxSizer:new(?wxVERTICAL, Parent, [{label, J("Return Type")}]),
|
||||||
|
ReturnSzBox = wxStaticBoxSizer:getStaticBox(ReturnSz),
|
||||||
|
ReturnLabel = wxStaticText:new(ReturnSzBox, ?wxID_ANY, IlkLabel),
|
||||||
|
Single = [{style, ?wxTE_READONLY}],
|
||||||
|
Return = #w{wx = ReturnTx} = gd_lib:mono_text(ReturnSzBox, return, "", Single),
|
||||||
|
Copy = #w{wx = CopyB} = gd_lib:button(ReturnSzBox, J("Copy")),
|
||||||
|
_ = wxButton:disable(CopyB),
|
||||||
|
_ = wxStaticBoxSizer:add(ReturnSz, ReturnLabel, zxw:flags({wide, 5})),
|
||||||
|
_ = wxStaticBoxSizer:add(ReturnSz, ReturnTx, zxw:flags({wide, 5})),
|
||||||
|
_ = wxStaticBoxSizer:add(ReturnSz, CopyB, zxw:flags({wide, 5})),
|
||||||
|
{ReturnSz, Return, Copy}.
|
||||||
|
|
||||||
|
|
||||||
|
call_param_sizer(Frame, J) ->
|
||||||
|
case hz:top_height() of
|
||||||
|
{ok, Height} -> call_param_sizer(Frame, J, Height);
|
||||||
|
Error -> handle_troubling(State, Error)
|
||||||
|
end.
|
||||||
|
|
||||||
|
call_param_sizer(Frame, J, Height) ->
|
||||||
|
DefTTL = Height + 10000,
|
||||||
|
DefGasP = hz:min_gas_price(),
|
||||||
|
DefGas = 5000000,
|
||||||
|
DefAmount = 0,
|
||||||
|
ParamSz = wxStaticBoxSizer:new(?wxVERTICAL, Frame, [{label, J("TX Parameters")}]),
|
||||||
|
ParamBox = wxStaticBoxSizer:getStaticBox(ParamSz),
|
||||||
|
GridSz = wxFlexGridSizer:new(2, 4, 4),
|
||||||
|
ok = wxFlexGridSizer:setFlexibleDirection(GridSz, ?wxHORIZONTAL),
|
||||||
|
ok = wxFlexGridSizer:addGrowableCol(GridSz, 1),
|
||||||
|
Amount_L = wxStaticText:new(ParamBox, ?wxID_ANY, J("Amount")),
|
||||||
|
Amount_T = wxTextCtrl:new(ParamBox, ?wxID_ANY),
|
||||||
|
ok = wxTextCtrl:setValue(Amount_T, integer_to_list(DefAmount)),
|
||||||
|
Gas_L = wxStaticText:new(ParamBox, ?wxID_ANY, J("Gas")),
|
||||||
|
Gas_T = wxTextCtrl:new(ParamBox, ?wxID_ANY),
|
||||||
|
ok = wxTextCtrl:setValue(Gas_T, integer_to_list(DefGas)),
|
||||||
|
GasP_L = wxStaticText:new(ParamBox, ?wxID_ANY, J("Gas Price")),
|
||||||
|
GasP_T = wxTextCtrl:new(ParamBox, ?wxID_ANY),
|
||||||
|
ok = wxTextCtrl:setValue(GasP_T, integer_to_list(DefGasP)),
|
||||||
|
TTL_L = wxStaticText:new(ParamBox, ?wxID_ANY, "TTL"),
|
||||||
|
TTL_T = wxTextCtrl:new(ParamBox, ?wxID_ANY),
|
||||||
|
ok = wxTextCtrl:setValue(TTL_T, integer_to_list(DefTTL)),
|
||||||
|
_ = wxFlexGridSizer:add(GridSz, Amount_L, zxw:flags({base, 5})),
|
||||||
|
_ = wxFlexGridSizer:add(GridSz, Amount_T, zxw:flags({wide, 5})),
|
||||||
|
_ = wxFlexGridSizer:add(GridSz, Gas_L, zxw:flags({base, 5})),
|
||||||
|
_ = wxFlexGridSizer:add(GridSz, Gas_T, zxw:flags({wide, 5})),
|
||||||
|
_ = wxFlexGridSizer:add(GridSz, GasP_L, zxw:flags({base, 5})),
|
||||||
|
_ = wxFlexGridSizer:add(GridSz, GasP_T, zxw:flags({wide, 5})),
|
||||||
|
_ = wxFlexGridSizer:add(GridSz, TTL_L, zxw:flags({base, 5})),
|
||||||
|
_ = wxFlexGridSizer:add(GridSz, TTL_T, zxw:flags({wide, 5})),
|
||||||
|
_ = wxSizer:add(ParamSz, GridSz, zxw:flags(wide)),
|
||||||
|
Params =
|
||||||
|
[{J("TX Amount"), fun gte_0/1, Amount_T} ,
|
||||||
|
{J("Gas") , fun gt_0/1, Gas_T},
|
||||||
|
{J("Gas Price"), fun gt_0/1, GasP_T},
|
||||||
|
{ "TTL", fun gte_0/1, TTL_T}],
|
||||||
|
{ParamSz, Params}.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%%% Spine
|
||||||
|
|
||||||
|
handle_call(tx_hash, _, State) ->
|
||||||
|
TXHash = do_tx_hash(State),
|
||||||
|
{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}.
|
||||||
|
|
||||||
|
|
||||||
|
handle_cast(Unexpected, State) ->
|
||||||
|
ok = log(warning, "Unexpected cast: ~tp~n", [Unexpected]),
|
||||||
|
{noreply, State}.
|
||||||
|
|
||||||
|
|
||||||
|
handle_info(retire, State) ->
|
||||||
|
ok = retire(State),
|
||||||
|
{noreply, State};
|
||||||
|
handle_info(Unexpected, State) ->
|
||||||
|
ok = log(warning, "Unexpected info: ~tp~n", [Unexpected]),
|
||||||
|
{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 = check_tx(State),
|
||||||
|
{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(#wx{event = #wxClose{}}, State) ->
|
||||||
|
ok = retire(State),
|
||||||
|
{noreply, State};
|
||||||
|
handle_event(Event, State) ->
|
||||||
|
ok = tell(info, "Unexpected event ~tp State: ~tp~n", [Event, State]),
|
||||||
|
{noreply, State}.
|
||||||
|
|
||||||
|
|
||||||
|
code_change(_, State, _) ->
|
||||||
|
{ok, State}.
|
||||||
|
|
||||||
|
|
||||||
|
retire(#s{frame = Frame}) ->
|
||||||
|
wxWindow:destroy(Frame).
|
||||||
|
|
||||||
|
|
||||||
|
terminate(wx_deleted, _) ->
|
||||||
|
wx:destroy();
|
||||||
|
terminate(Reason, State) ->
|
||||||
|
ok = log(info, "Reason: ~tp, State: ~tp", [Reason, State]),
|
||||||
|
wx:destroy().
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%%% Handlers
|
||||||
|
|
||||||
|
handle_troubling(State = #s{frame = Frame}, Info) ->
|
||||||
|
ok = wxFrame:raise(Frame),
|
||||||
|
ok = zxw:show_message(Frame, Info),
|
||||||
|
State.
|
||||||
|
|
||||||
|
|
||||||
|
do_tx_hash(#s{tx_data = #{"tx_hash" := TXHash}}) ->
|
||||||
|
TXHash;
|
||||||
|
do_tx_hash(#s{tx_data = none}) ->
|
||||||
|
none.
|
||||||
|
|
||||||
|
|
||||||
|
prep_call(State) ->
|
||||||
|
case gd_con:chain_id() of
|
||||||
|
{ok, ChainID} -> prep_call2(State, ChainID);
|
||||||
|
Error -> handle_troubling(State, Error)
|
||||||
|
end.
|
||||||
|
|
||||||
|
prep_call2(State, ChainID) ->
|
||||||
|
case params(State) of
|
||||||
|
{ok, Params} -> prep_call3(State, ChainID, Params);
|
||||||
|
Error -> handle_troubling(State, Error)
|
||||||
|
end.
|
||||||
|
|
||||||
|
prep_call3(State, ChainID, Params) ->
|
||||||
|
case args(State) of
|
||||||
|
{ok, Args} -> prep_call4(State, ChainID, Params, {sophia, Args});
|
||||||
|
Error -> handle_troubling(State, Error)
|
||||||
|
end.
|
||||||
|
|
||||||
|
prep_call4(State = #s{fundef = {"init", init}, build = Build}, ChainID, Params, Args) ->
|
||||||
|
{CallerID, Nonce, Gas, GP, Amount, TTL} = Params,
|
||||||
|
case hz:contract_create_built(CallerID, Nonce, Gas, GP, Amount, TTL, Build, Args) of
|
||||||
|
{ok, CreateTX} -> deploy(State, ChainID, CallerID, CreateTX);
|
||||||
|
Error -> handle_troubling(State, Error)
|
||||||
|
end;
|
||||||
|
prep_call4(State = #s{fundef = {Name, Ilk}, con_id = ConID, build = Build}, ChainID, Params, Args) ->
|
||||||
|
{CallerID, Nonce, Gas, GP, Amount, TTL} = Params,
|
||||||
|
AACI = maps:get(aaci, Build),
|
||||||
|
case hz:contract_call(CallerID, Nonce, Gas, GP, Amount, TTL, AACI, ConID, Name, Args) of
|
||||||
|
{ok, UnsignedTX} ->
|
||||||
|
case Ilk of
|
||||||
|
call -> do_call(State, ChainID, CallerID, UnsignedTX);
|
||||||
|
dryr -> do_dry_run(State, ConID, UnsignedTX)
|
||||||
|
end;
|
||||||
|
Error ->
|
||||||
|
handle_troubling(State, Error)
|
||||||
|
end.
|
||||||
|
|
||||||
|
params(State = #s{kp = #w{wx = KeyPicker}}) ->
|
||||||
|
ID = wxChoice:getString(KeyPicker, wxChoice:getSelection(KeyPicker)),
|
||||||
|
PK = unicode:characters_to_binary(ID),
|
||||||
|
case hz:next_nonce(PK) of
|
||||||
|
{ok, Nonce} -> params2(State, PK, Nonce);
|
||||||
|
Error -> handle_troubling(State, Error)
|
||||||
|
end.
|
||||||
|
|
||||||
|
params2(#s{params = Params}, PK, Nonce) ->
|
||||||
|
case lists:foldl(fun extract/2, {ok, []}, Params) of
|
||||||
|
{ok, [TTL, GP, Gas, Amount]} -> {ok, {PK, Nonce, Gas, GP, Amount, TTL}};
|
||||||
|
Error -> Error
|
||||||
|
end.
|
||||||
|
|
||||||
|
extract({Name, Check, Widget}, {Status, Out}) ->
|
||||||
|
case Check(wxTextCtrl:getValue(Widget)) of
|
||||||
|
{ok, Value} -> {Status, [Value | Out]};
|
||||||
|
Error -> {error, [{Name, Error}, Out]}
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
% TODO: Put some basic checking in here, like for blank strings, at least.
|
||||||
|
% It should be possible to perform type/parse checks over this since we have
|
||||||
|
% access to the AACI. But not today.
|
||||||
|
args(#s{args = ArgFields}) ->
|
||||||
|
Values = [wxTextCtrl:getValue(W) || #w{wx = W} <- ArgFields],
|
||||||
|
{ok, Values}.
|
||||||
|
|
||||||
|
|
||||||
|
deploy(State, ChainID, CallerID, CreateTX) ->
|
||||||
|
case gd_con:sign_call(ChainID, CallerID, CreateTX) of
|
||||||
|
{ok, SignedTX} -> deploy2(State, SignedTX);
|
||||||
|
Error -> handle_troubling(State, Error)
|
||||||
|
end.
|
||||||
|
|
||||||
|
deploy2(State = #s{j = J, hash = #w{wx = HashT}, action = #w{wx = ActionB}}, SignedTX) ->
|
||||||
|
case hz:post_tx(SignedTX) of
|
||||||
|
{ok, Data = #{"tx_hash" := TXHash}} ->
|
||||||
|
_ = wxButton:disable(ActionB),
|
||||||
|
ok = wxButton:setLabel(ActionB, J("Check Transaction Status")),
|
||||||
|
ok = log(info, "Submitted transaction ~s", [TXHash]),
|
||||||
|
ok = wxTextCtrl:setValue(HashT, unicode:characters_to_list(TXHash)),
|
||||||
|
check_tx(State#s{tx_data = Data, status = submitted});
|
||||||
|
{ok, #{"reason" := Reason}} ->
|
||||||
|
handle_troubling(State, {error, Reason});
|
||||||
|
Error ->
|
||||||
|
handle_troubling(State, Error)
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
do_call(State, ChainID, CallerID, UnsignedTX) ->
|
||||||
|
case gd_con:sign_call(ChainID, CallerID, UnsignedTX) of
|
||||||
|
{ok, SignedTX} -> do_call2(State, SignedTX);
|
||||||
|
Error -> handle_troubling(State, Error)
|
||||||
|
end.
|
||||||
|
|
||||||
|
do_call2(State = #s{action = #w{wx = ActionB}}, SignedTX) ->
|
||||||
|
_ = wxButton:disable(ActionB),
|
||||||
|
case hz:post_tx(SignedTX) of
|
||||||
|
{ok, #{"reason" := Reason}} -> handle_troubling(State#s{status = rejected}, Reason);
|
||||||
|
{ok, Data} -> check_tx(State#s{tx_data = Data, status = submitted});
|
||||||
|
Error -> handle_troubling(State, Error)
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
do_dry_run(State = #s{action = #w{wx = ActionB}}, ConID, TX) ->
|
||||||
|
_ = wxButton:disable(ActionB),
|
||||||
|
case hz:dry_run(TX) of
|
||||||
|
{ok, Result} -> dry_run2(State#s{tx_info = Result});
|
||||||
|
Other -> handle_troubling(State, {error, ConID, Other})
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
dry_run2(State = #s{funret = ReturnType,
|
||||||
|
return = #w{wx = ReturnT},
|
||||||
|
copy = #w{wx = CopyB},
|
||||||
|
tx_data = TXData,
|
||||||
|
tx_info = TXInfo,
|
||||||
|
hash = #w{wx = HashT},
|
||||||
|
info = #w{wx = InfoT}}) ->
|
||||||
|
ReturnV =
|
||||||
|
case TXInfo of
|
||||||
|
#{"results" :=
|
||||||
|
[#{"call_obj" :=
|
||||||
|
#{"return_type" := "revert",
|
||||||
|
"return_value" := ReturnCB},
|
||||||
|
"result" := "ok","type" := "contract_call"}]} ->
|
||||||
|
io_lib:format("Revert: ~ts", [hz:decode_bytearray(ReturnCB, sophia)]);
|
||||||
|
#{"results" :=
|
||||||
|
[#{"call_obj" :=
|
||||||
|
#{"return_type" := "ok",
|
||||||
|
"return_value" := ReturnCB},
|
||||||
|
"result" := "ok","type" := "contract_call"}]} ->
|
||||||
|
hz:decode_bytearray(ReturnCB, {sophia, ReturnType});
|
||||||
|
Other ->
|
||||||
|
io_lib:format("???: ~tp", [Other])
|
||||||
|
end,
|
||||||
|
_ = wxButton:enable(CopyB),
|
||||||
|
FormattedHash = io_lib:format("~tp", [TXData]),
|
||||||
|
FormattedInfo = io_lib:format("~tp", [TXInfo]),
|
||||||
|
ok = wxTextCtrl:setValue(ReturnT, ReturnV),
|
||||||
|
ok = wxTextCtrl:setValue(HashT, FormattedHash),
|
||||||
|
ok = wxTextCtrl:setValue(InfoT, FormattedInfo),
|
||||||
|
State.
|
||||||
|
|
||||||
|
|
||||||
|
check_tx(State = #s{j = J,
|
||||||
|
fundef = {_, init},
|
||||||
|
tx_data = #{"tx_hash" := TXHash},
|
||||||
|
tx_info = none,
|
||||||
|
status = submitted,
|
||||||
|
action = #w{wx = ActionB},
|
||||||
|
info = #w{wx = InfoT}}) ->
|
||||||
|
case hz:tx_info(TXHash) of
|
||||||
|
{ok, Info = #{"call_info" := #{"return_type" := "ok", "contract_id" := ConID}}} ->
|
||||||
|
ok = tell(info, "Contract deployed: ~p", [Info]),
|
||||||
|
_ = wxButton:disable(ActionB),
|
||||||
|
ok = gd_con:open_contract(ConID),
|
||||||
|
self() ! retire,
|
||||||
|
State;
|
||||||
|
{error, "Tx not mined"} ->
|
||||||
|
ok = wxTextCtrl:setValue(InfoT, J("[Transaction not yet mined.]")),
|
||||||
|
ok = wxButton:setLabel(ActionB, J("Check Deployment Status")),
|
||||||
|
_ = wxButton:enable(ActionB),
|
||||||
|
State;
|
||||||
|
Other ->
|
||||||
|
FormattedJunk = io_lib:format("~tp", [Other]),
|
||||||
|
ok = wxTextCtrl:setValue(InfoT, FormattedJunk),
|
||||||
|
ok = wxButton:setLabel(ActionB, J("Check Depoyment Status")),
|
||||||
|
_ = wxButton:enable(ActionB),
|
||||||
|
State
|
||||||
|
end;
|
||||||
|
check_tx(State = #s{j = J,
|
||||||
|
funret = ReturnType,
|
||||||
|
tx_data = #{"tx_hash" := TXHash},
|
||||||
|
tx_info = none,
|
||||||
|
status = submitted,
|
||||||
|
return = #w{wx = ReturnT},
|
||||||
|
copy = #w{wx = CopyB},
|
||||||
|
action = #w{wx = ActionB},
|
||||||
|
info = #w{wx = InfoT}}) ->
|
||||||
|
case hz:tx_info(TXHash) of
|
||||||
|
{ok, Info = #{"call_info" := #{"return_type" := "ok",
|
||||||
|
"return_value" := ReturnCB}}} ->
|
||||||
|
FormattedInfo = io_lib:format("~tp", [Info]),
|
||||||
|
_ = wxButton:enable(CopyB),
|
||||||
|
_ = wxButton:disable(ActionB),
|
||||||
|
ReturnV = hz:decode_bytearray(ReturnCB, {sophia, ReturnType}),
|
||||||
|
ok = wxTextCtrl:setValue(ReturnT, ReturnV),
|
||||||
|
ok = wxTextCtrl:setValue(InfoT, FormattedInfo),
|
||||||
|
State#s{status = included, tx_info = Info};
|
||||||
|
{ok, Reason = #{"call_info" := #{"return_type" := "revert", "return_value" := ReturnCB}}} ->
|
||||||
|
_ = wxButton:enable(CopyB),
|
||||||
|
_ = wxButton:disable(ActionB),
|
||||||
|
ReturnV = io_lib:format("Revert: ~ts", [hz:decode_bytearray(ReturnCB, sophia)]),
|
||||||
|
ok = wxTextCtrl:setValue(ReturnT, ReturnV),
|
||||||
|
FormattedInfo = io_lib:format("~tp", [Reason]),
|
||||||
|
ok = wxTextCtrl:setValue(InfoT, FormattedInfo),
|
||||||
|
State#s{status = rejected, tx_info = Reason};
|
||||||
|
{error, "Tx not mined"} ->
|
||||||
|
ok = wxTextCtrl:setValue(InfoT, J("[Transaction not yet mined.]")),
|
||||||
|
ok = wxButton:setLabel(ActionB, J("Check Transaction Status")),
|
||||||
|
_ = wxButton:enable(ActionB),
|
||||||
|
State;
|
||||||
|
Error ->
|
||||||
|
handle_troubling(State, Error)
|
||||||
|
end;
|
||||||
|
check_tx(State = #s{tx_data = TXData,
|
||||||
|
action = #w{wx = ActionB}}) ->
|
||||||
|
_ = wxButton:disable(ActionB),
|
||||||
|
tell(info, "TXData: ~p", [TXData]),
|
||||||
|
ok = tell("Nothing to check"),
|
||||||
|
State.
|
||||||
|
|
||||||
|
|
||||||
|
copy(#s{tx_info = none}) ->
|
||||||
|
ok;
|
||||||
|
copy(#s{return = #w{wx = ReturnT}}) ->
|
||||||
|
Output = wxTextCtrl:getValue(ReturnT),
|
||||||
|
gd_lib:copy_to_clipboard(Output).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
textify({integer, _, _}) -> "int";
|
||||||
|
textify({boolean, _, _}) -> "bool";
|
||||||
|
textify({{bytes, [I]}, _, _}) -> io_lib:format("bytes(~w)", [I]);
|
||||||
|
textify({{bytes, any}, _, _}) -> "bytes()";
|
||||||
|
textify({T, _, _}) when is_atom(T) -> atom_to_list(T);
|
||||||
|
textify({T, _, _}) when is_list(T) -> T;
|
||||||
|
textify({T, _, _}) -> io_lib:format("~tp", [T]).
|
||||||
|
|
||||||
|
|
||||||
|
gt_0(S) ->
|
||||||
|
C = "Must be an integer greater than 0",
|
||||||
|
R =
|
||||||
|
try
|
||||||
|
{ok, list_to_integer(S)}
|
||||||
|
catch
|
||||||
|
error:badarg -> {error, {S, C}}
|
||||||
|
end,
|
||||||
|
case R of
|
||||||
|
{ok, N} when N > 0 -> {ok, N};
|
||||||
|
{ok, N} when N =< 0 -> {error, {S, C}};
|
||||||
|
Error -> Error
|
||||||
|
end.
|
||||||
|
|
||||||
|
gte_0(S) ->
|
||||||
|
C = "Must be a non-negative integer.",
|
||||||
|
R =
|
||||||
|
try
|
||||||
|
{ok, list_to_integer(S)}
|
||||||
|
catch
|
||||||
|
error:badarg -> {error, {S, C}}
|
||||||
|
end,
|
||||||
|
case R of
|
||||||
|
{ok, N} when N >= 0 -> {ok, N};
|
||||||
|
{ok, N} when N < 0 -> {error, {S, C}};
|
||||||
|
Error -> Error
|
||||||
|
end.
|
||||||
+139
-577
@@ -1,5 +1,5 @@
|
|||||||
-module(gd_v_devman).
|
-module(gd_v_devman).
|
||||||
-vsn("0.7.0").
|
-vsn("0.9.0").
|
||||||
-author("Craig Everett <craigeverett@qpq.swiss>").
|
-author("Craig Everett <craigeverett@qpq.swiss>").
|
||||||
-copyright("QPQ AG <info@qpq.swiss>").
|
-copyright("QPQ AG <info@qpq.swiss>").
|
||||||
-license("GPL-3.0-or-later").
|
-license("GPL-3.0-or-later").
|
||||||
@@ -8,27 +8,21 @@
|
|||||||
%-behavior(gd_v).
|
%-behavior(gd_v).
|
||||||
-include_lib("wx/include/wx.hrl").
|
-include_lib("wx/include/wx.hrl").
|
||||||
-export([to_front/1]).
|
-export([to_front/1]).
|
||||||
-export([set_manifest/1, open_contract/1, call_result/2, dryrun_result/2, trouble/1]).
|
-export([set_manifest/1, open_contract/1, write_console/2, call_result/2, dryrun_result/2, trouble/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]).
|
||||||
-include("$zx_include/zx_logger.hrl").
|
-include("$zx_include/zx_logger.hrl").
|
||||||
-include("gd.hrl").
|
-include("gd.hrl").
|
||||||
|
-include("gdl.hrl").
|
||||||
|
|
||||||
-define(editorMode, sophia).
|
|
||||||
|
|
||||||
% Widgets
|
|
||||||
-record(w,
|
|
||||||
{name = none :: atom() | {FunName :: binary(), call | dryr},
|
|
||||||
id = 0 :: integer(),
|
|
||||||
wx = none :: none | wx:wx_object()}).
|
|
||||||
|
|
||||||
% Contract functions in an ACI
|
% Contract functions in an ACI
|
||||||
-record(f,
|
-record(f,
|
||||||
{name = <<"">> :: binary(),
|
{name = <<"">> :: binary(),
|
||||||
call = #w{} :: #w{},
|
call = #w{} :: #w{},
|
||||||
dryrun = #w{} :: none | #w{},
|
dryrun = #w{} :: none | #w{},
|
||||||
args = [] :: [{wx:wx_object(), wx:wx_object(), argt()}]}).
|
args = [] :: [argt()]}).
|
||||||
|
|
||||||
% Code book pages
|
% Code book pages
|
||||||
-record(p,
|
-record(p,
|
||||||
@@ -57,7 +51,9 @@
|
|||||||
code = {none, []} :: {Codebook :: none | wx:wx_object(), Pages :: [#p{}]},
|
code = {none, []} :: {Codebook :: none | wx:wx_object(), Pages :: [#p{}]},
|
||||||
cons = {none, []} :: {Consbook :: none | wx:wx_object(), Pages :: [#c{}]}}).
|
cons = {none, []} :: {Consbook :: none | wx:wx_object(), Pages :: [#c{}]}}).
|
||||||
|
|
||||||
-type argt() :: int | string | address | list(argt()).
|
% TODO: Spec HZ AACIs.
|
||||||
|
-type argt() :: term(). % FIXME: Whatever HZ returns in the AACI as an arg type.
|
||||||
|
|
||||||
|
|
||||||
%%% Interface
|
%%% Interface
|
||||||
|
|
||||||
@@ -80,10 +76,20 @@ set_manifest(Entries) ->
|
|||||||
|
|
||||||
|
|
||||||
-spec open_contract(Address) -> ok
|
-spec open_contract(Address) -> ok
|
||||||
when Address :: string().
|
when Address :: binary() | string().
|
||||||
|
|
||||||
open_contract(Address) ->
|
open_contract(Address) when is_binary(Address) ->
|
||||||
wx_object:cast(?MODULE, {open_contract, Address}).
|
wx_object:cast(?MODULE, {open_contract, Address});
|
||||||
|
open_contract(Address) when is_list(Address) ->
|
||||||
|
open_contract(list_to_binary(Address)).
|
||||||
|
|
||||||
|
|
||||||
|
-spec write_console(ConID, Message) -> ok
|
||||||
|
when ConID :: gajudesk:id(),
|
||||||
|
Message :: unicode:chardata().
|
||||||
|
|
||||||
|
write_console(ConID, Message) ->
|
||||||
|
wx_object:cast(?MODULE, {write_console, ConID, Message}).
|
||||||
|
|
||||||
|
|
||||||
-spec call_result(ConID, CallInfo) -> ok
|
-spec call_result(ConID, CallInfo) -> ok
|
||||||
@@ -118,7 +124,7 @@ start_link(Args) ->
|
|||||||
|
|
||||||
|
|
||||||
init({Prefs, Manifest}) ->
|
init({Prefs, Manifest}) ->
|
||||||
Lang = maps:get(lang, Prefs, en_us),
|
Lang = maps:get(lang, Prefs, en),
|
||||||
Trans = gd_jt:read_translations(?MODULE),
|
Trans = gd_jt:read_translations(?MODULE),
|
||||||
J = gd_jt:j(Lang, Trans),
|
J = gd_jt:j(Lang, Trans),
|
||||||
Wx = wx:new(),
|
Wx = wx:new(),
|
||||||
@@ -219,6 +225,9 @@ handle_cast(to_front, State = #s{frame = Frame}) ->
|
|||||||
handle_cast({open_contract, Address}, State) ->
|
handle_cast({open_contract, Address}, State) ->
|
||||||
NewState = load2(State, Address),
|
NewState = load2(State, Address),
|
||||||
{noreply, NewState};
|
{noreply, NewState};
|
||||||
|
handle_cast({write_console, ConID, Message}, State) ->
|
||||||
|
ok = do_write_console(State, ConID, Message),
|
||||||
|
{noreply, State};
|
||||||
handle_cast({call_result, ConID, CallInfo}, State) ->
|
handle_cast({call_result, ConID, CallInfo}, State) ->
|
||||||
ok = do_call_result(State, ConID, CallInfo),
|
ok = do_call_result(State, ConID, CallInfo),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
@@ -226,8 +235,8 @@ handle_cast({dryrun_result, ConID, CallInfo}, State) ->
|
|||||||
ok = do_dryrun_result(State, ConID, CallInfo),
|
ok = do_dryrun_result(State, ConID, CallInfo),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
handle_cast({trouble, Info}, State) ->
|
handle_cast({trouble, Info}, State) ->
|
||||||
ok = handle_troubling(State, Info),
|
NewState = handle_troubling(State, Info),
|
||||||
{noreply, State};
|
{noreply, NewState};
|
||||||
handle_cast(Unexpected, State) ->
|
handle_cast(Unexpected, State) ->
|
||||||
ok = log(warning, "Unexpected cast: ~tp~n", [Unexpected]),
|
ok = log(warning, "Unexpected cast: ~tp~n", [Unexpected]),
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
@@ -280,14 +289,17 @@ handle_event(Event, State) ->
|
|||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
|
|
||||||
handle_troubling(#s{frame = Frame}, Info) ->
|
handle_troubling(State = #s{frame = Frame}, Info) ->
|
||||||
zxw:show_message(Frame, Info).
|
ok = zxw:show_message(Frame, Info),
|
||||||
|
State.
|
||||||
|
|
||||||
|
|
||||||
code_change(_, State, _) ->
|
code_change(_, State, _) ->
|
||||||
{ok, State}.
|
{ok, State}.
|
||||||
|
|
||||||
|
|
||||||
|
terminate(wx_deleted, _) ->
|
||||||
|
wx:destroy();
|
||||||
terminate(Reason, State) ->
|
terminate(Reason, State) ->
|
||||||
ok = log(info, "Reason: ~tp, State: ~tp", [Reason, State]),
|
ok = log(info, "Reason: ~tp, State: ~tp", [Reason, State]),
|
||||||
wx:destroy().
|
wx:destroy().
|
||||||
@@ -304,176 +316,40 @@ style(#s{code = {_, Pages}}, Win, Event) ->
|
|||||||
tell("Received bogus style event.~nWin: ~p~nEvent: ~p", [Win, Event])
|
tell("Received bogus style event.~nWin: ~p~nEvent: ~p", [Win, Event])
|
||||||
end.
|
end.
|
||||||
|
|
||||||
clicked(State = #s{cons = {Consbook, Contracts}}, Name) ->
|
|
||||||
|
clicked(State = #s{cons = {Consbook, Contracts}}, FunDef) ->
|
||||||
|
ok =
|
||||||
case wxNotebook:getSelection(Consbook) of
|
case wxNotebook:getSelection(Consbook) of
|
||||||
?wxNOT_FOUND ->
|
?wxNOT_FOUND ->
|
||||||
ok = tell(warning, "Inconcievable! No notebook page is selected!"),
|
tell(warning, "Inconcievable! No deployed contract page is selected!");
|
||||||
State;
|
|
||||||
Index ->
|
Index ->
|
||||||
Contract = lists:nth(Index + 1, Contracts),
|
#c{id = ConID, build = Build} = lists:nth(Index + 1, Contracts),
|
||||||
clicked2(State, Contract, Name)
|
gd_con:prompt_call(FunDef, ConID, Build)
|
||||||
end.
|
|
||||||
|
|
||||||
clicked2(State, Contract, Name) ->
|
|
||||||
case gd_con:list_keys() of
|
|
||||||
{ok, 0, []} ->
|
|
||||||
handle_troubling(State, "No keys exist in the current wallet.");
|
|
||||||
{ok, Selected, Keys} ->
|
|
||||||
clicked3(State, Contract, Name, Selected, Keys);
|
|
||||||
error ->
|
|
||||||
handle_troubling(State, "No wallet is selected!")
|
|
||||||
end.
|
|
||||||
|
|
||||||
clicked3(State = #s{frame = Frame, j = J}, Contract, Name, Selected, Keys) ->
|
|
||||||
Label =
|
|
||||||
case element(2, Name) of
|
|
||||||
call -> "Contract Call";
|
|
||||||
dryr -> "Dry Run"
|
|
||||||
end,
|
end,
|
||||||
Dialog = wxDialog:new(Frame, ?wxID_ANY, J(Label)),
|
|
||||||
Sizer = wxBoxSizer:new(?wxVERTICAL),
|
|
||||||
KeySz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("Signature Key")}]),
|
|
||||||
KeyPicker = wxChoice:new(Dialog, ?wxID_ANY, [{choices, Keys}]),
|
|
||||||
_ = wxStaticBoxSizer:add(KeySz, KeyPicker, zxw:flags(wide)),
|
|
||||||
ok = wxChoice:setSelection(KeyPicker, Selected - 1),
|
|
||||||
{ParamSz, TTL_Tx, GasP_Tx, Gas_Tx, Amount_Tx} = call_param_sizer(Dialog, J),
|
|
||||||
ButtSz = wxBoxSizer:new(?wxHORIZONTAL),
|
|
||||||
Affirm = wxButton:new(Dialog, ?wxID_OK),
|
|
||||||
Cancel = wxButton:new(Dialog, ?wxID_CANCEL),
|
|
||||||
_ = wxBoxSizer:add(ButtSz, Affirm, zxw:flags(wide)),
|
|
||||||
_ = wxBoxSizer:add(ButtSz, Cancel, zxw:flags(wide)),
|
|
||||||
_ = wxSizer:add(Sizer, KeySz, zxw:flags(wide)),
|
|
||||||
_ = wxSizer:add(Sizer, ParamSz, zxw:flags(wide)),
|
|
||||||
_ = wxSizer:add(Sizer, ButtSz, zxw:flags(wide)),
|
|
||||||
ok = wxDialog:setSizer(Dialog, Sizer),
|
|
||||||
ok = wxBoxSizer:layout(Sizer),
|
|
||||||
ok = wxDialog:setSize(Dialog, {500, 300}),
|
|
||||||
ok = wxDialog:center(Dialog),
|
|
||||||
Outcome =
|
|
||||||
case wxDialog:showModal(Dialog) of
|
|
||||||
?wxID_OK ->
|
|
||||||
ID = wxChoice:getString(KeyPicker, wxChoice:getSelection(KeyPicker)),
|
|
||||||
PK = unicode:characters_to_binary(ID),
|
|
||||||
Controls =
|
|
||||||
[{"TTL", TTL_Tx},
|
|
||||||
{"Gas Price", GasP_Tx},
|
|
||||||
{"Gas", Gas_Tx},
|
|
||||||
{"Amount", Amount_Tx}],
|
|
||||||
case call_params(Controls) of
|
|
||||||
{ok, [TTL, GasP, Gas, Amount]} ->
|
|
||||||
{ok, Nonce} = hz:next_nonce(PK),
|
|
||||||
{ok, {PK, Nonce, TTL, GasP, Gas, Amount}};
|
|
||||||
E ->
|
|
||||||
E
|
|
||||||
end;
|
|
||||||
?wxID_CANCEL ->
|
|
||||||
cancel
|
|
||||||
end,
|
|
||||||
ok = wxDialog:destroy(Dialog),
|
|
||||||
case Outcome of
|
|
||||||
{ok, Params} -> clicked4(State, Contract, Name, Params);
|
|
||||||
cancel -> State;
|
|
||||||
Error -> handle_troubling(State, Error)
|
|
||||||
end.
|
|
||||||
|
|
||||||
call_param_sizer(Dialog, J) ->
|
|
||||||
{ok, Height} = hz:top_height(),
|
|
||||||
DefTTL = Height + 10000,
|
|
||||||
DefGasP = hz:min_gas_price(),
|
|
||||||
DefGas = 5000000,
|
|
||||||
DefAmount = 0,
|
|
||||||
ParamSz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("TX Parameters")}]),
|
|
||||||
GridSz = wxFlexGridSizer:new(2, 4, 4),
|
|
||||||
ok = wxFlexGridSizer:setFlexibleDirection(GridSz, ?wxHORIZONTAL),
|
|
||||||
ok = wxFlexGridSizer:addGrowableCol(GridSz, 1),
|
|
||||||
TTL_L = wxStaticText:new(Dialog, ?wxID_ANY, "TTL"),
|
|
||||||
TTL_Tx = wxTextCtrl:new(Dialog, ?wxID_ANY),
|
|
||||||
ok = wxTextCtrl:setValue(TTL_Tx, integer_to_list(DefTTL)),
|
|
||||||
GasP_L = wxStaticText:new(Dialog, ?wxID_ANY, J("Gas Price")),
|
|
||||||
GasP_Tx = wxTextCtrl:new(Dialog, ?wxID_ANY),
|
|
||||||
ok = wxTextCtrl:setValue(GasP_Tx, integer_to_list(DefGasP)),
|
|
||||||
Gas_L = wxStaticText:new(Dialog, ?wxID_ANY, J("Gas")),
|
|
||||||
Gas_Tx = wxTextCtrl:new(Dialog, ?wxID_ANY),
|
|
||||||
ok = wxTextCtrl:setValue(Gas_Tx, integer_to_list(DefGas)),
|
|
||||||
Amount_L = wxStaticText:new(Dialog, ?wxID_ANY, J("TX Amount")),
|
|
||||||
Amount_Tx = wxTextCtrl:new(Dialog, ?wxID_ANY),
|
|
||||||
ok = wxTextCtrl:setValue(Amount_Tx, integer_to_list(DefAmount)),
|
|
||||||
_ = wxFlexGridSizer:add(GridSz, TTL_L, zxw:flags(base)),
|
|
||||||
_ = wxFlexGridSizer:add(GridSz, TTL_Tx, zxw:flags(wide)),
|
|
||||||
_ = wxFlexGridSizer:add(GridSz, GasP_L, zxw:flags(base)),
|
|
||||||
_ = wxFlexGridSizer:add(GridSz, GasP_Tx, zxw:flags(wide)),
|
|
||||||
_ = wxFlexGridSizer:add(GridSz, Gas_L, zxw:flags(base)),
|
|
||||||
_ = wxFlexGridSizer:add(GridSz, Gas_Tx, zxw:flags(wide)),
|
|
||||||
_ = wxFlexGridSizer:add(GridSz, Amount_L, zxw:flags(base)),
|
|
||||||
_ = wxFlexGridSizer:add(GridSz, Amount_Tx, zxw:flags(wide)),
|
|
||||||
_ = wxSizer:add(ParamSz, GridSz, zxw:flags(wide)),
|
|
||||||
{ParamSz, TTL_Tx, GasP_Tx, Gas_Tx, Amount_Tx}.
|
|
||||||
|
|
||||||
call_params(Controls) ->
|
|
||||||
call_params(Controls, []).
|
|
||||||
|
|
||||||
call_params([], A) ->
|
|
||||||
{ok, lists:reverse(A)};
|
|
||||||
call_params([{L, C} | T], A) ->
|
|
||||||
O =
|
|
||||||
try
|
|
||||||
{ok, list_to_integer(wxTextCtrl:getValue(C))}
|
|
||||||
catch
|
|
||||||
error:badarg -> {error, {L, not_an_integer}}
|
|
||||||
end,
|
|
||||||
case O of
|
|
||||||
{ok, N} -> call_params(T, [N | A]);
|
|
||||||
Error -> Error
|
|
||||||
end.
|
|
||||||
|
|
||||||
clicked4(State,
|
|
||||||
#c{id = ConID, build = #{aaci := AACI}, funs = {_, Funs}},
|
|
||||||
{Name, Type},
|
|
||||||
{PK, Nonce, TTL, GasP, Gas, Amt}) ->
|
|
||||||
#f{args = ArgFields} = maps:get(Name, Funs),
|
|
||||||
Args = lists:map(fun get_arg/1, ArgFields),
|
|
||||||
case hz:contract_call(PK, Nonce, Gas, GasP, Amt, TTL, AACI, ConID, Name, Args) of
|
|
||||||
{ok, UnsignedTX} ->
|
|
||||||
case Type of
|
|
||||||
call -> do_call(State, ConID, PK, UnsignedTX);
|
|
||||||
dryr -> do_dry_run(State, ConID, UnsignedTX)
|
|
||||||
end;
|
|
||||||
Error ->
|
|
||||||
handle_troubling(State, Error),
|
|
||||||
State
|
|
||||||
end.
|
|
||||||
|
|
||||||
do_call(State, ConID, CallerID, UnsignedTX) ->
|
|
||||||
ok = gd_con:sign_call(ConID, CallerID, UnsignedTX),
|
|
||||||
State.
|
|
||||||
|
|
||||||
do_dry_run(State, ConID, TX) ->
|
|
||||||
ok = gd_con:dry_run(ConID, TX),
|
|
||||||
State.
|
State.
|
||||||
|
|
||||||
|
|
||||||
do_call_result(#s{tabs = TopBook, cons = {Consbook, Contracts}}, ConID, CallInfo) ->
|
do_write_console(#s{tabs = TopBook, cons = {Consbook, Contracts}}, ConID, Message) ->
|
||||||
case lookup_contract(ConID, Contracts) of
|
case lookup_contract(ConID, Contracts) of
|
||||||
{#c{cons = Console}, ZeroIndex} ->
|
{#c{cons = Console}, ZeroIndex} ->
|
||||||
_ = wxNotebook:changeSelection(TopBook, 1),
|
_ = wxNotebook:changeSelection(TopBook, 1),
|
||||||
_ = wxNotebook:changeSelection(Consbook, ZeroIndex),
|
_ = wxNotebook:changeSelection(Consbook, ZeroIndex),
|
||||||
Out = io_lib:format("Call Result:~n~p~n~n", [CallInfo]),
|
Out = [Message, "\n\n"],
|
||||||
wxTextCtrl:appendText(Console, Out);
|
wxTextCtrl:appendText(Console, Out);
|
||||||
error ->
|
error ->
|
||||||
tell(info, "Received result for ~p:~n~p ", [ConID, CallInfo])
|
tell(info, "Received result for ~p:~n~p ", [ConID, Message])
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
do_dryrun_result(#s{tabs = TopBook, cons = {Consbook, Contracts}}, ConID, CallInfo) ->
|
do_call_result(State, ConID, CallInfo) ->
|
||||||
case lookup_contract(ConID, Contracts) of
|
Message = io_lib:format("Call Result:~n~p", [CallInfo]),
|
||||||
{#c{cons = Console}, ZeroIndex} ->
|
do_write_console(State, ConID, Message).
|
||||||
_ = wxNotebook:changeSelection(TopBook, 1),
|
|
||||||
_ = wxNotebook:changeSelection(Consbook, ZeroIndex),
|
|
||||||
Out = io_lib:format("Call Result:~n~p~n~n", [CallInfo]),
|
do_dryrun_result(State, ConID, CallInfo) ->
|
||||||
wxTextCtrl:appendText(Console, Out);
|
Message = io_lib:format("Call Result:~n~p", [CallInfo]),
|
||||||
error ->
|
do_write_console(State, ConID, Message).
|
||||||
tell(info, "Received result for ~p:~n~p ", [ConID, CallInfo])
|
|
||||||
end.
|
|
||||||
|
|
||||||
lookup_contract(ConID, Contracts) ->
|
lookup_contract(ConID, Contracts) ->
|
||||||
lookup_contract(ConID, Contracts, 0).
|
lookup_contract(ConID, Contracts, 0).
|
||||||
@@ -503,20 +379,16 @@ add_code_page2(State = #s{j = J}, {file, File}) ->
|
|||||||
add_code_page(State, {file, File}, Code);
|
add_code_page(State, {file, File}, Code);
|
||||||
Error ->
|
Error ->
|
||||||
Message = io_lib:format(J("Opening ~p failed with: ~p"), [File, Error]),
|
Message = io_lib:format(J("Opening ~p failed with: ~p"), [File, Error]),
|
||||||
ok = handle_troubling(State, Message),
|
handle_troubling(State, Message)
|
||||||
State
|
|
||||||
end;
|
end;
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
Message = io_lib:format(J("Opening ~p failed with: ~p"), [File, Reason]),
|
Message = io_lib:format(J("Opening ~p failed with: ~p"), [File, Reason]),
|
||||||
ok = handle_troubling(State, Message),
|
handle_troubling(State, Message)
|
||||||
State
|
|
||||||
end;
|
end;
|
||||||
add_code_page2(State, {hash, Address}) ->
|
add_code_page2(State, {hash, Address}) ->
|
||||||
open_hash2(State, Address).
|
open_hash2(State, Address).
|
||||||
|
|
||||||
add_code_page(State = #s{tabs = TopBook, code = {Codebook, Pages}}, Location, Code) ->
|
add_code_page(State = #s{tabs = TopBook, code = {Codebook, Pages}}, Location, Code) ->
|
||||||
Color = wxSystemSettings:getColour(?wxSYS_COLOUR_WINDOW),
|
|
||||||
tell("Color: ~p", [Color]),
|
|
||||||
Window = wxWindow:new(Codebook, ?wxID_ANY),
|
Window = wxWindow:new(Codebook, ?wxID_ANY),
|
||||||
PageSz = wxBoxSizer:new(?wxHORIZONTAL),
|
PageSz = wxBoxSizer:new(?wxHORIZONTAL),
|
||||||
|
|
||||||
@@ -589,99 +461,16 @@ deploy(State = #s{code = {Codebook, Pages}}) ->
|
|||||||
State;
|
State;
|
||||||
Index ->
|
Index ->
|
||||||
#p{code = CodeTx} = lists:nth(Index + 1, Pages),
|
#p{code = CodeTx} = lists:nth(Index + 1, Pages),
|
||||||
Source = get_source(CodeTx),
|
Source = gd_sophia_editor:get_text(CodeTx),
|
||||||
deploy2(State, Source)
|
deploy2(State, Source)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
deploy2(State, Source) ->
|
deploy2(State, Source) ->
|
||||||
|
ok =
|
||||||
case compile(Source) of
|
case compile(Source) of
|
||||||
% TODO: Make hz accept either the aaci or the aci, preferring the aaci if present
|
{ok, Build} -> gd_con:prompt_call({"init", init}, init, Build);
|
||||||
{ok, Build} ->
|
Other -> tell(info, "Compilation Failed!~n~tp", [Other])
|
||||||
{aaci, ContractName, Funs, NS} = maps:get(aaci, Build),
|
|
||||||
ok = tell(info, "Deploying Contract: ~p", [ContractName]),
|
|
||||||
InitSpec = maps:get("init", Funs),
|
|
||||||
deploy3(State, InitSpec, Build, NS);
|
|
||||||
Other ->
|
|
||||||
ok = tell(info, "Compilation Failed!~n~tp", [Other]),
|
|
||||||
State
|
|
||||||
end.
|
|
||||||
|
|
||||||
deploy3(State, InitSpec, Build, NS) ->
|
|
||||||
case gd_con:list_keys() of
|
|
||||||
{ok, 0, []} ->
|
|
||||||
handle_troubling(State, "No keys exist in the current wallet.");
|
|
||||||
{ok, Selected, Keys} ->
|
|
||||||
deploy4(State, InitSpec, Build, NS, Selected, Keys);
|
|
||||||
error ->
|
|
||||||
handle_troubling(State, "No wallet is selected!")
|
|
||||||
end.
|
|
||||||
|
|
||||||
deploy4(State = #s{frame = Frame, j = J}, InitSpec, Build, NS, Selected, Keys) ->
|
|
||||||
InitArgs = element(1, InitSpec),
|
|
||||||
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("Deploy Contract")),
|
|
||||||
Sizer = wxBoxSizer:new(?wxVERTICAL),
|
|
||||||
ScrollWin = wxScrolledWindow:new(Dialog),
|
|
||||||
ScrollSz = wxBoxSizer:new(?wxVERTICAL),
|
|
||||||
ok = wxScrolledWindow:setSizerAndFit(ScrollWin, ScrollSz),
|
|
||||||
ok = wxScrolledWindow:setScrollRate(ScrollWin, 5, 5),
|
|
||||||
FunName = unicode:characters_to_list(["init/", integer_to_list(length(InitArgs))]),
|
|
||||||
FunSz = wxStaticBoxSizer:new(?wxVERTICAL, ScrollWin, [{label, FunName}]),
|
|
||||||
KeySz = wxStaticBoxSizer:new(?wxVERTICAL, ScrollWin, [{label, J("Signature Key")}]),
|
|
||||||
KeyPicker = wxChoice:new(ScrollWin, ?wxID_ANY, [{choices, Keys}]),
|
|
||||||
_ = wxStaticBoxSizer:add(KeySz, KeyPicker, zxw:flags(wide)),
|
|
||||||
ok = wxChoice:setSelection(KeyPicker, Selected - 1),
|
|
||||||
{ParamSz, TTL_Tx, GasP_Tx, Gas_Tx, Amount_Tx} = call_param_sizer(ScrollWin, J),
|
|
||||||
ButtSz = wxBoxSizer:new(?wxHORIZONTAL),
|
|
||||||
Affirm = wxButton:new(Dialog, ?wxID_OK),
|
|
||||||
Cancel = wxButton:new(Dialog, ?wxID_CANCEL),
|
|
||||||
_ = wxBoxSizer:add(ButtSz, Affirm, zxw:flags(wide)),
|
|
||||||
_ = wxBoxSizer:add(ButtSz, Cancel, zxw:flags(wide)),
|
|
||||||
GridSz = wxFlexGridSizer:new(2, 4, 4),
|
|
||||||
ok = wxFlexGridSizer:setFlexibleDirection(GridSz, ?wxHORIZONTAL),
|
|
||||||
ok = wxFlexGridSizer:addGrowableCol(GridSz, 1),
|
|
||||||
ArgFields = make_arg_fields(ScrollWin, GridSz, InitArgs, NS, J),
|
|
||||||
_ = wxStaticBoxSizer:add(FunSz, GridSz, zxw:flags(wide)),
|
|
||||||
_ = wxStaticBoxSizer:add(ScrollSz, FunSz, [{proportion, 1}, {flag, ?wxEXPAND}]),
|
|
||||||
_ = wxStaticBoxSizer:add(ScrollSz, KeySz, [{proportion, 0}, {flag, ?wxEXPAND}]),
|
|
||||||
_ = wxStaticBoxSizer:add(ScrollSz, ParamSz, [{proportion, 0}, {flag, ?wxEXPAND}]),
|
|
||||||
_ = wxSizer:add(Sizer, ScrollWin, [{proportion, 5}, {flag, ?wxEXPAND}]),
|
|
||||||
_ = wxSizer:add(Sizer, ButtSz, [{proportion, 1}, {flag, ?wxEXPAND}]),
|
|
||||||
ok = wxDialog:setSizer(Dialog, Sizer),
|
|
||||||
ok = wxBoxSizer:layout(Sizer),
|
|
||||||
ok = wxDialog:setSize(Dialog, {500, 500}),
|
|
||||||
ok = wxDialog:center(Dialog),
|
|
||||||
Outcome =
|
|
||||||
case wxDialog:showModal(Dialog) of
|
|
||||||
?wxID_OK ->
|
|
||||||
ID = wxChoice:getString(KeyPicker, wxChoice:getSelection(KeyPicker)),
|
|
||||||
PK = unicode:characters_to_binary(ID),
|
|
||||||
IArgs = lists:map(fun get_arg/1, ArgFields),
|
|
||||||
Controls =
|
|
||||||
[{"TTL", TTL_Tx},
|
|
||||||
{"Gas Price", GasP_Tx},
|
|
||||||
{"Gas", Gas_Tx},
|
|
||||||
{"Amount", Amount_Tx}],
|
|
||||||
case call_params(Controls) of
|
|
||||||
{ok, [TTL, GasP, Gas, Amount]} ->
|
|
||||||
{ok, Nonce} = hz:next_nonce(PK),
|
|
||||||
DeployParams = {PK, Nonce, TTL, GasP, Gas, Amount},
|
|
||||||
{ok, DeployParams, IArgs};
|
|
||||||
E ->
|
|
||||||
E
|
|
||||||
end;
|
|
||||||
?wxID_CANCEL ->
|
|
||||||
cancel
|
|
||||||
end,
|
end,
|
||||||
ok = wxDialog:destroy(Dialog),
|
|
||||||
case Outcome of
|
|
||||||
{ok, Params, Args} -> deploy5(State, Build, Params, Args);
|
|
||||||
cancel -> State;
|
|
||||||
Error -> handle_troubling(State, Error)
|
|
||||||
end.
|
|
||||||
|
|
||||||
deploy5(State, Build, Params, Args) ->
|
|
||||||
tell(info, "Build: ~p", [Build]),
|
|
||||||
ok = gd_con:deploy(Build, Params, Args),
|
|
||||||
State.
|
State.
|
||||||
|
|
||||||
|
|
||||||
@@ -713,7 +502,8 @@ open(State = #s{frame = Frame, j = J}) ->
|
|||||||
1 -> hash;
|
1 -> hash;
|
||||||
?wxNOT_FOUND -> none
|
?wxNOT_FOUND -> none
|
||||||
end;
|
end;
|
||||||
?wxID_CANCEL -> cancel
|
?wxID_CANCEL ->
|
||||||
|
cancel
|
||||||
end,
|
end,
|
||||||
ok = wxDialog:destroy(Dialog),
|
ok = wxDialog:destroy(Dialog),
|
||||||
case Choice of
|
case Choice of
|
||||||
@@ -773,41 +563,16 @@ open_file(State = #s{frame = Frame, j = J, prefs = Prefs}) ->
|
|||||||
|
|
||||||
|
|
||||||
open_hash(State = #s{frame = Frame, j = J}) ->
|
open_hash(State = #s{frame = Frame, j = J}) ->
|
||||||
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("Retrieve Contract Source")),
|
Title = J("Retrieve Contract Source"),
|
||||||
Sizer = wxBoxSizer:new(?wxVERTICAL),
|
Label = J("Address Hash"),
|
||||||
AddressSz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("Address Hash")}]),
|
case zxw_modal_text:show(Frame, Title, [{label, Label}]) of
|
||||||
AddressTx = wxTextCtrl:new(Dialog, ?wxID_ANY),
|
{ok, Address = "ct_" ++ _} -> open_hash2(State, list_to_binary(Address));
|
||||||
_ = wxSizer:add(AddressSz, AddressTx, zxw:flags(wide)),
|
{ok, Address = "th_" ++ _} -> get_contract_from_tx(State, list_to_binary(Address));
|
||||||
ButtSz = wxBoxSizer:new(?wxHORIZONTAL),
|
|
||||||
Affirm = wxButton:new(Dialog, ?wxID_OK),
|
|
||||||
Cancel = wxButton:new(Dialog, ?wxID_CANCEL),
|
|
||||||
_ = wxBoxSizer:add(ButtSz, Affirm, zxw:flags(wide)),
|
|
||||||
_ = wxBoxSizer:add(ButtSz, Cancel, zxw:flags(wide)),
|
|
||||||
_ = wxSizer:add(Sizer, AddressSz, zxw:flags(wide)),
|
|
||||||
_ = wxSizer:add(Sizer, ButtSz, zxw:flags(wide)),
|
|
||||||
ok = wxDialog:setSizer(Dialog, Sizer),
|
|
||||||
ok = wxBoxSizer:layout(Sizer),
|
|
||||||
ok = wxDialog:setSize(Dialog, {500, 200}),
|
|
||||||
ok = wxDialog:center(Dialog),
|
|
||||||
ok = wxTextCtrl:setFocus(AddressTx),
|
|
||||||
Choice =
|
|
||||||
case wxDialog:showModal(Dialog) of
|
|
||||||
?wxID_OK ->
|
|
||||||
case wxTextCtrl:getValue(AddressTx) of
|
|
||||||
"" -> cancel;
|
|
||||||
A -> {ok, A}
|
|
||||||
end;
|
|
||||||
?wxID_CANCEL ->
|
|
||||||
cancel
|
|
||||||
end,
|
|
||||||
ok = wxDialog:destroy(Dialog),
|
|
||||||
case Choice of
|
|
||||||
{ok, Address = "ct_" ++ _} -> open_hash2(State, Address);
|
|
||||||
{ok, Address = "th_" ++ _} -> get_contract_from_tx(State, Address);
|
|
||||||
{ok, Turd} -> handle_troubling(State, {bad_address, Turd});
|
{ok, Turd} -> handle_troubling(State, {bad_address, Turd});
|
||||||
cancel -> State
|
cancel -> State
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
get_contract_from_tx(State, Address) ->
|
get_contract_from_tx(State, Address) ->
|
||||||
case hz:tx_info(Address) of
|
case hz:tx_info(Address) of
|
||||||
{ok, #{"call_info" := #{"contract_id" := Contract}}} ->
|
{ok, #{"call_info" := #{"contract_id" := Contract}}} ->
|
||||||
@@ -820,19 +585,20 @@ get_contract_from_tx(State, Address) ->
|
|||||||
|
|
||||||
open_hash2(State, Address) ->
|
open_hash2(State, Address) ->
|
||||||
case hz:contract_source(Address) of
|
case hz:contract_source(Address) of
|
||||||
|
{project, [{Name, Source}]} ->
|
||||||
|
ok = tell("Retrieved ~p from ~p", [Name, Address]),
|
||||||
|
open_hash3(State, Address, Source);
|
||||||
{ok, Source} ->
|
{ok, Source} ->
|
||||||
|
ok = tell("Retrieved uncompressed source of ~p", [Address]),
|
||||||
open_hash3(State, Address, Source);
|
open_hash3(State, Address, Source);
|
||||||
Error ->
|
Error ->
|
||||||
ok = handle_troubling(State, Error),
|
handle_troubling(State, Error)
|
||||||
State
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
open_hash3(State, Address, Source) ->
|
open_hash3(State, Address, Source) ->
|
||||||
% TODO: Compile on load and verify the deployed hash for validity.
|
% TODO: Compile on load and verify the deployed hash for validity.
|
||||||
case compile(Source) of
|
case compile(Source) of
|
||||||
{ok, Build} ->
|
{ok, _Build} ->
|
||||||
{aaci, _, FunDefs, _} = maps:get(aaci, Build),
|
|
||||||
ok = tell(info, "Compilation Succeeded!~n~tp~n~n~tp", [Build, FunDefs]),
|
|
||||||
add_code_page(State, {hash, Address}, Source);
|
add_code_page(State, {hash, Address}, Source);
|
||||||
Other ->
|
Other ->
|
||||||
ok = tell(info, "Compilation Failed!~n~tp", [Other]),
|
ok = tell(info, "Compilation Failed!~n~tp", [Other]),
|
||||||
@@ -840,30 +606,25 @@ open_hash3(State, Address, Source) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
% TODO: Break this down -- tons of things in here recur.
|
save(State = #s{prefs = Prefs, code = {Codebook, Pages}}) ->
|
||||||
save(State = #s{frame = Frame, j = J, prefs = Prefs, code = {Codebook, Pages}}) ->
|
|
||||||
case wxNotebook:getSelection(Codebook) of
|
case wxNotebook:getSelection(Codebook) of
|
||||||
?wxNOT_FOUND ->
|
?wxNOT_FOUND ->
|
||||||
State;
|
State;
|
||||||
Index ->
|
Index ->
|
||||||
case lists:nth(Index + 1, Pages) of
|
case lists:nth(Index + 1, Pages) of
|
||||||
#p{path = {file, Path}, code = Widget} ->
|
#p{path = {file, Path}, code = Widget} ->
|
||||||
Source = wxTextCtrl:getValue(Widget),
|
Source = gd_sophia_editor:get_text(Widget),
|
||||||
case filelib:ensure_dir(Path) of
|
case filelib:ensure_dir(Path) of
|
||||||
ok ->
|
ok ->
|
||||||
case file:write_file(Path, Source) of
|
case file:write_file(Path, Source) of
|
||||||
ok ->
|
ok -> State;
|
||||||
State;
|
Error -> handle_troubling(State, Error)
|
||||||
Error ->
|
|
||||||
ok = handle_troubling(State, Error),
|
|
||||||
State
|
|
||||||
end;
|
end;
|
||||||
Error ->
|
Error ->
|
||||||
ok = handle_troubling(State, Error),
|
handle_troubling(State, Error)
|
||||||
State
|
|
||||||
end;
|
end;
|
||||||
Page = #p{path = {hash, Hash}, code = Widget} ->
|
Page = #p{path = {hash, Hash}, code = Widget} ->
|
||||||
DefaultDir =
|
DefDir =
|
||||||
case maps:find(dir, Prefs) of
|
case maps:find(dir, Prefs) of
|
||||||
{ok, PrefDir} ->
|
{ok, PrefDir} ->
|
||||||
PrefDir;
|
PrefDir;
|
||||||
@@ -873,98 +634,34 @@ save(State = #s{frame = Frame, j = J, prefs = Prefs, code = {Codebook, Pages}})
|
|||||||
D -> filename:basename(D)
|
D -> filename:basename(D)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
Options =
|
DefName = unicode:characters_to_list([Hash, ".aes"]),
|
||||||
[{message, J("Save Location")},
|
save_dialog(State, DefDir, DefName, Widget, Index, Page)
|
||||||
{defaultDir, DefaultDir},
|
|
||||||
{defaultFile, unicode:characters_to_list([Hash, ".aes"])},
|
|
||||||
{wildCard, "*.aes"},
|
|
||||||
{style, ?wxFD_SAVE bor ?wxFD_OVERWRITE_PROMPT}],
|
|
||||||
Dialog = wxFileDialog:new(Frame, Options),
|
|
||||||
NewState =
|
|
||||||
case wxFileDialog:showModal(Dialog) of
|
|
||||||
?wxID_OK ->
|
|
||||||
Dir = wxFileDialog:getDirectory(Dialog),
|
|
||||||
case wxFileDialog:getFilename(Dialog) of
|
|
||||||
"" ->
|
|
||||||
State;
|
|
||||||
Name ->
|
|
||||||
File =
|
|
||||||
case filename:extension(Name) of
|
|
||||||
".aes" -> Name;
|
|
||||||
_ -> Name ++ ".aes"
|
|
||||||
end,
|
|
||||||
Path = filename:join(Dir, File),
|
|
||||||
Source = get_source(Widget),
|
|
||||||
case filelib:ensure_dir(Path) of
|
|
||||||
ok ->
|
|
||||||
case file:write_file(Path, Source) of
|
|
||||||
ok ->
|
|
||||||
true = wxNotebook:setPageText(Codebook, Index, File),
|
|
||||||
NewPrefs = maps:put(dir, Dir, Prefs),
|
|
||||||
NewPage = Page#p{path = {file, Path}},
|
|
||||||
NewPages = store_nth(Index + 1, NewPage, Pages),
|
|
||||||
NewCode = {Codebook, NewPages},
|
|
||||||
State#s{prefs = NewPrefs, code = NewCode};
|
|
||||||
Error ->
|
|
||||||
ok = handle_troubling(State, Error),
|
|
||||||
State
|
|
||||||
end;
|
|
||||||
Error ->
|
|
||||||
ok = handle_troubling(State, Error),
|
|
||||||
State
|
|
||||||
end
|
|
||||||
end;
|
|
||||||
?wxID_CANCEL ->
|
|
||||||
State
|
|
||||||
end,
|
|
||||||
ok = wxFileDialog:destroy(Dialog),
|
|
||||||
NewState
|
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
make_plain_text_control(Parent) ->
|
|
||||||
CodeTxStyle = {style, ?wxTE_MULTILINE
|
|
||||||
bor ?wxTE_PROCESS_TAB
|
|
||||||
bor ?wxTE_DONTWRAP
|
|
||||||
bor ?wxTE_READONLY},
|
|
||||||
CodeTx = wxTextCtrl:new(Parent, ?wxID_ANY, [CodeTxStyle]),
|
|
||||||
Mono = wxFont:new(10, ?wxMODERN, ?wxNORMAL, ?wxNORMAL, [{face, "Monospace"}]),
|
|
||||||
TextAt = wxTextAttr:new(),
|
|
||||||
ok = wxTextAttr:setFont(TextAt, Mono),
|
|
||||||
true = wxTextCtrl:setDefaultStyle(CodeTx, TextAt),
|
|
||||||
CodeTx.
|
|
||||||
|
|
||||||
make_source_text_control(Parent) ->
|
rename(State = #s{code = {Codebook, Pages}}) ->
|
||||||
case ?editorMode of
|
|
||||||
plain -> make_plain_text_control(Parent);
|
|
||||||
sophia -> gd_sophia_editor:new(Parent)
|
|
||||||
end.
|
|
||||||
|
|
||||||
get_source(Widget) ->
|
|
||||||
case ?editorMode of
|
|
||||||
plain -> wxTextCtrl:getValue(Widget);
|
|
||||||
sophia -> gd_sophia_editor:get_text(Widget)
|
|
||||||
end.
|
|
||||||
|
|
||||||
set_source(Widget, Src) ->
|
|
||||||
case ?editorMode of
|
|
||||||
plain -> wxTextCtrl:setValue(Widget, Src);
|
|
||||||
sophia -> gd_sophia_editor:set_text(Widget, Src)
|
|
||||||
end.
|
|
||||||
|
|
||||||
% TODO: Break this down -- tons of things in here recur.
|
|
||||||
rename(State = #s{frame = Frame, j = J, prefs = Prefs, code = {Codebook, Pages}}) ->
|
|
||||||
case wxNotebook:getSelection(Codebook) of
|
case wxNotebook:getSelection(Codebook) of
|
||||||
?wxNOT_FOUND ->
|
?wxNOT_FOUND ->
|
||||||
State;
|
State;
|
||||||
Index ->
|
Index ->
|
||||||
case lists:nth(Index + 1, Pages) of
|
case lists:nth(Index + 1, Pages) of
|
||||||
Page = #p{path = {file, Path}, code = Widget} ->
|
Page = #p{path = {file, Path}, code = Widget} ->
|
||||||
DefaultDir = filename:dirname(Path),
|
DefDir = filename:dirname(Path),
|
||||||
|
DefName = filename:basename(Path),
|
||||||
|
save_dialog(State, DefDir, DefName, Widget, Index, Page);
|
||||||
|
#p{path = {hash, _}} ->
|
||||||
|
save(State)
|
||||||
|
end
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
save_dialog(State = #s{frame = Frame, j = J, prefs = Prefs, code = {Codebook, Pages}},
|
||||||
|
DefDir, DefName, Widget, Index, Page) ->
|
||||||
Options =
|
Options =
|
||||||
[{message, J("Save Location")},
|
[{message, J("Save Location")},
|
||||||
{defaultDir, DefaultDir},
|
{defaultDir, DefDir},
|
||||||
{defaultFile, filename:basename(Path)},
|
{defaultFile, DefName},
|
||||||
{wildCard, "*.aes"},
|
{wildCard, "*.aes"},
|
||||||
{style, ?wxFD_SAVE bor ?wxFD_OVERWRITE_PROMPT}],
|
{style, ?wxFD_SAVE bor ?wxFD_OVERWRITE_PROMPT}],
|
||||||
Dialog = wxFileDialog:new(Frame, Options),
|
Dialog = wxFileDialog:new(Frame, Options),
|
||||||
@@ -982,7 +679,7 @@ rename(State = #s{frame = Frame, j = J, prefs = Prefs, code = {Codebook, Pages}}
|
|||||||
_ -> Name ++ ".aes"
|
_ -> Name ++ ".aes"
|
||||||
end,
|
end,
|
||||||
NewPath = filename:join(Dir, File),
|
NewPath = filename:join(Dir, File),
|
||||||
Source = get_source(Widget),
|
Source = gd_sophia_editor:get_text(Widget),
|
||||||
case filelib:ensure_dir(NewPath) of
|
case filelib:ensure_dir(NewPath) of
|
||||||
ok ->
|
ok ->
|
||||||
case file:write_file(NewPath, Source) of
|
case file:write_file(NewPath, Source) of
|
||||||
@@ -994,23 +691,17 @@ rename(State = #s{frame = Frame, j = J, prefs = Prefs, code = {Codebook, Pages}}
|
|||||||
NewCode = {Codebook, NewPages},
|
NewCode = {Codebook, NewPages},
|
||||||
State#s{prefs = NewPrefs, code = NewCode};
|
State#s{prefs = NewPrefs, code = NewCode};
|
||||||
Error ->
|
Error ->
|
||||||
ok = handle_troubling(State, Error),
|
handle_troubling(State, Error)
|
||||||
State
|
|
||||||
end;
|
end;
|
||||||
Error ->
|
Error ->
|
||||||
ok = handle_troubling(State, Error),
|
handle_troubling(State, Error)
|
||||||
State
|
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
?wxID_CANCEL ->
|
?wxID_CANCEL ->
|
||||||
State
|
State
|
||||||
end,
|
end,
|
||||||
ok = wxFileDialog:destroy(Dialog),
|
ok = wxFileDialog:destroy(Dialog),
|
||||||
NewState;
|
NewState.
|
||||||
#p{path = {hash, _}} ->
|
|
||||||
save(State)
|
|
||||||
end
|
|
||||||
end.
|
|
||||||
|
|
||||||
|
|
||||||
close_source(State = #s{code = {Codebook, Pages}}) ->
|
close_source(State = #s{code = {Codebook, Pages}}) ->
|
||||||
@@ -1028,41 +719,16 @@ load(State = #s{frame = Frame, j = J}) ->
|
|||||||
% TODO: Extract the exact compiler version, load it, and use only that or fail if
|
% TODO: Extract the exact compiler version, load it, and use only that or fail if
|
||||||
% the specific version is unavailable.
|
% the specific version is unavailable.
|
||||||
% TODO: Compile on load and verify the deployed hash for validity.
|
% TODO: Compile on load and verify the deployed hash for validity.
|
||||||
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("Retrieve Contract Source")),
|
Title = J("Retrieve Contract Source"),
|
||||||
Sizer = wxBoxSizer:new(?wxVERTICAL),
|
Label = J("Address Hash"),
|
||||||
AddressSz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("Address Hash")}]),
|
case zxw_modal_text:show(Frame, Title, [{label, Label}]) of
|
||||||
AddressTx = wxTextCtrl:new(Dialog, ?wxID_ANY),
|
|
||||||
_ = wxSizer:add(AddressSz, AddressTx, zxw:flags(wide)),
|
|
||||||
ButtSz = wxBoxSizer:new(?wxHORIZONTAL),
|
|
||||||
Affirm = wxButton:new(Dialog, ?wxID_OK),
|
|
||||||
Cancel = wxButton:new(Dialog, ?wxID_CANCEL),
|
|
||||||
_ = wxBoxSizer:add(ButtSz, Affirm, zxw:flags(wide)),
|
|
||||||
_ = wxBoxSizer:add(ButtSz, Cancel, zxw:flags(wide)),
|
|
||||||
_ = wxSizer:add(Sizer, AddressSz, zxw:flags(wide)),
|
|
||||||
_ = wxSizer:add(Sizer, ButtSz, zxw:flags(wide)),
|
|
||||||
ok = wxDialog:setSizer(Dialog, Sizer),
|
|
||||||
ok = wxBoxSizer:layout(Sizer),
|
|
||||||
ok = wxDialog:setSize(Dialog, {500, 200}),
|
|
||||||
ok = wxDialog:center(Dialog),
|
|
||||||
ok = wxTextCtrl:setFocus(AddressTx),
|
|
||||||
Choice =
|
|
||||||
case wxDialog:showModal(Dialog) of
|
|
||||||
?wxID_OK ->
|
|
||||||
case wxTextCtrl:getValue(AddressTx) of
|
|
||||||
"" -> cancel;
|
|
||||||
A -> {ok, A}
|
|
||||||
end;
|
|
||||||
?wxID_CANCEL ->
|
|
||||||
cancel
|
|
||||||
end,
|
|
||||||
ok = wxDialog:destroy(Dialog),
|
|
||||||
case Choice of
|
|
||||||
{ok, Address = "ct_" ++ _} -> load2(State, Address);
|
{ok, Address = "ct_" ++ _} -> load2(State, Address);
|
||||||
{ok, Address = "th_" ++ _} -> load_from_tx(State, Address);
|
{ok, Address = "th_" ++ _} -> load_from_tx(State, Address);
|
||||||
{ok, Turd} -> handle_troubling(State, {bad_address, Turd});
|
{ok, Turd} -> handle_troubling(State, {bad_address, Turd});
|
||||||
cancel -> State
|
cancel -> State
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
load_from_tx(State, Address) ->
|
load_from_tx(State, Address) ->
|
||||||
case hz:tx_info(Address) of
|
case hz:tx_info(Address) of
|
||||||
{ok, #{"call_info" := #{"contract_id" := Contract}}} ->
|
{ok, #{"call_info" := #{"contract_id" := Contract}}} ->
|
||||||
@@ -1073,24 +739,36 @@ load_from_tx(State, Address) ->
|
|||||||
handle_troubling(State, Error)
|
handle_troubling(State, Error)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
load2(State, Address) ->
|
load2(State = #s{cons = {_, Pages}}, Address) when is_binary(Address) ->
|
||||||
|
case lists:keyfind(Address, #c.id, Pages) of
|
||||||
|
false -> load3(State, Address);
|
||||||
|
#c{} -> State
|
||||||
|
end;
|
||||||
|
load2(State, Address) when is_list(Address) ->
|
||||||
|
load2(State, list_to_binary(Address)).
|
||||||
|
|
||||||
|
load3(State, Address) ->
|
||||||
case hz:contract_source(Address) of
|
case hz:contract_source(Address) of
|
||||||
|
{project, [{Name, Source}]} ->
|
||||||
|
ok = tell("Retrieved ~p from ~p", [Name, Address]),
|
||||||
|
load4(State, Address, Source);
|
||||||
{ok, Source} ->
|
{ok, Source} ->
|
||||||
load3(State, Address, Source);
|
ok = tell("Retrieved uncompressed source of ~p", [Address]),
|
||||||
|
load4(State, Address, Source);
|
||||||
Error ->
|
Error ->
|
||||||
ok = handle_troubling(State, Error),
|
handle_troubling(State, Error)
|
||||||
State
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
load3(State = #s{tabs = TopBook, cons = {Consbook, Pages}, buttons = Buttons, j = J},
|
load4(State = #s{tabs = TopBook, cons = {Consbook, Pages}, buttons = Buttons, j = J},
|
||||||
Address,
|
Address,
|
||||||
Source) ->
|
Source) ->
|
||||||
Window = wxWindow:new(Consbook, ?wxID_ANY),
|
Window = wxWindow:new(Consbook, ?wxID_ANY),
|
||||||
PageSz = wxBoxSizer:new(?wxVERTICAL),
|
PageSz = wxBoxSizer:new(?wxVERTICAL),
|
||||||
ProgSz = wxBoxSizer:new(?wxHORIZONTAL),
|
ProgSz = wxBoxSizer:new(?wxHORIZONTAL),
|
||||||
CodeSz = wxStaticBoxSizer:new(?wxVERTICAL, Window, [{label, J("Contract Source")}]),
|
CodeSz = wxStaticBoxSizer:new(?wxVERTICAL, Window, [{label, J("Contract Source")}]),
|
||||||
CodeTx = make_source_text_control(Window),
|
CodeTx = gd_sophia_editor:new(Window),
|
||||||
ok = set_source(CodeTx, Source),
|
ok = gd_sophia_editor:set_text(CodeTx, Source),
|
||||||
|
ok = gd_sophia_editor:update(CodeTx),
|
||||||
_ = wxSizer:add(CodeSz, CodeTx, zxw:flags(wide)),
|
_ = wxSizer:add(CodeSz, CodeTx, zxw:flags(wide)),
|
||||||
ScrollWin = wxScrolledWindow:new(Window),
|
ScrollWin = wxScrolledWindow:new(Window),
|
||||||
FunSz = wxStaticBoxSizer:new(?wxVERTICAL, ScrollWin, [{label, J("Function Interfaces")}]),
|
FunSz = wxStaticBoxSizer:new(?wxVERTICAL, ScrollWin, [{label, J("Function Interfaces")}]),
|
||||||
@@ -1099,18 +777,17 @@ load3(State = #s{tabs = TopBook, cons = {Consbook, Pages}, buttons = Buttons, j
|
|||||||
ConsSz = wxStaticBoxSizer:new(?wxVERTICAL, Window, [{label, J("Console")}]),
|
ConsSz = wxStaticBoxSizer:new(?wxVERTICAL, Window, [{label, J("Console")}]),
|
||||||
ConsTxStyle = {style, ?wxTE_MULTILINE bor ?wxTE_READONLY},
|
ConsTxStyle = {style, ?wxTE_MULTILINE bor ?wxTE_READONLY},
|
||||||
ConsTx = wxTextCtrl:new(Window, ?wxID_ANY, [ConsTxStyle]),
|
ConsTx = wxTextCtrl:new(Window, ?wxID_ANY, [ConsTxStyle]),
|
||||||
_ = wxSizer:add(ConsSz, ConsTx, zxw:flags(wide)),
|
_ = wxSizer:add(ConsSz, ConsTx, zxw:flags({wide, 5})),
|
||||||
_ = wxSizer:add(ProgSz, CodeSz, [{proportion, 2}, {flag, ?wxEXPAND}]),
|
_ = wxSizer:add(ProgSz, CodeSz, [{proportion, 3}, {flag, ?wxEXPAND bor ?wxALL}, {border, 5}]),
|
||||||
_ = wxSizer:add(ProgSz, ScrollWin, [{proportion, 1}, {flag, ?wxEXPAND}]),
|
_ = wxSizer:add(ProgSz, ScrollWin, [{proportion, 1}, {flag, ?wxEXPAND bor ?wxALL}, {border, 5}]),
|
||||||
_ = wxSizer:add(PageSz, ProgSz, [{proportion, 3}, {flag, ?wxEXPAND}]),
|
_ = wxSizer:add(PageSz, ProgSz, [{proportion, 3}, {flag, ?wxEXPAND bor ?wxALL}, {border, 5}]),
|
||||||
_ = wxSizer:add(PageSz, ConsSz, [{proportion, 1}, {flag, ?wxEXPAND}]),
|
_ = wxSizer:add(PageSz, ConsSz, [{proportion, 1}, {flag, ?wxEXPAND bor ?wxALL}, {border, 5}]),
|
||||||
{Out, IFaces, Build, NewButtons} =
|
{Out, IFaces, Build, NewButtons} =
|
||||||
case compile(Source) of
|
case compile(Source) of
|
||||||
{ok, Output} ->
|
{ok, Output} ->
|
||||||
{aaci, _, Funs, NS} = maps:get(aaci, Output),
|
{aaci, _, Funs, _} = maps:get(aaci, Output),
|
||||||
Callable = maps:remove("init", Funs),
|
Callable = maps:remove("init", Funs),
|
||||||
tell(info, "Callable: ~p", [Callable]),
|
{NB, IFs} = fun_interfaces(ScrollWin, FunSz, Buttons, Callable, J),
|
||||||
{NB, IFs} = fun_interfaces(ScrollWin, FunSz, Buttons, Callable, NS, J),
|
|
||||||
O = io_lib:format("Compilation Succeeded!~n~tp~n~nDone!~n", [Output]),
|
O = io_lib:format("Compilation Succeeded!~n~tp~n~nDone!~n", [Output]),
|
||||||
{O, IFs, Output, NB};
|
{O, IFs, Output, NB};
|
||||||
Other ->
|
Other ->
|
||||||
@@ -1130,143 +807,27 @@ load3(State = #s{tabs = TopBook, cons = {Consbook, Pages}, buttons = Buttons, j
|
|||||||
State#s{cons = {Consbook, NewPages}, buttons = NewButtons}.
|
State#s{cons = {Consbook, NewPages}, buttons = NewButtons}.
|
||||||
|
|
||||||
|
|
||||||
get_arg({list, AFs, _}) ->
|
fun_interfaces(ScrollWin, FunSz, Buttons, Funs, J) ->
|
||||||
lists:map(fun get_arg/1, AFs);
|
|
||||||
get_arg({record, AFs}) ->
|
|
||||||
get_record(AFs);
|
|
||||||
get_arg({tuple, AFs}) ->
|
|
||||||
list_to_tuple(lists:map(fun get_arg/1, AFs));
|
|
||||||
get_arg({map, [Key, Value]}) ->
|
|
||||||
#{get_arg(Key) => get_arg(Value)};
|
|
||||||
get_arg({variant, AFs, [VariantOne | _]}) ->
|
|
||||||
Elems = lists:map(fun get_arg/1, AFs),
|
|
||||||
list_to_tuple([VariantOne | Elems]);
|
|
||||||
get_arg({_, TextCtrl}) ->
|
|
||||||
wxTextCtrl:getValue(TextCtrl).
|
|
||||||
|
|
||||||
get_record([{L, A} | T]) ->
|
|
||||||
[{L, get_arg(A)} | get_record(T)].
|
|
||||||
|
|
||||||
fun_interfaces(ScrollWin, FunSz, Buttons, Funs, NS, J) ->
|
|
||||||
MakeIface =
|
MakeIface =
|
||||||
fun(Name, {Args, _}) ->
|
fun(Name, {Args, _}) ->
|
||||||
tell(info, "Fun: ~p, Args: ~p", [Name, Args]),
|
|
||||||
FunName = unicode:characters_to_list([Name, "/", integer_to_list(length(Args))]),
|
FunName = unicode:characters_to_list([Name, "/", integer_to_list(length(Args))]),
|
||||||
FN = wxStaticBoxSizer:new(?wxVERTICAL, ScrollWin, [{label, FunName}]),
|
FS = wxBoxSizer:new(?wxHORIZONTAL),
|
||||||
GridSz = wxFlexGridSizer:new(2, 4, 4),
|
FLabel = wxStaticText:new(ScrollWin, ?wxID_ANY, FunName),
|
||||||
ok = wxFlexGridSizer:setFlexibleDirection(GridSz, ?wxHORIZONTAL),
|
|
||||||
ok = wxFlexGridSizer:addGrowableCol(GridSz, 1),
|
|
||||||
ArgFields = make_arg_fields(ScrollWin, GridSz, Args, NS, J),
|
|
||||||
ButtSz = wxBoxSizer:new(?wxHORIZONTAL),
|
|
||||||
CallBn = wxButton:new(ScrollWin, ?wxID_ANY, [{label, J("Call")}]),
|
CallBn = wxButton:new(ScrollWin, ?wxID_ANY, [{label, J("Call")}]),
|
||||||
DryRBn = wxButton:new(ScrollWin, ?wxID_ANY, [{label, J("Dry Run")}]),
|
DryRBn = wxButton:new(ScrollWin, ?wxID_ANY, [{label, J("Dry Run")}]),
|
||||||
_ = wxBoxSizer:add(ButtSz, CallBn, zxw:flags(wide)),
|
_ = wxBoxSizer:add(FS, FLabel, zxw:flags(wide)),
|
||||||
_ = wxBoxSizer:add(ButtSz, DryRBn, zxw:flags(wide)),
|
_ = wxBoxSizer:add(FS, CallBn, zxw:flags(base)),
|
||||||
|
_ = wxBoxSizer:add(FS, DryRBn, zxw:flags(base)),
|
||||||
CallButton = #w{name = {Name, call}, id = wxButton:getId(CallBn), wx = CallBn},
|
CallButton = #w{name = {Name, call}, id = wxButton:getId(CallBn), wx = CallBn},
|
||||||
DryRButton = #w{name = {Name, dryr}, id = wxButton:getId(DryRBn), wx = DryRBn},
|
DryRButton = #w{name = {Name, dryr}, id = wxButton:getId(DryRBn), wx = DryRBn},
|
||||||
_ = wxStaticBoxSizer:add(FN, GridSz, zxw:flags(wide)),
|
_ = wxSizer:add(FunSz, FS, zxw:flags({base, 5})),
|
||||||
_ = wxStaticBoxSizer:add(FN, ButtSz, zxw:flags(base)),
|
#f{name = Name, call = CallButton, dryrun = DryRButton, args = Args}
|
||||||
_ = wxSizer:add(FunSz, FN, zxw:flags(base)),
|
|
||||||
#f{name = Name, call = CallButton, dryrun = DryRButton, args = ArgFields}
|
|
||||||
end,
|
end,
|
||||||
IFaces = maps:map(MakeIface, Funs),
|
Iterator = maps:iterator(Funs, ordered),
|
||||||
tell(info, "IFaces: ~p", [IFaces]),
|
IFaces = maps:map(MakeIface, Iterator),
|
||||||
NewButtons = maps:fold(fun map_iface_buttons/3, Buttons, IFaces),
|
NewButtons = maps:fold(fun map_iface_buttons/3, Buttons, IFaces),
|
||||||
{NewButtons, IFaces}.
|
{NewButtons, IFaces}.
|
||||||
|
|
||||||
% FIXME: This can be simplified and needs to provide better widgets for types.
|
|
||||||
% "variant" types should be wxChoice
|
|
||||||
% Booleans should either be wxChoice or check boxes
|
|
||||||
% The sizer expansion direction for vertical elements is stupid
|
|
||||||
% FIXME: We probably don't need the opaque type definitions 'NS', since the
|
|
||||||
% AACI already caches the useful expansions that might be needed for error
|
|
||||||
% messages.
|
|
||||||
make_arg_fields(ScrollWin, GridSz, Args, NS, J) ->
|
|
||||||
MakeArgField =
|
|
||||||
fun
|
|
||||||
({AN, {_O, _N, T}}) when is_atom(T) ->
|
|
||||||
% tell(info, "~p Arg: ~p, Type: ~p", [?LINE, AN, T]),
|
|
||||||
ANT = wxStaticText:new(ScrollWin, ?wxID_ANY, AN),
|
|
||||||
TCT = wxTextCtrl:new(ScrollWin, ?wxID_ANY),
|
|
||||||
_ = wxFlexGridSizer:add(GridSz, ANT, fill()),
|
|
||||||
_ = wxFlexGridSizer:add(GridSz, TCT, fill()),
|
|
||||||
{T, TCT};
|
|
||||||
({AN, {_O, _N, {record, InnerArgs}}}) ->
|
|
||||||
% tell(info, "~p Arg: ~p, ~p: ~p", [?LINE, AN, TypeName, InnerArgs]),
|
|
||||||
ANT = wxStaticText:new(ScrollWin, ?wxID_ANY, AN),
|
|
||||||
InnerSz = wxFlexGridSizer:new(2, 4, 4),
|
|
||||||
ok = wxFlexGridSizer:setFlexibleDirection(InnerSz, ?wxHORIZONTAL),
|
|
||||||
ok = wxFlexGridSizer:addGrowableCol(InnerSz, 1),
|
|
||||||
AFs = make_arg_fields(ScrollWin, InnerSz, InnerArgs, NS, J),
|
|
||||||
_ = wxFlexGridSizer:add(GridSz, ANT, fill()),
|
|
||||||
_ = wxFlexGridSizer:add(GridSz, InnerSz, fill()),
|
|
||||||
{record, AFs};
|
|
||||||
({AN, {_O, _N, {tuple, InnerArgs}}}) ->
|
|
||||||
% tell(info, "~p Arg: ~p, ~p: ~p", [?LINE, AN, TypeName, InnerArgs]),
|
|
||||||
ANT = wxStaticText:new(ScrollWin, ?wxID_ANY, AN),
|
|
||||||
InnerSz = wxFlexGridSizer:new(2, 4, 4),
|
|
||||||
ok = wxFlexGridSizer:setFlexibleDirection(InnerSz, ?wxHORIZONTAL),
|
|
||||||
ok = wxFlexGridSizer:addGrowableCol(InnerSz, 1),
|
|
||||||
AFs = make_unnamed_fields(ScrollWin, InnerSz, InnerArgs, NS, J),
|
|
||||||
_ = wxFlexGridSizer:add(GridSz, ANT, fill()),
|
|
||||||
_ = wxFlexGridSizer:add(GridSz, InnerSz, fill()),
|
|
||||||
{tuple, AFs};
|
|
||||||
({AN, {_O, _N, {list, [InnerType]}}}) ->
|
|
||||||
% tell(info, "~p Arg: ~p, ~p: ~p", [?LINE, AN, TypeName, InnerArgs]),
|
|
||||||
ANT = wxStaticText:new(ScrollWin, ?wxID_ANY, AN),
|
|
||||||
ArgSz = wxBoxSizer:new(?wxVERTICAL),
|
|
||||||
InnerSz = wxFlexGridSizer:new(2, 4, 4),
|
|
||||||
ok = wxFlexGridSizer:setFlexibleDirection(InnerSz, ?wxHORIZONTAL),
|
|
||||||
ok = wxFlexGridSizer:addGrowableCol(InnerSz, 1),
|
|
||||||
AFs = make_unnamed_fields(ScrollWin, InnerSz, [InnerType], NS, J),
|
|
||||||
B = wxButton:new(ScrollWin, ?wxID_ANY, [{label, J("Add")}]),
|
|
||||||
AB = #w{name = {AN, add}, id = wxButton:getId(B), wx = B},
|
|
||||||
_ = wxBoxSizer:add(ArgSz, InnerSz, fill()),
|
|
||||||
_ = wxBoxSizer:add(ArgSz, B, fill()),
|
|
||||||
_ = wxFlexGridSizer:add(GridSz, ANT, fill()),
|
|
||||||
_ = wxFlexGridSizer:add(GridSz, ArgSz, fill()),
|
|
||||||
{list, AFs, AB};
|
|
||||||
({AN, {_O, _N, {map, [Key, Value]}}}) ->
|
|
||||||
% tell(info, "~p Arg: ~p, ~p: ~p", [?LINE, AN, TypeName, T]),
|
|
||||||
ANT = wxStaticText:new(ScrollWin, ?wxID_ANY, AN),
|
|
||||||
InnerSz = wxFlexGridSizer:new(2, 4, 4),
|
|
||||||
ok = wxFlexGridSizer:setFlexibleDirection(InnerSz, ?wxHORIZONTAL),
|
|
||||||
ok = wxFlexGridSizer:addGrowableCol(InnerSz, 1),
|
|
||||||
AFs = make_unnamed_fields(ScrollWin, InnerSz, [Key, Value], NS, J),
|
|
||||||
_ = wxFlexGridSizer:add(GridSz, ANT, fill()),
|
|
||||||
_ = wxFlexGridSizer:add(GridSz, InnerSz, fill()),
|
|
||||||
{map, AFs};
|
|
||||||
({AN, {_O, _N, {variant, Variants = [{_, VariantElements} | _]}}}) ->
|
|
||||||
% tell(info, "~p Arg: ~p, ~p: ~p", [?LINE, AN, TypeName, InnerArgs]),
|
|
||||||
ANT = wxStaticText:new(ScrollWin, ?wxID_ANY, AN),
|
|
||||||
InnerSz = wxFlexGridSizer:new(2, 4, 4),
|
|
||||||
ok = wxFlexGridSizer:setFlexibleDirection(InnerSz, ?wxHORIZONTAL),
|
|
||||||
ok = wxFlexGridSizer:addGrowableCol(InnerSz, 1),
|
|
||||||
AFs = make_unnamed_fields(ScrollWin, InnerSz, VariantElements, NS, J),
|
|
||||||
_ = wxFlexGridSizer:add(GridSz, ANT, fill()),
|
|
||||||
_ = wxFlexGridSizer:add(GridSz, InnerSz, fill()),
|
|
||||||
VariantNames = lists:map(fun({Name, _}) -> Name end, Variants),
|
|
||||||
{variant, AFs, VariantNames}
|
|
||||||
end,
|
|
||||||
lists:map(MakeArgField, Args).
|
|
||||||
|
|
||||||
make_unnamed_fields(ScrollWin, InnerSz, Elems, NS, J) ->
|
|
||||||
ChooseName =
|
|
||||||
fun
|
|
||||||
(Ann = {_, _, T}) when is_atom(T) ->
|
|
||||||
{atom_to_list(T), Ann};
|
|
||||||
(Ann = {Name, _, {record, _}}) when is_list(Name) ->
|
|
||||||
io:format("record: ~p~n", [Ann]),
|
|
||||||
{Name, Ann};
|
|
||||||
(Ann = {_, _, {T, _}}) when is_atom(T) ->
|
|
||||||
{atom_to_list(T), Ann}
|
|
||||||
end,
|
|
||||||
WithNames = lists:map(ChooseName, Elems),
|
|
||||||
make_arg_fields(ScrollWin, InnerSz, WithNames, NS, J).
|
|
||||||
|
|
||||||
fill() ->
|
|
||||||
[{proportion, 0}, {flag, ?wxEXPAND}].
|
|
||||||
|
|
||||||
|
|
||||||
map_iface_buttons(_, #f{call = C = #w{id = CID}, dryrun = D = #w{id = DID}}, A) ->
|
map_iface_buttons(_, #f{call = C = #w{id = CID}, dryrun = D = #w{id = DID}}, A) ->
|
||||||
maps:merge(#{CID => C, DID => D}, A);
|
maps:merge(#{CID => C, DID => D}, A);
|
||||||
@@ -1281,7 +842,7 @@ edit(State = #s{cons = {Consbook, Pages}}) ->
|
|||||||
Index ->
|
Index ->
|
||||||
#c{code = CodeTx} = lists:nth(Index + 1, Pages),
|
#c{code = CodeTx} = lists:nth(Index + 1, Pages),
|
||||||
Address = wxNotebook:getPageText(Consbook, Index),
|
Address = wxNotebook:getPageText(Consbook, Index),
|
||||||
Source = wxTextCtrl:getValue(CodeTx),
|
Source = gd_sophia_editor:get_text(CodeTx),
|
||||||
add_code_page(State, {hash, Address}, Source)
|
add_code_page(State, {hash, Address}, Source)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@@ -1292,7 +853,8 @@ close_instance(State = #s{cons = {Consbook, Pages}, buttons = Buttons}) ->
|
|||||||
State;
|
State;
|
||||||
Index ->
|
Index ->
|
||||||
{#c{funs = {_, IFaces}}, NewPages} = take_nth(Index + 1, Pages),
|
{#c{funs = {_, IFaces}}, NewPages} = take_nth(Index + 1, Pages),
|
||||||
IDs = list_iface_buttons(IFaces),
|
log(info, "IFaces: ~tp", [IFaces]),
|
||||||
|
IDs = list_iface_buttons(maps:values(IFaces)),
|
||||||
NewButtons = maps:without(IDs, Buttons),
|
NewButtons = maps:without(IDs, Buttons),
|
||||||
true = wxNotebook:deletePage(Consbook, Index),
|
true = wxNotebook:deletePage(Consbook, Index),
|
||||||
State#s{cons = {Consbook, NewPages}, buttons = NewButtons}
|
State#s{cons = {Consbook, NewPages}, buttons = NewButtons}
|
||||||
@@ -1313,7 +875,7 @@ compile(Source) ->
|
|||||||
case so_compiler:from_string(Source, Options) of
|
case so_compiler:from_string(Source, Options) of
|
||||||
{ok, Build} ->
|
{ok, Build} ->
|
||||||
ACI = maps:get(aci, Build),
|
ACI = maps:get(aci, Build),
|
||||||
AACI = hz:prepare_aaci(ACI),
|
AACI = hz_aaci:prepare(ACI),
|
||||||
Complete = maps:put(aaci, AACI, Build),
|
Complete = maps:put(aaci, AACI, Build),
|
||||||
{ok, Complete};
|
{ok, Complete};
|
||||||
Other ->
|
Other ->
|
||||||
|
|||||||
+3
-7
@@ -1,5 +1,5 @@
|
|||||||
-module(gd_v_netman).
|
-module(gd_v_netman).
|
||||||
-vsn("0.7.0").
|
-vsn("0.9.0").
|
||||||
-author("Craig Everett <zxq9@zxq9.com>").
|
-author("Craig Everett <zxq9@zxq9.com>").
|
||||||
-copyright("QPQ AG <info@qpq.swiss>").
|
-copyright("QPQ AG <info@qpq.swiss>").
|
||||||
-license("GPL-3.0-or-later").
|
-license("GPL-3.0-or-later").
|
||||||
@@ -14,13 +14,9 @@
|
|||||||
handle_call/3, handle_cast/2, handle_info/2, handle_event/2]).
|
handle_call/3, handle_cast/2, handle_info/2, handle_event/2]).
|
||||||
-include("$zx_include/zx_logger.hrl").
|
-include("$zx_include/zx_logger.hrl").
|
||||||
-include("gd.hrl").
|
-include("gd.hrl").
|
||||||
|
-include("gdl.hrl").
|
||||||
|
|
||||||
|
|
||||||
-record(w,
|
|
||||||
{name = none :: atom(),
|
|
||||||
id = 0 :: integer(),
|
|
||||||
wx = none :: none | wx:wx_object()}).
|
|
||||||
|
|
||||||
-record(s,
|
-record(s,
|
||||||
{wx = none :: none | wx:wx_object(),
|
{wx = none :: none | wx:wx_object(),
|
||||||
frame = none :: none | wx:wx_object(),
|
frame = none :: none | wx:wx_object(),
|
||||||
@@ -60,7 +56,7 @@ start_link(Args) ->
|
|||||||
|
|
||||||
|
|
||||||
init({Prefs, Manifest}) ->
|
init({Prefs, Manifest}) ->
|
||||||
Lang = maps:get(lang, Prefs, en_us),
|
Lang = maps:get(lang, Prefs, en),
|
||||||
Trans = gd_jt:read_translations(?MODULE),
|
Trans = gd_jt:read_translations(?MODULE),
|
||||||
J = gd_jt:j(Lang, Trans),
|
J = gd_jt:j(Lang, Trans),
|
||||||
Wx = wx:new(),
|
Wx = wx:new(),
|
||||||
|
|||||||
+19
-85
@@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
|
|
||||||
-module(gd_v_wallman).
|
-module(gd_v_wallman).
|
||||||
-vsn("0.7.0").
|
-vsn("0.9.0").
|
||||||
-author("Craig Everett <zxq9@zxq9.com>").
|
-author("Craig Everett <zxq9@zxq9.com>").
|
||||||
-copyright("QPQ AG <info@qpq.swiss>").
|
-copyright("QPQ AG <info@qpq.swiss>").
|
||||||
-license("GPL-3.0-or-later").
|
-license("GPL-3.0-or-later").
|
||||||
@@ -28,13 +28,9 @@
|
|||||||
handle_call/3, handle_cast/2, handle_info/2, handle_event/2]).
|
handle_call/3, handle_cast/2, handle_info/2, handle_event/2]).
|
||||||
-include("$zx_include/zx_logger.hrl").
|
-include("$zx_include/zx_logger.hrl").
|
||||||
-include("gd.hrl").
|
-include("gd.hrl").
|
||||||
|
-include("gdl.hrl").
|
||||||
|
|
||||||
|
|
||||||
-record(w,
|
|
||||||
{name = none :: atom(),
|
|
||||||
id = 0 :: integer(),
|
|
||||||
wx = none :: none | wx:wx_object()}).
|
|
||||||
|
|
||||||
-record(s,
|
-record(s,
|
||||||
{wx = none :: none | wx:wx_object(),
|
{wx = none :: none | wx:wx_object(),
|
||||||
frame = none :: none | wx:wx_object(),
|
frame = none :: none | wx:wx_object(),
|
||||||
@@ -90,7 +86,7 @@ start_link(Args) ->
|
|||||||
|
|
||||||
|
|
||||||
init({Prefs, Manifest}) ->
|
init({Prefs, Manifest}) ->
|
||||||
Lang = maps:get(lang, Prefs, en_us),
|
Lang = maps:get(lang, Prefs, en),
|
||||||
Trans = gd_jt:read_translations(?MODULE),
|
Trans = gd_jt:read_translations(?MODULE),
|
||||||
J = gd_jt:j(Lang, Trans),
|
J = gd_jt:j(Lang, Trans),
|
||||||
Wx = wx:new(),
|
Wx = wx:new(),
|
||||||
@@ -317,41 +313,15 @@ do_open2(Selected, State = #s{wallets = Wallets}) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
do_open3(Path, State = #s{frame = Frame, j = J}) ->
|
do_open3(Path, State = #s{frame = Frame, j = J}) ->
|
||||||
Label = J("Password"),
|
Title = J("Passphrase"),
|
||||||
Dialog = wxDialog:new(Frame, ?wxID_ANY, Label),
|
case zxw_modal_text:show(Frame, Title, [{password, true}]) of
|
||||||
Sizer = wxBoxSizer:new(?wxVERTICAL),
|
{ok, Phrase} ->
|
||||||
PassSz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, Label}]),
|
|
||||||
PassTx = wxTextCtrl:new(Dialog, ?wxID_ANY, [{style, ?wxTE_PASSWORD}]),
|
|
||||||
_ = wxStaticBoxSizer:add(PassSz, PassTx, zxw:flags(wide)),
|
|
||||||
ButtSz = wxBoxSizer:new(?wxHORIZONTAL),
|
|
||||||
Affirm = wxButton:new(Dialog, ?wxID_OK),
|
|
||||||
_ = wxBoxSizer:add(ButtSz, Affirm, zxw:flags(wide)),
|
|
||||||
_ = wxBoxSizer:add(Sizer, PassSz, zxw:flags(base)),
|
|
||||||
_ = wxBoxSizer:add(Sizer, ButtSz, zxw:flags(wide)),
|
|
||||||
ok = wxDialog:setSizer(Dialog, Sizer),
|
|
||||||
ok = wxBoxSizer:layout(Sizer),
|
|
||||||
ok = wxDialog:setSize(Dialog, {500, 130}),
|
|
||||||
ok = wxDialog:center(Dialog),
|
|
||||||
ok = wxStyledTextCtrl:setFocus(PassTx),
|
|
||||||
case wxDialog:showModal(Dialog) of
|
|
||||||
?wxID_OK ->
|
|
||||||
case wxTextCtrl:getValue(PassTx) of
|
|
||||||
"" ->
|
|
||||||
ok = wxDialog:destroy(Dialog),
|
|
||||||
ensure_shown(Frame);
|
|
||||||
Phrase ->
|
|
||||||
ok = wxDialog:destroy(Dialog),
|
|
||||||
case gd_con:open_wallet(Path, Phrase) of
|
case gd_con:open_wallet(Path, Phrase) of
|
||||||
ok ->
|
ok -> do_close(State);
|
||||||
do_close(State);
|
Error -> trouble(Error)
|
||||||
Error ->
|
|
||||||
ok = ensure_shown(Frame),
|
|
||||||
trouble(Error)
|
|
||||||
end
|
|
||||||
end;
|
end;
|
||||||
?wxID_CANCEL ->
|
cancel ->
|
||||||
ok = wxDialog:destroy(Dialog),
|
ok
|
||||||
ensure_shown(Frame)
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
@@ -538,51 +508,15 @@ do_import2(_, "", _, _) ->
|
|||||||
abort;
|
abort;
|
||||||
do_import2(Dir, File, J, Frame) ->
|
do_import2(Dir, File, J, Frame) ->
|
||||||
Path = filename:join(Dir, File),
|
Path = filename:join(Dir, File),
|
||||||
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("Import Wallet")),
|
Title = J("Import Wallet"),
|
||||||
Sizer = wxBoxSizer:new(?wxVERTICAL),
|
NameL = J("Wallet Name"),
|
||||||
|
PassL = J("Passphrase (leave blank if none)"),
|
||||||
NameSz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("Name")}]),
|
OK_L = J("OK"),
|
||||||
NameTx = wxTextCtrl:new(Dialog, ?wxID_ANY),
|
CancelL = J("Cancel"),
|
||||||
_ = wxSizer:add(NameSz, NameTx, zxw:flags(wide)),
|
case gd_m_wallet_importer:show(Frame, Title, NameL, PassL, OK_L, CancelL) of
|
||||||
PassSz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("Passphrase")}]),
|
{ok, Name, Pass} -> gd_con:import_wallet(Name, Path, Pass);
|
||||||
PassTx = wxTextCtrl:new(Dialog, ?wxID_ANY),
|
cancel -> abort
|
||||||
_ = wxSizer:add(PassSz, PassTx, zxw:flags(wide)),
|
end.
|
||||||
|
|
||||||
ButtSz = wxBoxSizer:new(?wxHORIZONTAL),
|
|
||||||
Affirm = wxButton:new(Dialog, ?wxID_OK),
|
|
||||||
Cancel = wxButton:new(Dialog, ?wxID_CANCEL),
|
|
||||||
_ = wxBoxSizer:add(ButtSz, Affirm, zxw:flags(wide)),
|
|
||||||
_ = wxBoxSizer:add(ButtSz, Cancel, zxw:flags(wide)),
|
|
||||||
|
|
||||||
_ = wxSizer:add(Sizer, NameSz, zxw:flags(base)),
|
|
||||||
_ = wxSizer:add(Sizer, PassSz, zxw:flags(base)),
|
|
||||||
_ = wxSizer:add(Sizer, ButtSz, zxw:flags(wide)),
|
|
||||||
|
|
||||||
ok = wxDialog:setSizer(Dialog, Sizer),
|
|
||||||
ok = wxBoxSizer:layout(Sizer),
|
|
||||||
ok = wxFrame:setSize(Dialog, {500, 200}),
|
|
||||||
ok = wxFrame:center(Dialog),
|
|
||||||
ok = wxStyledTextCtrl:setFocus(NameTx),
|
|
||||||
|
|
||||||
Result =
|
|
||||||
case wxDialog:showModal(Dialog) of
|
|
||||||
?wxID_OK ->
|
|
||||||
Name =
|
|
||||||
case wxTextCtrl:getValue(NameTx) of
|
|
||||||
"" -> Path;
|
|
||||||
N -> N
|
|
||||||
end,
|
|
||||||
Pass =
|
|
||||||
case wxTextCtrl:getValue(PassTx) of
|
|
||||||
"" -> none;
|
|
||||||
P -> P
|
|
||||||
end,
|
|
||||||
gd_con:import_wallet(Name, Path, Pass);
|
|
||||||
?wxID_CANCEL ->
|
|
||||||
abort
|
|
||||||
end,
|
|
||||||
ok = wxDialog:destroy(Dialog),
|
|
||||||
Result.
|
|
||||||
|
|
||||||
|
|
||||||
do_drop(State = #s{picker = Picker}) ->
|
do_drop(State = #s{picker = Picker}) ->
|
||||||
|
|||||||
@@ -4,8 +4,9 @@
|
|||||||
{prefix,"gd"}.
|
{prefix,"gd"}.
|
||||||
{author,"Craig Everett"}.
|
{author,"Craig Everett"}.
|
||||||
{desc,"A desktop client for the Gajumaru network of blockchain networks"}.
|
{desc,"A desktop client for the Gajumaru network of blockchain networks"}.
|
||||||
{package_id,{"otpr","gajudesk",{0,7,0}}}.
|
{package_id,{"otpr","gajudesk",{0,9,0}}}.
|
||||||
{deps,[{"otpr","hakuzaru",{0,6,1}},
|
{deps,[{"otpr","hakuzaru",{0,9,1}},
|
||||||
|
{"otpr","zxwidgets",{1,1,0}},
|
||||||
{"otpr","eblake2",{1,0,1}},
|
{"otpr","eblake2",{1,0,1}},
|
||||||
{"otpr","base58",{0,1,1}},
|
{"otpr","base58",{0,1,1}},
|
||||||
{"otpr","gmserialization",{0,1,3}},
|
{"otpr","gmserialization",{0,1,3}},
|
||||||
@@ -13,8 +14,7 @@
|
|||||||
{"otpr","gmbytecode",{3,4,1}},
|
{"otpr","gmbytecode",{3,4,1}},
|
||||||
{"otpr","lom",{1,0,0}},
|
{"otpr","lom",{1,0,0}},
|
||||||
{"otpr","zj",{1,1,0}},
|
{"otpr","zj",{1,1,0}},
|
||||||
{"otpr","ec_utils",{1,0,0}},
|
{"otpr","ec_utils",{1,0,0}}]}.
|
||||||
{"otpr","zxwidgets",{1,0,1}}]}.
|
|
||||||
{key_name,none}.
|
{key_name,none}.
|
||||||
{a_email,"craigeverett@qpq.swiss"}.
|
{a_email,"craigeverett@qpq.swiss"}.
|
||||||
{c_email,"info@qpq.swiss"}.
|
{c_email,"info@qpq.swiss"}.
|
||||||
|
|||||||
Reference in New Issue
Block a user