First-run wallet creatorator (v0.7.0) #24

Merged
zxq9 merged 9 commits from wizard into master 2025-08-07 15:47:06 +09:00
13 changed files with 64 additions and 44 deletions
Showing only changes of commit 45ab1a35a4 - Show all commits

View File

@ -3,7 +3,7 @@
{registered,[]}, {registered,[]},
{included_applications,[]}, {included_applications,[]},
{applications,[stdlib,kernel,sasl,ssl]}, {applications,[stdlib,kernel,sasl,ssl]},
{vsn,"0.6.6"}, {vsn,"0.7.0"},
{modules,[gajudesk,gd_con,gd_grids,gd_gui,gd_jt, {modules,[gajudesk,gd_con,gd_grids,gd_gui,gd_jt,
gd_sophia_editor,gd_sup,gd_v,gd_v_devman,gd_v_netman, gd_sophia_editor,gd_sup,gd_v,gd_v_devman,gd_v_netman,
gd_v_wallman]}, gd_v_wallman]},

View File

@ -3,7 +3,7 @@
%%% @end %%% @end
-module(gajudesk). -module(gajudesk).
-vsn("0.6.6"). -vsn("0.7.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>").

View File

@ -3,7 +3,7 @@
%%% @end %%% @end
-module(gd_con). -module(gd_con).
-vsn("0.6.6"). -vsn("0.7.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").
@ -66,12 +66,13 @@ show_ui(Name) ->
gen_server:cast(?MODULE, {show_ui, Name}). gen_server:cast(?MODULE, {show_ui, Name}).
-spec open_wallet(Path, Phrase) -> ok -spec open_wallet(Path, Phrase) -> Result
when Path :: file:filename(), when Path :: file:filename(),
Phrase :: string(). Phrase :: string(),
Result :: ok | {error, Reason :: term()}.
open_wallet(Path, Phrase) -> open_wallet(Path, Phrase) ->
gen_server:cast(?MODULE, {open_wallet, Path, Phrase}). gen_server:call(?MODULE, {open_wallet, Path, Phrase}).
-spec close_wallet() -> ok. -spec close_wallet() -> ok.
@ -217,7 +218,7 @@ deploy(Build, Params, InitArgs) ->
Size :: 256, Size :: 256,
Name :: string(), Name :: string(),
Seed :: string(), Seed :: string(),
Encoding :: utf8 | base64 | base58, Encoding :: utf8 | base64 | base58 | none,
Transform :: {Algo, Yugeness}, Transform :: {Algo, Yugeness},
Algo :: sha3 | sha2 | x_or | pbkdf2, Algo :: sha3 | sha2 | x_or | pbkdf2,
Yugeness :: rand | non_neg_integer(). Yugeness :: rand | non_neg_integer().
@ -365,6 +366,9 @@ 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({open_wallet, Path, Phrase}, _, State) ->
{Response, NewState} = do_open_wallet(Path, Phrase, State),
{reply, Response, NewState};
handle_call(network, _, State) -> handle_call(network, _, State) ->
Response = do_network(State), Response = do_network(State),
{reply, Response, State}; {reply, Response, State};
@ -390,9 +394,6 @@ handle_call(Unexpected, From, State) ->
handle_cast({show_ui, Name}, State) -> handle_cast({show_ui, Name}, State) ->
NewState = do_show_ui(Name, State), NewState = do_show_ui(Name, State),
{noreply, NewState}; {noreply, NewState};
handle_cast({open_wallet, Path, Phrase}, State) ->
NewState = do_open_wallet(Path, Phrase, State),
{noreply, NewState};
handle_cast(close_wallet, State) -> handle_cast(close_wallet, State) ->
NextState = do_close_wallet(State), NextState = do_close_wallet(State),
ok = gd_gui:show([]), ok = gd_gui:show([]),
@ -489,7 +490,6 @@ handle_info(Unexpected, State) ->
handle_down(Mon, PID, Info, State = #s{tasks = Tasks}) -> handle_down(Mon, PID, Info, State = #s{tasks = Tasks}) ->
tell("Handling down"),
case lists:keytake(Mon, #ui.mon, Tasks) of case lists:keytake(Mon, #ui.mon, Tasks) of
{value, #ui{}, NewTasks} -> {value, #ui{}, NewTasks} ->
State#s{tasks = NewTasks}; State#s{tasks = NewTasks};
@ -1024,19 +1024,12 @@ do_open_wallet(Path, Phrase, State) ->
{ok, ChainID} -> gd_gui:chain(ChainID, Node); {ok, ChainID} -> gd_gui:chain(ChainID, Node);
Error -> gd_gui:trouble(Error) Error -> gd_gui:trouble(Error)
end, end,
State#s{pass = Pass, wallet = Recovered}; {ok, State#s{pass = Pass, wallet = Recovered}};
Error -> Error ->
ok = gd_gui:trouble(Error), {Error, State}
% FIXME: This is chaotically stupid.
tell("Sending myself the show_ui message"),
self() ! {show_ui, gd_v_wallman},
State
end. end.
default_wallet() ->
default_wallet(testnet).
default_wallet(mainnet) -> default_wallet(mainnet) ->
Node = #node{ip = "groot.mainnet.gajumaru.io"}, Node = #node{ip = "groot.mainnet.gajumaru.io"},
Groot = #chain{id = <<"groot.mainnet">>, Groot = #chain{id = <<"groot.mainnet">>,

View File

@ -37,7 +37,7 @@
%%% @end %%% @end
-module(gd_grids). -module(gd_grids).
-vsn("0.6.6"). -vsn("0.7.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").

View File

@ -3,7 +3,7 @@
%%% @end %%% @end
-module(gd_gui). -module(gd_gui).
-vsn("0.6.6"). -vsn("0.7.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").

View File

@ -15,7 +15,7 @@
%%% translation library is retained). %%% translation library is retained).
-module(gd_jt). -module(gd_jt).
-vsn("0.6.6"). -vsn("0.7.0").
-export([read_translations/1, j/2, oneshot_j/2]). -export([read_translations/1, j/2, oneshot_j/2]).

View File

@ -1,5 +1,5 @@
-module(gd_sophia_editor). -module(gd_sophia_editor).
-vsn("0.6.6"). -vsn("0.7.0").
-export([new/1, update/2, -export([new/1, update/2,
get_text/1, set_text/2]). get_text/1, set_text/2]).

View File

@ -12,7 +12,7 @@
%%% @end %%% @end
-module(gd_sup). -module(gd_sup).
-vsn("0.6.6"). -vsn("0.7.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>").

View File

@ -1,5 +1,5 @@
-module(gd_v). -module(gd_v).
-vsn("0.6.6"). -vsn("0.7.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").

View File

@ -1,5 +1,5 @@
-module(gd_v_devman). -module(gd_v_devman).
-vsn("0.6.6"). -vsn("0.7.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").

View File

@ -1,5 +1,5 @@
-module(gd_v_netman). -module(gd_v_netman).
-vsn("0.6.6"). -vsn("0.7.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").

View File

@ -1,5 +1,5 @@
-module(gd_v_wallman). -module(gd_v_wallman).
-vsn("0.6.6"). -vsn("0.7.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").
@ -7,7 +7,7 @@
-behavior(wx_object). -behavior(wx_object).
%-behavior(gd_v). %-behavior(gd_v).
-include_lib("wx/include/wx.hrl"). -include_lib("wx/include/wx.hrl").
-export([to_front/1]). -export([to_front/1, trouble/1]).
-export([show/2]). -export([show/2]).
-export([start_link/1]). -export([start_link/1]).
-export([init/1, terminate/2, code_change/3, -export([init/1, terminate/2, code_change/3,
@ -42,6 +42,13 @@ to_front(Win) ->
wx_object:cast(Win, to_front). wx_object:cast(Win, to_front).
-spec trouble(Info) -> ok
when Info :: term().
trouble(Info) ->
wx_object:cast(?MODULE, {trouble, Info}).
-spec show(Win, Manifest) -> ok -spec show(Win, Manifest) -> ok
when Win :: wx:xw_object(), when Win :: wx:xw_object(),
Manifest :: [#wr{}]. Manifest :: [#wr{}].
@ -140,6 +147,9 @@ handle_cast(to_front, State = #s{frame = Frame}) ->
ok = ensure_shown(Frame), ok = ensure_shown(Frame),
ok = wxFrame:raise(Frame), ok = wxFrame:raise(Frame),
{noreply, State}; {noreply, State};
handle_cast({trouble, Info}, State) ->
ok = handle_troubling(State, Info),
{noreply, State};
handle_cast({show, Manifest}, State) -> handle_cast({show, Manifest}, State) ->
NewState = do_show(Manifest, State), NewState = do_show(Manifest, State),
{noreply, NewState}; {noreply, NewState};
@ -191,13 +201,17 @@ handle_event(#wx{event = #wxCommand{type = command_button_clicked},
end, end,
{noreply, NewState}; {noreply, NewState};
handle_event(#wx{event = #wxClose{}}, State = #s{wiz = {_, _}}) -> handle_event(#wx{event = #wxClose{}}, State = #s{wiz = {_, _}}) ->
ok = close_wiz(State), NewState = close_wiz(State),
{noreply, State}; {noreply, NewState};
handle_event(Event, State) -> handle_event(Event, State) ->
ok = tell(info, "Unexpected event ~tp State: ~tp~n", [Event, State]), ok = tell(info, "Unexpected event ~tp State: ~tp~n", [Event, State]),
{noreply, State}. {noreply, State}.
handle_troubling(#s{frame = Frame}, Info) ->
zxw:show_message(Frame, Info).
code_change(_, State, _) -> code_change(_, State, _) ->
{ok, State}. {ok, State}.
@ -236,8 +250,7 @@ do_close(#s{frame = Frame, prefs = Prefs}) ->
end, end,
NewPrefs = maps:put(geometry, Geometry, Prefs), NewPrefs = maps:put(geometry, Geometry, Prefs),
ok = gd_con:save(?MODULE, NewPrefs), ok = gd_con:save(?MODULE, NewPrefs),
ok = wxWindow:destroy(Frame), ok = wxWindow:destroy(Frame).
exit(normal).
handle_button(Name, State) -> handle_button(Name, State) ->
@ -249,9 +262,15 @@ do_open(State = #s{wallets = []}) ->
State; State;
do_open(State = #s{wallets = [#wr{pass = true, path = Path}]}) -> do_open(State = #s{wallets = [#wr{pass = true, path = Path}]}) ->
do_open3(Path, State); do_open3(Path, State);
do_open(State = #s{wallets = [#wr{pass = false, path = Path}]}) -> do_open(State = #s{wallets = [#wr{pass = false, path = Path}], frame = Frame}) ->
ok = gd_con:open_wallet(Path, none), ok =
ok = do_close(State), case gd_con:open_wallet(Path, none) of
ok ->
do_close(State);
Error ->
ok = ensure_shown(Frame),
trouble(Error)
end,
State; State;
do_open(State = #s{picker = Picker}) -> do_open(State = #s{picker = Picker}) ->
case wxListBox:getSelection(Picker) of case wxListBox:getSelection(Picker) of
@ -295,8 +314,14 @@ do_open3(Path, State = #s{frame = Frame, j = J}) ->
State; State;
Phrase -> Phrase ->
ok = wxDialog:destroy(Dialog), ok = wxDialog:destroy(Dialog),
ok = gd_con:open_wallet(Path, Phrase), ok =
ok = do_close(State), case gd_con:open_wallet(Path, Phrase) of
ok ->
do_close(State);
Error ->
ok = ensure_shown(Frame),
trouble(Error)
end,
State State
end; end;
?wxID_CANCEL -> ?wxID_CANCEL ->
@ -314,8 +339,8 @@ do_wiz(State = #s{wx = WX, lang = Lang, wiz = none}) ->
MainSz = wxBoxSizer:new(?wxVERTICAL), MainSz = wxBoxSizer:new(?wxVERTICAL),
ButtonTemplates = ButtonTemplates =
[{noob, J("Create a default wallet with a new account for me.")}, [{noob, J("I'm new!\nCreate a new account for me.")},
{l33t, J("I know what I'm doing.\nJust show me the wallet manager.")}], {l33t, J("Open the wallet manager.")}],
MakeButton = MakeButton =
fun({Name, Label}) -> fun({Name, Label}) ->
@ -347,6 +372,8 @@ wiz_noob_assist(State = #s{j = J, wiz = {Wiz, _}}) ->
Path = filename:join(DefaultDir, Name ++ ".gaju"), Path = filename:join(DefaultDir, Name ++ ".gaju"),
case do_new2(Path, J, Wiz) of case do_new2(Path, J, Wiz) of
ok -> ok ->
Label = J("Account 1"),
ok = gd_con:make_key({eddsa, ed25519}, 256, Label, <<>>, none, {sha3, 256}),
ok = do_close(State), ok = do_close(State),
State; State;
abort -> abort ->
@ -387,8 +414,8 @@ do_new(State = #s{frame = Frame, j = J, prefs = Prefs}) ->
do_new2(Path, J, Frame) -> do_new2(Path, J, Frame) ->
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("New Wallet"), [{size, {400, 250}}]), Dialog = wxDialog:new(Frame, ?wxID_ANY, J("New Wallet"), [{size, {400, 250}}]),
Sizer = wxBoxSizer:new(?wxVERTICAL), Sizer = wxBoxSizer:new(?wxVERTICAL),
NetworkOptions = [J("Mainnet"), J("Testnet")],
Network = wxRadioBox:new(Dialog, ?wxID_ANY, J("Network"), {0, 0}, {50, 50}, [J("Mainnet"), J("Testnet")]), Network = wxRadioBox:new(Dialog, ?wxID_ANY, J("Network"), {0, 0}, {50, 50}, NetworkOptions),
NameSz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("Name")}]), NameSz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("Name")}]),
NameTx = wxTextCtrl:new(Dialog, ?wxID_ANY), NameTx = wxTextCtrl:new(Dialog, ?wxID_ANY),
_ = wxSizer:add(NameSz, NameTx, zxw:flags(wide)), _ = wxSizer:add(NameSz, NameTx, zxw:flags(wide)),

View File

@ -4,7 +4,7 @@
{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,6,6}}}. {package_id,{"otpr","gajudesk",{0,7,0}}}.
{deps,[{"otpr","hakuzaru",{0,6,1}}, {deps,[{"otpr","hakuzaru",{0,6,1}},
{"otpr","eblake2",{1,0,1}}, {"otpr","eblake2",{1,0,1}},
{"otpr","base58",{0,1,1}}, {"otpr","base58",{0,1,1}},