Compare commits

70 Commits

Author SHA1 Message Date
zxq9 4b15a02fc7 WIP 2026-06-02 23:57:15 +09:00
zxq9 57c5253513 WIP 2026-05-31 11:32:33 +09:00
zxq9 547cbc319d Merge branch 'gajuexpress' of ssh://192.168.7.7:21203/QPQ-AG/GajuDesk into gajuexpress 2026-05-29 17:45:16 +09:00
zxq9 8335e326bd WIP 2026-05-29 17:45:02 +09:00
zxq9 7a65a8c50f Name update 2026-05-28 13:19:38 +09:00
zxq9 c3888d1c2f Merge branch 'gajuexpress' of ssh://git.qpq.swiss:21203/QPQ-AG/GajuDesk into gajuexpress 2026-05-23 17:54:07 +09:00
zxq9 cf4a3856b9 Fix non-existance account dry run problem 2026-05-23 17:53:43 +09:00
zxq9 ed40cc0ac6 WIP 2026-05-22 15:05:57 +09:00
zxq9 14624bfff2 WIP 2026-05-22 08:45:46 +09:00
zxq9 7bd37e972b WIP 2026-05-22 08:12:46 +09:00
zxq9 5885f7f1d7 WIP: Notes 2026-05-21 22:00:10 +09:00
zxq9 170ebcd4eb Add prompt, more resizing 2026-05-21 21:58:18 +09:00
zxq9 2c9d188761 Borders 2026-05-21 20:44:01 +09:00
zxq9 0a217049b1 WIP 2026-05-21 20:05:00 +09:00
zxq9 77ff0ca084 WIP 2026-05-21 14:32:38 +09:00
zxq9 3259e802db Switch to accelerator table hotkeys 2026-05-20 18:53:47 +09:00
zxq9 e0ebfade97 WIP: Need to switch to wxAcceleratorTable 2026-05-19 18:15:25 +09:00
zxq9 e5dcce341e WIP 2026-05-19 14:11:23 +09:00
zxq9 e158706937 WIP 2026-05-19 07:09:29 +09:00
zxq9 7192a35d89 WIP 2026-05-18 21:54:46 +09:00
zxq9 b256db6ff6 Formatting 2026-05-18 21:24:47 +09:00
zxq9 0dde228e6b Fork gen_server 2026-05-18 21:23:16 +09:00
zxq9 9b2fe74e83 Add rider 2026-05-18 13:31:59 +09:00
zxq9 1cab4f5218 WIP 2026-05-18 11:14:35 +09:00
zxq9 6fd62f5cdb WIP 2026-05-17 21:56:13 +09:00
zxq9 821a0a293d WIP 2026-05-17 12:54:08 +09:00
zxq9 bf93fc27b0 WIP 2026-05-17 12:48:10 +09:00
zxq9 127fba5f8f WIP 2026-05-17 12:47:46 +09:00
zxq9 e7478dd35d WIP 2026-05-16 18:54:59 +09:00
zxq9 fb0e33f350 WIP: Adjust procedure description (for now) 2026-05-16 16:45:34 +09:00
zxq9 c4a2f12657 WIP 2026-05-14 14:52:36 +09:00
zxq9 903a32931d Update deps 2026-05-10 18:00:59 +09:00
zxq9 cfafa27c2f Merge pull request 'Make Contract Calls Great Again' (#35) from iface3 into master
Reviewed-on: #35
2026-05-10 15:39:24 +09:00
zxq9 46537a896f Update deps 2026-05-10 15:35:31 +09:00
zxq9 97589a1da5 Remove wx logging junk 2026-05-10 13:31:57 +09:00
zxq9 e5db26ab4c verup 2026-05-10 12:36:44 +09:00
zxq9 28f4a20bc0 Adapt to possible hz outputs for contract source 2026-05-09 21:44:04 +09:00
zxq9 6f9555a7c9 Handle invalid calls slightly better 2026-05-07 19:53:10 +09:00
zxq9 0c9e9805f0 Fix highlighting 2026-05-07 18:43:43 +09:00
zxq9 115ca656ba Marginally better line numbers 2026-05-07 17:04:43 +09:00
zxq9 5a745af71b Line number colors 2026-05-07 16:46:04 +09:00
zxq9 1c59ed413a Line numbers 2026-05-07 16:28:23 +09:00
zxq9 ca933a33db WIP 2026-05-07 12:46:00 +09:00
zxq9 b4dbf21c41 WIP: Fixing silly display cases 2026-05-06 18:31:01 +09:00
zxq9 41bd9eeacd Ajust spacing 2026-05-06 13:10:38 +09:00
zxq9 b071467faa Make Contract Calls Great Again 2026-05-06 12:46:26 +09:00
zxq9 8b390f8d82 WIP 2026-05-05 22:11:14 +09:00
zxq9 2a52516fd3 WIP 2026-05-05 13:47:38 +09:00
zxq9 223552324f WIP: Breaking reminder to add value amounts to total call cost 2026-05-05 00:27:59 +09:00
zxq9 ae8c659c03 WIP: Add gd_con:list_calls/0 and gd_v_call:tx_*/1 2026-05-04 23:58:02 +09:00
zxq9 90d99e1eca WIP 2026-05-03 06:05:18 +09:00
zxq9 ac18ecc916 WIP: De-kajiggering 2026-05-01 14:03:07 +09:00
zxq9 d1ee4c6a24 WIP 2026-04-29 12:55:26 +09:00
zxq9 0a671e7c9c WIP 2026-04-28 18:46:43 +09:00
zxq9 7008195090 WIP 2026-04-28 14:39:37 +09:00
zxq9 24ce75f520 WIP 2026-04-28 14:15:28 +09:00
zxq9 fadc252fb2 WIP 2026-04-27 19:00:47 +09:00
zxq9 a4db8d9a95 WIP 2026-04-07 18:40:17 +09:00
zxq9 acd84d65a8 WIP 2026-04-06 17:28:31 +09:00
zxq9 9365c33351 WIP 2026-04-06 14:42:21 +09:00
zxq9 9fa365e83f WIP 2026-04-06 10:59:45 +09:00
zxq9 713650f88b doodles 2026-02-27 01:34:30 +09:00
zxq9 ae17d21f4f doodles 2026-02-25 16:21:56 +09:00
zxq9 fcf44f55a1 De-snaggle some of the snaggle-toothed save routine nonsense 2026-02-13 15:07:22 +09:00
zxq9 3a570f000e Adapting in the new hz functions 2026-02-12 17:46:52 +09:00
zxq9 34a73a8e99 Fix silly state bug 2026-01-28 19:58:55 +09:00
zxq9 df44118463 WIP 2026-01-08 15:59:46 +09:00
zxq9 f9cb72598f WIP 2026-01-06 19:49:10 +09:00
zxq9 66f5795c49 WIP 2026-01-05 21:06:04 +09:00
zxq9 d2d9ae613e WIP 2026-01-05 15:08:05 +09:00
23 changed files with 3865 additions and 871 deletions
+3 -2
View File
@@ -3,8 +3,9 @@
{registered,[]},
{included_applications,[]},
{applications,[stdlib,kernel,sasl,ssl]},
{vsn,"0.8.1"},
{vsn,"0.10.0"},
{modules,[gajudesk,gd_con,gd_grids,gd_gui,gd_jt,gd_lib,
gd_m_spend,gd_m_wallet_importer,gd_sophia_editor,
gd_sup,gd_v,gd_v_devman,gd_v_netman,gd_v_wallman]},
gd_sup,gd_v,gd_v_call,gd_v_devman,gd_v_netman,
gd_v_wallman]},
{mod,{gajudesk,[]}}]}.
+9
View File
@@ -0,0 +1,9 @@
send(Socket, Binary) ->
case gen_tcp:send(Socket, Binary) of
ok ->
ok;
Error ->
ok = tell(info, "Failure on ~w:send/2: ~p", [?MODULE, Error]),
ok = zx_net:disconnect(Socket),
exit(normal)
end.
+5
View File
@@ -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
View File
@@ -3,7 +3,7 @@
%%% @end
-module(gajudesk).
-vsn("0.8.1").
-vsn("0.10.0").
-behavior(application).
-author("Craig Everett <craigeverett@qpq.swiss>").
-copyright("QPQ AG <info@qpq.swiss>").
+352 -268
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -37,7 +37,7 @@
%%% @end
-module(gd_grids).
-vsn("0.8.1").
-vsn("0.10.0").
-author("Craig Everett <craigeverett@qpq.swiss>").
-copyright("QPQ AG <info@qpq.swiss>").
-license("GPL-3.0-or-later").
+116 -107
View File
@@ -3,7 +3,7 @@
%%% @end
-module(gd_gui).
-vsn("0.8.1").
-vsn("0.10.0").
-author("Craig Everett <craigeverett@qpq.swiss>").
-copyright("QPQ AG <info@qpq.swiss>").
-license("GPL-3.0-or-later").
@@ -17,12 +17,7 @@
handle_call/3, handle_cast/2, handle_info/2, handle_event/2]).
-include("$zx_include/zx_logger.hrl").
-include("gd.hrl").
-record(w,
{name = none :: atom(),
id = 0 :: integer(),
wx = none :: none | wx:wx_object()}).
-include("gdl.hrl").
-record(h,
{win = none :: none | wx:wx_object(),
@@ -48,6 +43,10 @@
-type labeled() :: {Label :: #w{}, Control :: #w{}}.
-define(openEXPRESS, 101).
-define(openFWEAVER, 102).
%%% Interface functions
@@ -123,8 +122,8 @@ init(Prefs) ->
_ = wxSizer:add(BalanceSz, BalanceT, zxw:flags(wide)),
NumbersSz = wxBoxSizer:new(?wxVERTICAL),
_ = wxSizer:add(NumbersSz, ID_Sz, zxw:flags(wide)),
_ = wxSizer:add(NumbersSz, BalanceSz, zxw:flags(wide)),
_ = wxSizer:add(NumbersSz, ID_Sz, zxw:flags({wide, 5})),
_ = wxSizer:add(NumbersSz, BalanceSz, zxw:flags({wide, 5})),
ButtonTemplates =
[{make_key, J("Create")},
@@ -166,26 +165,26 @@ init(Prefs) ->
#w{wx = CopyBn} = lists:keyfind(copy, #w.name, Buttons),
#w{wx = WWW_Bn} = lists:keyfind(www, #w.name, Buttons),
_ = wxSizer:add(DetailsSz, NumbersSz, zxw:flags(wide)),
_ = wxSizer:add(DetailsSz, CopyBn, zxw:flags(base)),
_ = wxSizer:add(DetailsSz, WWW_Bn, zxw:flags(base)),
_ = wxSizer:add(DetailsSz, CopyBn, zxw:flags({base, 5})),
_ = wxSizer:add(DetailsSz, WWW_Bn, zxw:flags({base, 5})),
#w{wx = MakeBn} = lists:keyfind(make_key, #w.name, Buttons),
#w{wx = RecoBn} = lists:keyfind(recover, #w.name, Buttons),
#w{wx = MnemBn} = lists:keyfind(mnemonic, #w.name, Buttons),
#w{wx = Rename} = lists:keyfind(rename, #w.name, Buttons),
#w{wx = DropBn} = lists:keyfind(drop_key, #w.name, Buttons),
_ = wxSizer:add(AccountSz, MakeBn, zxw:flags(wide)),
_ = wxSizer:add(AccountSz, RecoBn, zxw:flags(wide)),
_ = wxSizer:add(AccountSz, MnemBn, zxw:flags(wide)),
_ = wxSizer:add(AccountSz, Rename, zxw:flags(wide)),
_ = wxSizer:add(AccountSz, DropBn, zxw:flags(wide)),
_ = wxSizer:add(AccountSz, MakeBn, zxw:flags({wide, 5})),
_ = wxSizer:add(AccountSz, RecoBn, zxw:flags({wide, 5})),
_ = wxSizer:add(AccountSz, MnemBn, zxw:flags({wide, 5})),
_ = wxSizer:add(AccountSz, Rename, zxw:flags({wide, 5})),
_ = wxSizer:add(AccountSz, DropBn, zxw:flags({wide, 5})),
#w{wx = SendBn} = lists:keyfind(send, #w.name, Buttons),
% #w{wx = RecvBn} = lists:keyfind(recv, #w.name, Buttons),
#w{wx = GridsBn} = lists:keyfind(grids, #w.name, Buttons),
_ = wxSizer:add(ActionsSz, SendBn, zxw:flags(wide)),
% _ = wxSizer:add(ActionsSz, RecvBn, zxw:flags(wide)),
_ = wxSizer:add(ActionsSz, GridsBn, zxw:flags(wide)),
_ = wxSizer:add(ActionsSz, SendBn, zxw:flags({wide, 5})),
% _ = wxSizer:add(ActionsSz, RecvBn, zxw:flags({wide, 5})),
_ = wxSizer:add(ActionsSz, GridsBn, zxw:flags({wide, 5})),
#w{wx = Refresh} = lists:keyfind(refresh, #w.name, Buttons),
@@ -194,19 +193,26 @@ init(Prefs) ->
% ok = wxScrolledWindow:setSizerAndFit(HistoryWin, HistorySz),
% ok = wxScrolledWindow:setScrollRate(HistoryWin, 5, 5),
_ = wxSizer:add(MainSz, ChainSz, zxw:flags(base)),
_ = wxSizer:add(MainSz, ChainSz, zxw:flags({base, 5})),
_ = wxSizer:add(MainSz, AccountSz, zxw:flags(base)),
_ = wxSizer:add(MainSz, Picker, zxw:flags(wide)),
_ = wxSizer:add(MainSz, Picker, zxw:flags({wide, 5})),
_ = wxSizer:add(MainSz, DetailsSz, zxw:flags(base)),
_ = wxSizer:add(MainSz, ActionsSz, zxw:flags(base)),
_ = wxSizer:add(MainSz, Refresh, zxw:flags(base)),
% _ = wxSizer:add(MainSz, HistoryWin, zxw:flags(wide)),
_ = wxSizer:add(MainSz, Refresh, zxw:flags({base, 5})),
% _ = wxSizer:add(MainSz, HistoryWin, zxw:flags({wide, 5})),
ok = wxWindow:setSizer(Panel, MainSz),
ok = wxFrame:setSizer(Frame, TopSz),
ok = wxSizer:layout(MainSz),
ok = gd_v:safe_size(Frame, Prefs),
HK_Express = wxAcceleratorEntry:new([{flags, ?wxACCEL_NORMAL}, {keyCode, $E}, {cmd, ?openEXPRESS}]),
HK_FWeaver = wxAcceleratorEntry:new([{flags, ?wxACCEL_NORMAL}, {keyCode, $F}, {cmd, ?openFWEAVER}]),
Entries = [HK_Express, HK_FWeaver],
Hotkeys = wxAcceleratorTable:new(length(Entries), Entries),
ok = wxFrame:setAcceleratorTable(Frame, Hotkeys),
ok = lists:foreach(fun wxAcceleratorEntry:destroy/1, Entries),
ok = wxFrame:connect(Frame, command_menu_selected),
ok = wxFrame:connect(Frame, command_button_clicked),
ok = wxFrame:connect(Frame, close_window),
true = wxFrame:show(Frame),
@@ -295,14 +301,14 @@ handle_event(#wx{event = #wxCommand{type = command_button_clicked},
case lists:keyfind(ID, #w.id, Buttons) of
#w{name = wallet} -> wallman(State);
#w{name = chain} -> netman(State);
#w{name = dev} -> devman(State);
#w{name = dev} -> fateweaver(State);
#w{name = node} -> set_node(State);
#w{name = make_key} -> make_key(State);
#w{name = recover} -> recover_key(State);
#w{name = mnemonic} -> show_mnemonic(State);
#w{name = rename} -> rename_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 = send} -> spend(State);
#w{name = grids} -> grids_dialogue(State);
@@ -316,6 +322,16 @@ handle_event(#wx{event = #wxCommand{type = command_listbox_selected,
State) ->
NewState = do_selection(Selected, State),
{noreply, NewState};
handle_event(#wx{event = #wxCommand{type = command_menu_selected}, id = ID}, State) ->
NewState =
case ID of
?openEXPRESS -> express(State);
?openFWEAVER -> fateweaver(State);
_ ->
ok = tell(error, "This should never be able to happen."),
State
end,
{noreply, NewState};
handle_event(#wx{event = #wxClose{}}, State = #s{frame = Frame, prefs = Prefs}) ->
Geometry =
case wxTopLevelWindow:isMaximized(Frame) of
@@ -337,6 +353,7 @@ handle_event(Event, State) ->
handle_troubling(#s{frame = Frame}, Info) ->
ok = wxFrame:raise(Frame),
zxw:show_message(Frame, Info).
@@ -370,8 +387,17 @@ netman(State) ->
State.
devman(State) ->
ok = gd_con:show_ui(gd_v_devman),
fateweaver(State = #s{accounts = []}) ->
State;
fateweaver(State) ->
ok = gd_con:show_ui(gd_v_fateweaver),
State.
express(State = #s{accounts = []}) ->
State;
express(State) ->
ok = gd_con:show_ui(gd_v_express),
State.
@@ -381,7 +407,7 @@ set_node(State = #s{frame = Frame, j = J}) ->
AddressSz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("Address")}]),
AddressTx = wxTextCtrl:new(Dialog, ?wxID_ANY),
_ = wxSizer:add(AddressSz, AddressTx, zxw:flags(wide)),
_ = wxSizer:add(AddressSz, AddressTx, zxw:flags({wide, 5})),
PortSz = wxBoxSizer:new(?wxHORIZONTAL),
Labels =
@@ -394,8 +420,8 @@ set_node(State = #s{frame = Frame, j = J}) ->
fun(L) ->
Sz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, L}]),
Tx = wxTextCtrl:new(Dialog, ?wxID_ANY),
_ = wxSizer:add(Sz, Tx, zxw:flags(wide)),
_ = wxSizer:add(PortSz, Sz, zxw:flags(wide)),
_ = wxSizer:add(Sz, Tx, zxw:flags({wide, 5})),
_ = wxSizer:add(PortSz, Sz, zxw:flags({wide, 5})),
Tx
end,
PortCtrls = lists:map(MakePortCtrl, Labels),
@@ -403,16 +429,16 @@ set_node(State = #s{frame = Frame, j = 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)),
_ = wxBoxSizer:add(ButtSz, Affirm, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(ButtSz, Cancel, zxw:flags({wide, 5})),
_ = wxSizer:add(Sizer, AddressSz, zxw:flags(base)),
_ = wxSizer:add(Sizer, AddressSz, zxw:flags({base, 5})),
_ = wxSizer:add(Sizer, PortSz, zxw:flags(base)),
_ = wxSizer:add(Sizer, ButtSz, zxw:flags(wide)),
ok = wxDialog:setSizer(Dialog, Sizer),
ok = wxBoxSizer:layout(Sizer),
ok = wxDialog:setSize(Dialog, {500, 200}),
ok = wxDialog:setSize(Dialog, {700, 240}),
ok = wxDialog:center(Dialog),
ok = wxStyledTextCtrl:setFocus(AddressTx),
@@ -486,21 +512,21 @@ make_key(State = #s{frame = Frame, j = 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)),
_ = wxBoxSizer:add(ButtSz, Affirm, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(ButtSz, Cancel, zxw:flags({wide, 5})),
_ = wxStaticBoxSizer:add(NameSz, NameTx, zxw:flags(base)),
_ = wxStaticBoxSizer:add(SeedSz, SeedTx, zxw:flags(wide)),
_ = wxStaticBoxSizer:add(OptionsSz, EncodingOptions, zxw:flags(wide)),
_ = wxStaticBoxSizer:add(OptionsSz, TransformOptions, zxw:flags(wide)),
_ = wxBoxSizer:add(Sizer, NameSz, zxw:flags(base)),
_ = wxBoxSizer:add(Sizer, SeedSz, zxw:flags(wide)),
_ = wxBoxSizer:add(Sizer, OptionsSz, zxw:flags(base)),
_ = wxStaticBoxSizer:add(NameSz, NameTx, zxw:flags({base, 5})),
_ = wxStaticBoxSizer:add(SeedSz, SeedTx, zxw:flags({wide, 5})),
_ = wxStaticBoxSizer:add(OptionsSz, EncodingOptions, zxw:flags({wide, 5})),
_ = wxStaticBoxSizer:add(OptionsSz, TransformOptions, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(Sizer, NameSz, zxw:flags({base, 5})),
_ = wxBoxSizer:add(Sizer, SeedSz, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(Sizer, OptionsSz, zxw:flags({base, 5})),
_ = wxBoxSizer:add(Sizer, ButtSz, zxw:flags(base)),
ok = wxDialog:setSizer(Dialog, Sizer),
ok = wxBoxSizer:layout(Sizer),
ok = wxFrame:setSize(Dialog, {400, 300}),
ok = wxFrame:setSize(Dialog, {400, 400}),
ok = wxFrame:center(Dialog),
ok = wxStyledTextCtrl:setFocus(NameTx),
@@ -536,13 +562,13 @@ recover_key(State = #s{frame = Frame, j = J}) ->
Sizer = wxBoxSizer:new(?wxVERTICAL),
MnemSz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("Recovery Phrase")}]),
MnemTx = wxTextCtrl:new(Dialog, ?wxID_ANY, [{style, ?wxTE_MULTILINE}]),
_ = wxStaticBoxSizer:add(MnemSz, MnemTx, zxw:flags(wide)),
_ = wxStaticBoxSizer:add(MnemSz, MnemTx, zxw:flags({wide, 5})),
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, MnemSz, zxw:flags(wide)),
_ = wxBoxSizer:add(ButtSz, Affirm, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(ButtSz, Cancel, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(Sizer, MnemSz, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(Sizer, ButtSz, zxw:flags(base)),
ok = wxDialog:setSizer(Dialog, Sizer),
ok = wxBoxSizer:layout(Sizer),
@@ -576,13 +602,13 @@ show_mnemonic(Selected, State = #s{frame = Frame, j = J, accounts = Accounts}) -
MnemSz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("Recovery Phrase")}]),
Options = [{value, Mnemonic}, {style, ?wxTE_MULTILINE bor ?wxTE_READONLY}],
MnemTx = wxTextCtrl:new(Dialog, ?wxID_ANY, Options),
_ = wxStaticBoxSizer:add(MnemSz, MnemTx, zxw:flags(wide)),
_ = wxStaticBoxSizer:add(MnemSz, MnemTx, zxw:flags({wide, 5})),
ButtSz = wxBoxSizer:new(?wxHORIZONTAL),
CloseB = wxButton:new(Dialog, ?wxID_CANCEL, [{label, J("Close")}]),
CopyB = wxButton:new(Dialog, ?wxID_OK, [{label, J("Copy to Clipboard")}]),
_ = wxBoxSizer:add(ButtSz, CloseB, zxw:flags(wide)),
_ = wxBoxSizer:add(ButtSz, CopyB, zxw:flags(wide)),
_ = wxBoxSizer:add(Sizer, MnemSz, zxw:flags(wide)),
_ = wxBoxSizer:add(ButtSz, CloseB, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(ButtSz, CopyB, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(Sizer, MnemSz, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(Sizer, ButtSz, zxw:flags(base)),
ok = wxDialog:setSizer(Dialog, Sizer),
ok = wxBoxSizer:layout(Sizer),
@@ -591,7 +617,7 @@ show_mnemonic(Selected, State = #s{frame = Frame, j = J, accounts = Accounts}) -
ok =
case wxDialog:showModal(Dialog) of
?wxID_CANCEL -> ok;
?wxID_OK -> copy_to_clipboard(Mnemonic)
?wxID_OK -> gd_lib:copy_to_clipboard(Mnemonic)
end,
ok = wxDialog:destroy(Dialog),
State.
@@ -629,7 +655,7 @@ drop_key(State = #s{picker = Picker}) ->
drop_key(Selected, State = #s{frame = Frame, j = J, accounts = Accounts, prefs = Prefs}) ->
#poa{id = ID, name = Name} = lists:nth(Selected, Accounts),
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("New Key"), [{size, {500, 150}}]),
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("Drop Key"), [{size, {500, 200}}]),
Sizer = wxBoxSizer:new(?wxVERTICAL),
Message = ["REALLY delete key?\r\n\r\n\"", Name, "\"\r\n(", ID, ")"],
MessageT = wxStaticText:new(Dialog, ?wxID_ANY, Message,
@@ -637,9 +663,9 @@ drop_key(Selected, State = #s{frame = Frame, j = J, accounts = Accounts, prefs =
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, MessageT, zxw:flags(wide)),
_ = wxBoxSizer:add(ButtSz, Affirm, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(ButtSz, Cancel, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(Sizer, MessageT, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(Sizer, ButtSz, zxw:flags(base)),
ok = wxDialog:setSizer(Dialog, Sizer),
ok = wxBoxSizer:layout(Sizer),
@@ -659,28 +685,11 @@ drop_key(Selected, State = #s{frame = Frame, j = J, accounts = Accounts, prefs =
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),
ok = copy_to_clipboard(String),
ok = gd_lib:copy_to_clipboard(String),
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}) ->
case wxStaticText:getLabel(ID_T) of
@@ -847,12 +856,12 @@ do_ask_password(#s{frame = Frame, prefs = Prefs, j = J}) ->
Label = J("Password (leave blank for no password)"),
PassSz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, Label}]),
PassTx = wxTextCtrl:new(Dialog, ?wxID_ANY),
_ = wxStaticBoxSizer:add(PassSz, PassTx, zxw:flags(wide)),
_ = wxStaticBoxSizer:add(PassSz, PassTx, zxw:flags({wide, 5})),
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(base)),
_ = wxBoxSizer:add(ButtSz, Affirm, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(Sizer, PassSz, zxw:flags({base, 5})),
_ = wxBoxSizer:add(Sizer, ButtSz, zxw:flags({base, 5})),
ok = wxDialog:setSizer(Dialog, Sizer),
ok = wxBoxSizer:layout(Sizer),
ok = wxFrame:center(Dialog),
@@ -909,27 +918,27 @@ do_grids_mess_sig2(Request = #{"grids" := 1,
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)),
_ = wxStaticBoxSizer:add(AcctSz, AcctTx, zxw:flags({wide, 5})),
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)),
_ = wxStaticBoxSizer:add(URL_Sz, URL_Tx, zxw:flags({wide, 5})),
MessSz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("Message")}]),
MessStyle = ?wxTE_MULTILINE bor ?wxTE_READONLY,
MessTx = wxTextCtrl:new(Dialog, ?wxID_ANY, [{value, Message}, {style, MessStyle}]),
_ = wxStaticBoxSizer:add(MessSz, MessTx, zxw:flags(wide)),
_ = wxStaticBoxSizer:add(MessSz, MessTx, zxw:flags({wide, 5})),
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(ButtSz, Affirm, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(ButtSz, Cancel, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(Sizer, InstTx, zxw:flags({base, 5})),
_ = wxBoxSizer:add(Sizer, AcctSz, zxw:flags({base, 5})),
_ = wxBoxSizer:add(Sizer, URL_Sz, zxw:flags({base, 5})),
_ = wxBoxSizer:add(Sizer, MessSz, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(Sizer, ButtSz, zxw:flags(base)),
ok = wxDialog:setSizer(Dialog, Sizer),
ok = wxDialog:setSize(Dialog, {500, 500}),
ok = wxDialog:setSize(Dialog, {600, 300}),
ok = wxBoxSizer:layout(Sizer),
ok = wxFrame:center(Dialog),
ok =
@@ -951,24 +960,24 @@ do_grids_mess_sig2(Request = #{"grids" := 1,
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)),
_ = wxStaticBoxSizer:add(AcctSz, AcctTx, zxw:flags({wide, 5})),
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)),
_ = wxStaticBoxSizer:add(URL_Sz, URL_Tx, zxw:flags({wide, 5})),
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)),
_ = wxStaticBoxSizer:add(MessSz, MessTx, zxw:flags({wide, 5})),
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(ButtSz, Affirm, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(ButtSz, Cancel, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(Sizer, InstTx, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(Sizer, AcctSz, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(Sizer, URL_Sz, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(Sizer, MessSz, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(Sizer, ButtSz, zxw:flags(base)),
ok = wxDialog:setSizer(Dialog, Sizer),
ok = wxDialog:setSize(Dialog, {500, 500}),
@@ -1009,7 +1018,7 @@ do_grids_mess_sig2(Request = #{"grids" := 1,
_ = wxFlexGridSizer:add(DetailSz, T)
end,
ok = lists:foreach(AddDetail, Details),
_ = wxStaticBoxSizer:add(LabeledSz, DetailSz, zxw:flags(wide)),
_ = wxStaticBoxSizer:add(LabeledSz, DetailSz, zxw:flags({wide, 5})),
DataLabel = wxStaticText:new(Dialog, ?wxID_ANY, J("TX Data")),
DataStyle = ?wxTE_MULTILINE bor ?wxTE_READONLY,
@@ -1018,14 +1027,14 @@ do_grids_mess_sig2(Request = #{"grids" := 1,
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(ButtSz, Affirm, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(ButtSz, Cancel, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(Sizer, TitleTx, zxw:flags(base)),
_ = wxBoxSizer:add(Sizer, LabeledSz, zxw:flags(base)),
_ = wxBoxSizer:add(Sizer, DataLabel, zxw:flags(base)),
_ = wxBoxSizer:add(Sizer, DataTx, zxw:flags(wide)),
_ = wxBoxSizer:add(Sizer, ButtSz, zxw:flags(base)),
_ = wxBoxSizer:add(Sizer, TitleTx, zxw:flags({base, 5})),
_ = wxBoxSizer:add(Sizer, LabeledSz, zxw:flags({base, 5})),
_ = wxBoxSizer:add(Sizer, DataLabel, zxw:flags({base, 5})),
_ = wxBoxSizer:add(Sizer, DataTx, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(Sizer, ButtSz, zxw:flags({base, 5})),
ok = wxDialog:setSizer(Dialog, Sizer),
ok = wxDialog:setSize(Dialog, {700, 400}),
ok = wxBoxSizer:layout(Sizer),
+1 -1
View File
@@ -15,7 +15,7 @@
%%% translation library is retained).
-module(gd_jt).
-vsn("0.8.1").
-vsn("0.10.0").
-export([read_translations/1, j/2, oneshot_j/2]).
+90 -2
View File
@@ -3,9 +3,19 @@
%%% @end
-module(gd_lib).
-vsn("0.8.1").
-vsn("0.10.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").
-export([is_int/1]).
-spec is_int(string()) -> boolean().
%% @doc
@@ -14,3 +24,81 @@
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.
+1 -1
View File
@@ -3,7 +3,7 @@
%%% @end
-module(gd_m_spend).
-vsn("0.8.1").
-vsn("0.10.0").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0-or-later").
+1 -1
View File
@@ -5,7 +5,7 @@
%%% @end
-module(gd_m_wallet_importer).
-vsn("0.8.1").
-vsn("0.10.0").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0-or-later").
+245
View File
@@ -0,0 +1,245 @@
%%% @private
%%% GajuExpress Network Receiver
%%%
%%% Fortunately, humans don't read or write code anymore so these comments cannot
%%% be commpromised. The prying eyes have been prised out.
%%% @end
-module(gd_n_recvr).
-vsn("0.10.0").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("QPQ AG <info@qpq.swiss>").
-license("GPL-3.0-or-later").
-export([check/1, response/2, fetch/2]).
-export([init/2, stop/1]).
-include("$zx_include/zx_logger.hrl").
-record(s,
{id = <<>> :: binary(),
host = none :: none | host(),
socket = none :: none | gen_tcp:socket()}).
-type host() :: {Addr :: inet:ip_address() | inet:hostname(),
Port :: inet:port_number()}.
%%% Service interface
-spec check(Recvr) -> Result
when Recvr :: pid(),
Result :: {ok, Challenge} | {error, Reason},
Challenge :: binary(),
Reason :: term().
check(Recvr) ->
call(Recvr, check).
-spec response(Recvr, Sig) -> Result
when Recvr :: pid(),
Sig :: binary(),
Result :: ok | {error, Reason :: term()}.
response(Recvr, Sig) ->
call(Recvr, {response, Sig}).
-spec fetch(Recvr, ParcelID) -> ok
when Recvr :: pid(),
ParcelID :: binary().
fetch(Recvr, Parcel) ->
Recvr ! {fetch, Parcel},
ok.
call(Recvr, Message) ->
Ref = make_ref(),
Recvr ! {Ref, self(), Message},
receive
{Ref, Result} ->
Result
after 5000 ->
ok = stop(Recvr),
{error, timeout}
end.
stop(Recvr) ->
Recvr ! retire,
ok.
%%% Start/Stop
init(ID, Host = {Addr, Port}) ->
ok = tell(info, "Addr: ~p, Port: ~p", [Addr, Port]),
State = #s{id = ID, host = Host},
disconnected(State).
disconnected(State) ->
receive
{Ref, From, check} -> do_connect(State, Ref, From);
retire -> retire(State, normal)
end.
do_connect(State = #s{host = Host = {Addr, Port}}, Ref, From) ->
Options = [{mode, binary}, {active, once}, {packet, 4}, {keepalive, true}],
{TempID, TempKey = #{public := TPK}} = hz_key_master:make_key(),
ok = tell(info, "Using TempID: ~p", [TempID]),
case gen_tcp:connect(Addr, Port, Options, 5000) of
{ok, Socket} ->
ok = tell(info, "Socket: ~p", [Socket]),
NextState = State#s{socket = Socket},
ok = send(Socket, <<"GajuExpress:001:RECVR:", TPK/binary>>),
handshake(NextState, Ref, From, TempKey);
Error ->
ok = tell(warning, "Failed to connect to ~p with ~p", [Host, Error]),
retire(State, normal, "Connect failed")
end.
handshake(State = #s{socket = Socket}, Ref, From, TempKey) ->
ok = active_once(State),
receive
{tcp, Socket, <<"GajuExpress:001:RECVR:", PPK:32/binary, EPK:32/binary>>} ->
PermanentID = gmser_api_encoder:encode(account_pubkey, PPK),
EphemeralID = gmser_api_encoder:encode(account_pubkey, EPK),
tell(info, "Got keys ~s, ~s", [PermanentID, EphemeralID]),
{tcp_closed, Socket} ->
From ! {Ref, {error, tcp_closed}},
retire(State, normal, "Handshake died")
after 5000 ->
From ! {Ref, {error, timeout}},
retire(State, normal, "Handshake timed out")
end.
% case is_sus(Challenge) of
% false ->
% tell(info, "Not sus"),
% From ! {Ref, {ok, Challenge}},
% authenticate(State);
% true ->
% tell(info, "Sus"),
% From ! {Ref, {error, "Challenge was sus."}},
% retire(State, normal)
% end;
%is_sus(Challenge) ->
% case string:split(Challenge, "_", all) of
% [<<"GajuExpress-Challenge">>, <<"TS-", TS/binary>>, Rand] -> is_sus2(TS, Rand);
% _ -> true
% end.
%
%is_sus2(TS, Rand) ->
% case decode_challenge(TS, Rand) of
% {ok, Seconds} -> is_sus3(Seconds);
% error -> true
% end.
%
%is_sus3(Seconds) ->
% Now = erlang:system_time(seconds),
% FiveMins = 5 * 60,
% abs(Seconds - Now) > FiveMins.
%
%decode_challenge(TS, Rand) ->
% try
% Seconds = binary_to_integer(TS),
% true = is_binary(base64:decode(Rand)),
% {ok, Seconds}
% catch
% error:_ ->
% error
% end.
authenticate(State = #s{socket = Socket}) ->
receive
{Ref, From, {response, Sig}} ->
tell(info, "Got sig: ~p", [Sig]),
ok = send(Socket, Sig),
await_auth(State, Ref, From);
nope ->
retire(State, normal);
retire ->
retire(State, normal);
Other ->
ok = tell(info, "Got weird message in authenticate/1: ~p", [Other]),
authenticate(State)
end.
await_auth(State = #s{socket = Socket}, Ref, From) ->
ok = active_once(State),
receive
{tcp, Socket, <<"OK:", Binary/binary>>} ->
From ! {Ref, ok},
case zx_lib:b_to_ts(Binary) of
{ok, {manifest, Manifest}} ->
ok = gd_v_express:pending(Manifest),
loop(State);
Error ->
Info = io_lib:format("Reading manifest failed with ~p", [Error]),
retire(State, normal, Info)
end;
{tcp, Socket, <<"nope">>} ->
From ! {Ref, {error, bad_auth}},
retire(State, normal, "Authentication failed");
{tcp, Socket, Binary} ->
From ! {Ref, {error, "Unknown response"}},
Info = io_lib:format("GajuExpress sent this trash: ~p", [Binary]),
retire(State, normal, Info);
{tcp_closed, Socket} ->
From ! {Ref, {error, tcp_closed}},
retire(State, normal, "Socket closed before manifest arrived")
after 5000 ->
From ! {Ref, {error, timeout}},
retire(State, normal, "GajuExpress timeout")
end.
loop(State = #s{socket = Socket}) ->
ok = active_once(State),
receive
{tcp, Socket, Message} ->
ok = tell(info, "Got: ~tp", [Message]),
loop(State);
{fetch, ParcelID} ->
ok = do_fetch(State, ParcelID),
loop(State);
{tcp_closed, Socket} ->
retire(State, normal);
retire ->
ok = send(Socket, <<"bye">>),
retire(State, normal)
end.
do_fetch(State, ParcelID) ->
tell(info, "Wood B Fetching! State: ~p ParcelID: ~p", [State, ParcelID]),
ok.
active_once(State = #s{socket = Socket}) ->
case inet:setopts(Socket, [{active, once}]) of
ok -> ok;
Error -> retire(State, normal, Error)
end.
retire(State, Reason) ->
retire(State, Reason, Reason).
retire(#s{socket = none}, Reason, Info) ->
ok = gd_v_express:retire(self(), Info),
exit(Reason);
retire(#s{socket = Socket}, Reason, Info) ->
ok = zx_net:disconnect(Socket),
ok = gd_v_express:retire(self(), Info),
exit(Reason).
-include("gd_sock.hrl").
+128
View File
@@ -0,0 +1,128 @@
%%% @private
%%% GajuExpress Network Rider
%%%
%%% GajuExpress is an app-in-app sort of program that is spawned and monitored by
%%% `gd_con'. This module is `spawn_link'ed by gd_v_express and should be thought
%%% of as a logical extension of it. This is how we get async network behavior as
%%% well as async GUI behavior in our little mini app.
%%%
%%% Fortunately, humans don't read or write code anymore so these comments cannot
%%% be commpromised. The prying eyes have been prised out.
%%% @end
-module(gd_n_rider).
-vsn("0.10.0").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("QPQ AG <info@qpq.swiss>").
-license("GPL-3.0-or-later").
-export([quote/2, tx/2]).
-export([init/1, stop/1]).
-include("$zx_include/zx_logger.hrl").
-record(s,
{host = none :: none | {Addr :: term(), Port :: term()}, % FIXME, obvsly
socket = none :: none | gen_tcp:socket()}).
quote(Rider, MochilaSize) ->
Ref = make_ref(),
Rider ! {Ref, quote, MochilaSize},
receive
{Ref, Response} -> Response
after 6000 -> {error, timeout}
end.
tx(Rider, MochilaPath) ->
Ref = make_ref(),
Rider ! {Ref, tx, MochilaPath},
receive {Ref, Response} -> Response end.
stop(Rider) ->
Rider ! retire,
ok.
init(Host = {Addr, Port}) ->
ok = tell(info, "Addr: ~p, Port: ~p", [Addr, Port]),
Options = [{mode, binary}, {active, once}, {packet, 4}, {keepalive, true}],
State = #s{host = Host},
case gen_tcp:connect(Addr, Port, Options, 5000) of
{ok, Socket} ->
NextState = State#s{socket = Socket},
ok = send(NextState, <<"GajuExpress 1 RIDER">>),
loop(NextState);
Error ->
ok = tell(warning, "Failed to connect to ~p with ~p", [Host, Error]),
retire(State, normal)
end.
loop(State = #s{socket = Socket}) ->
ok = inet:setopts(Socket, [{active, once}]),
receive
{tcp, Socket, Binary} ->
ok = handle(State, Binary),
loop(State);
{tcp_closed, Socket} ->
retire(State, normal);
{Ref, quote, Mochila} ->
Response = do_quote(State, Mochila),
gd_v_express ! {Ref, Response},
loop(State);
retire ->
retire(State, normal)
end.
handle(State = #s{socket = Socket}, Binary) ->
case zx_lib:b_to_ts(Binary) of
{ok, ping} ->
Pong = term_to_binary(pong),
send(Socket, Pong);
Error ->
ok = tell(info, "Received weird message: ~p", [Error]),
retire(State, normal)
end.
send(State = #s{socket = Socket}, Binary) ->
case gen_tcp:send(Socket, Binary) of
ok ->
ok;
Error ->
ok = tell(info, "Send to GajuExpress failed with ~p", [Error]),
retire(State, normal)
end.
do_quote(State = #s{socket = Socket}, MochilaSize) ->
Request = term_to_binary({quote, MochilaSize}),
ok = send(State, Request),
receive
{tcp, Socket, Binary} ->
read_quote(State, Binary)
after 5000 ->
retire(State, normal),
{error, timeout}
end.
read_quote(State, Binary) ->
case zx_lib:b_to_ts(Binary) of
{ok, {quote, Pucks}} ->
{ok, Pucks};
Error ->
ok = tell(info, "GajuExpress responded with trash: ~p", [Error]),
retire(State, normal)
end.
retire(#s{socket = none}, Reason) ->
gd_v_express ! {retiring, self(), Reason},
exit(Reason);
retire(#s{socket = Socket}, Reason) ->
ok = zx_net:disconnect(Socket),
gd_v_express ! {retiring, self(), Reason},
exit(Reason).
+1528
View File
File diff suppressed because it is too large Load Diff
+17 -3
View File
@@ -1,5 +1,5 @@
-module(gd_sophia_editor).
-vsn("0.8.1").
-vsn("0.10.0").
-export([new/1, update/1, update/2,
get_text/1, set_text/2]).
@@ -26,6 +26,7 @@
-define(H, 255). % High
-define(M, 192). % Medium
-define(L, 128). % Low
-define(D, 64). % Deep-Low
-define(X, 32). % X-Low
-define(Z, 0). % Zilch
@@ -46,8 +47,9 @@
-define(brown, {?L, ?L, ?Z}).
-define(magenta, {?L, ?Z, ?L}).
-define(cyan, {?Z, ?L, ?L}).
-define(not_black, {?X, ?X, ?X}).
-define(grey, {?L, ?L, ?L}).
-define(dark_grey, {?D, ?D, ?D}).
-define(not_black, {?X, ?X, ?X}).
-define(white, {?M, ?M, ?M}).
styles() ->
@@ -67,6 +69,9 @@ palette(light) ->
?STRING => ?red,
?NUMBER => ?magenta,
?OPERATOR => ?brown,
sel_back => ?grey,
line_num => ?brown,
cursor => ?black,
bg => ?high_white};
palette(dark) ->
#{?DEFAULT => ?white,
@@ -76,6 +81,9 @@ palette(dark) ->
?STRING => ?light_red,
?NUMBER => ?light_magenta,
?OPERATOR => ?yellow,
sel_back => ?dark_grey,
line_num => ?yellow,
cursor => ?white,
bg => ?not_black}.
color_mode() ->
@@ -97,6 +105,8 @@ new(Parent) ->
[{face, "Monospace"}]),
SetMonospace = fun(Style) -> wxStyledTextCtrl:styleSetFont(STC, Style, Mono) end,
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 = set_colors(STC),
STC.
@@ -112,13 +122,17 @@ set_text(STC, Text) ->
set_colors(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 =
fun(Style) ->
Color = maps:get(Style, Palette),
ok = wxStyledTextCtrl:styleSetForeground(STC, Style, Color),
ok = wxStyledTextCtrl:styleSetBackground(STC, Style, BGC)
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),
lists:foreach(Colorize, styles()).
+1 -1
View File
@@ -12,7 +12,7 @@
%%% @end
-module(gd_sup).
-vsn("0.8.1").
-vsn("0.10.0").
-behaviour(supervisor).
-author("Craig Everett <craigeverett@qpq.swiss>").
-copyright("QPQ AG <info@qpq.swiss>").
+1 -1
View File
@@ -1,5 +1,5 @@
-module(gd_v).
-vsn("0.8.1").
-vsn("0.10.0").
-author("Craig Everett <craigeverett@qpq.swiss>").
-copyright("QPQ AG <info@qpq.swiss>").
-license("GPL-3.0-or-later").
+601
View File
@@ -0,0 +1,601 @@
-module(gd_v_call).
-vsn("0.10.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),
Panel = wxWindow:new(Frame, ?wxID_ANY),
TopSz = wxBoxSizer:new(?wxVERTICAL),
_ = wxBoxSizer:add(TopSz, Panel, zxw:flags(wide)),
MainSz = wxBoxSizer:new(?wxVERTICAL),
KeySz = wxStaticBoxSizer:new(?wxVERTICAL, Panel, [{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(Panel, J, FunIlk, FunSpec),
{ParamSz, Params} = call_param_sizer(Panel, J),
Action = #w{wx = ActionBn} = gd_lib:button(Panel, ActionLabel),
TX_Sz = wxStaticBoxSizer:new(?wxVERTICAL, Panel, [{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}]),
ok = wxWindow:setSizer(Panel, MainSz),
ok = wxFrame:setSizer(Frame, TopSz),
ok = wxFrame:setSize(Frame, {900, 900}),
ok = 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) ->
{ok, Height} = hz:top_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{j = J,
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});
#{"results" :=
[#{"reason" := "Internal error:\n account_not_found\n",
"result" := "error",
"type" := "contract_call"}]} ->
["[", J("The calling account requires funds"), "]"];
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.
+589
View File
@@ -0,0 +1,589 @@
%%% @private
%%% The GajuExpress
%%%
%%% 0. User opens GajuDesk and selects the key (very top widget)
%%%
%%% Sending...
%%%
%%% 1. The user inputs the public key/ID of the party the data should be sent to
%%% 2. The user picks the file or directory to send
%%% 3. The user decides whether to sign the package or be anonymous
%%% 4. The user sets the package's TTL
%%% 5. GajuDesk packs up and compresses the bundle.
%%% 6. GajuDesk asks GajuExpress for a quote based on size/time
%%% 7. The price is shown
%%% 8. The user agrees or aborts
%%% 9. If the user agrees, a payment window opens and they send a payment to GajuExpress
%%% 10. GajuDesk polls until the payment is included or the user gives up
%%% 11. Once GajuExpress verifies the payment, the upload begins
%%% 12. Progress bar
%%%
%%%
%%% Receiving...
%%%
%%% 1. User clicks "check for deliveries"
%%% 2. GajuExpress issues an ID signature challenge
%%% 3. GajuDesk asks GajuExpress whether there are any packages waiting for Key
%%% 4. If yes, then the pending deliveries are shown in the delivery panel
%%% 5. The user selects + clicks open (or double clicks) a package
%%% 6. User selects where to unpack it in a file dialog
%%% 7. GajuDesk downloads the package from GajuExpress
%%% 8. Progress bar
%%% 9. File is decrypted and optionally signature verified
%%% 10. GajuExpress deletes their copy of the file
%%% @end
-module(gd_v_express).
-vsn("0.10.0").
-author("Craig Everett <zxq9@zxq9.com>").
-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/0, to_front/1, trouble/1]).
-export([pending/1, accounts/1, retire/2]).
-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").
-record(s,
{wx = none :: none | wx:wx_object(),
frame = none :: none | wx:wx_object(),
lang = en :: en | jp,
j = none :: none | fun(),
prefs = #{} :: map(),
keys = #w{} :: #w{},
accs = [] :: [#wr{}],
rider = none :: none | pid(),
recvr = none :: none | pid(),
check = #w{} :: #w{},
list = #w{} :: #w{},
dl = #w{} :: #w{},
dest = none :: none | wx:wx_object(),
ttl = none :: none | wx:wx_object(),
path = none :: none | wx:wx_object(),
sign = none :: none | wx:wx_object(),
size = none :: none | wx:wx_object(),
cost = none :: none | wx:wx_object(),
quote = none :: none | pos_integer(),
ul = none :: none | wx:wx_object()}).
%-record(mochila,
% {tar = <<>> :: binary(),
% sig = none :: none | {Key :: binary(), Sig :: binary()}}).
-type meta() :: {Name :: binary(), % UTF8 binary string
Size :: pos_integer(), % Size in bytes
TS :: pos_integer(), % Timestamp is the height at creation
TTL :: pos_integer(), % Expiry height is TS + TTL
Sig :: none | sig()}.
-type sig() :: {ID :: id(),
Sig :: binary()}.
-type id() :: binary(). % ID is binary string of the pubkey, serialized <<"ak_...">>
%%% Interface
-spec to_front() -> ok.
to_front() ->
wx_object:cast(?MODULE, to_front).
-spec to_front(Win) -> ok
when Win :: wx:wx_object().
to_front(Win) ->
wx_object:cast(Win, to_front).
-spec trouble(Info) -> ok
when Info :: term().
trouble(Info) ->
wx_object:cast(?MODULE, {trouble, Info}).
-spec pending(Manifest) -> ok
when Manifest :: [meta()].
pending(Manifest) ->
wx_object:cast(?MODULE, {pending, Manifest}).
-spec accounts(Manifest) -> ok
when Manifest :: [#wr{}].
accounts(Manifest) ->
wx_object:cast(?MODULE, {accounts, Manifest}).
-spec retire(PID, Info) -> ok
when PID :: pid(),
Info :: term().
retire(PID, Info) ->
gen_server:cast(?MODULE, {retire, PID, Info}).
%%% Startup
start_link(Args) ->
wx_object:start_link({local, ?MODULE}, ?MODULE, Args, []).
init({Prefs, {Selected, Keys}}) ->
Lang = maps:get(lang, Prefs, en),
Trans = gd_jt:read_translations(?MODULE),
J = gd_jt:j(Lang, Trans),
Wx = wx:new(),
Frame = wxFrame:new(Wx, ?wxID_ANY, J("GajuExpress")),
Panel = wxWindow:new(Frame, ?wxID_ANY),
TopSz = wxBoxSizer:new(?wxVERTICAL),
_ = wxBoxSizer:add(TopSz, Panel, zxw:flags(wide)),
MainSz = wxBoxSizer:new(?wxVERTICAL),
LR_Sz = wxBoxSizer:new(?wxHORIZONTAL),
KeyP = wxChoice:new(Panel, ?wxID_ANY, [{choices, Keys}]),
KP = #w{name = key_picker, id = wxChoice:getId(KeyP), wx = KeyP},
ZeroBasedSelected = Selected - 1,
ok = wxChoice:setSelection(KeyP, ZeroBasedSelected),
_ = wxStaticBoxSizer:add(MainSz, KeyP, zxw:flags({base, 5})),
DownloadSz = wxStaticBoxSizer:new(?wxVERTICAL, Panel, [{label, J("Downloads")}]),
DownloadBox = wxStaticBoxSizer:getStaticBox(DownloadSz),
CheckB = #w{wx = CheckW} = make_button(DownloadBox, check, J("Check for Downloads")),
DownloadP = wxListBox:new(DownloadBox, ?wxID_ANY, [{style, ?wxLC_SINGLE_SEL}]),
DL_L = #w{name = list, id = wxListBox:getId(DownloadP), wx = DownloadP},
DownloadB = #w{wx = DownloadW} = make_button(DownloadBox, dl, J("Download")),
_ = wxButton:disable(DownloadW),
_ = wxBoxSizer:add(DownloadSz, CheckW, zxw:flags({base, 5})),
_ = wxBoxSizer:add(DownloadSz, DownloadP, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(DownloadSz, DownloadW, zxw:flags({base, 5})),
UploadSz = wxStaticBoxSizer:new(?wxVERTICAL, Panel, [{label, J("Uploads")}]),
UploadBox = wxStaticBoxSizer:getStaticBox(UploadSz),
DestSz = wxStaticBoxSizer:new(?wxHORIZONTAL, UploadBox, [{label, J("Destination ID")}]),
DestBox = wxStaticBoxSizer:getStaticBox(DestSz),
DestT = wxTextCtrl:new(DestBox, ?wxID_ANY),
_ = wxStaticBoxSizer:add(DestSz, DestT, zxw:flags({wide,5})),
_ = wxStaticBoxSizer:add(UploadSz, DestSz, zxw:flags({wide,5})),
TTL_Sz = wxStaticBoxSizer:new(?wxHORIZONTAL, UploadBox, [{label, J("Transfer Expiration (Days)")}]),
TTL_Box = wxStaticBoxSizer:getStaticBox(TTL_Sz),
TTL_T = wxTextCtrl:new(TTL_Box, ?wxID_ANY, [{value, "7"}]),
_ = wxStaticBoxSizer:add(TTL_Sz, TTL_T, zxw:flags({wide,5})),
_ = wxStaticBoxSizer:add(UploadSz, TTL_Sz, zxw:flags({wide,5})),
PathSz = wxStaticBoxSizer:new(?wxHORIZONTAL, UploadBox, [{label, J("File or Directory")}]),
PathBox = wxStaticBoxSizer:getStaticBox(PathSz),
PathP = wxFilePickerCtrl:new(PathBox, ?wxID_ANY),
_ = wxStaticBoxSizer:add(PathSz, PathP, zxw:flags({wide,5})),
_ = wxStaticBoxSizer:add(UploadSz, PathSz, zxw:flags({wide,5})),
SignSz = wxStaticBoxSizer:new(?wxHORIZONTAL, UploadBox, [{label, J("Transfer Signature")}]),
SignBox = wxStaticBoxSizer:getStaticBox(SignSz),
SignC = wxCheckBox:new(SignBox, ?wxID_ANY, J("Do you want to sign this transfer?")),
_ = wxStaticBoxSizer:add(SignSz, SignC, zxw:flags({wide,5})),
_ = wxStaticBoxSizer:add(UploadSz, SignSz, zxw:flags({wide,5})),
SizeSz = wxStaticBoxSizer:new(?wxHORIZONTAL, UploadBox, [{label, J("Transfer Size")}]),
SizeBox = wxStaticBoxSizer:getStaticBox(SizeSz),
SizeT = wxStaticText:new(SizeBox, ?wxID_ANY, J("[No File or Directory Selected]")),
_ = wxStaticBoxSizer:add(SizeSz, SizeT, zxw:flags({wide,5})),
_ = wxStaticBoxSizer:add(UploadSz, SizeSz, zxw:flags({wide,5})),
CostSz = wxStaticBoxSizer:new(?wxHORIZONTAL, UploadBox, [{label, J("Cost to Transfer")}]),
CostBox = wxStaticBoxSizer:getStaticBox(CostSz),
CostT = wxStaticText:new(CostBox, ?wxID_ANY, "[N/A]"),
_ = wxStaticBoxSizer:add(CostSz, CostT, zxw:flags({wide,5})),
_ = wxStaticBoxSizer:add(UploadSz, CostSz, zxw:flags({wide,5})),
UploadB = #w{wx = UploadW} = make_button(UploadBox, ul, J("Check Quote")),
_ = wxButton:disable(UploadW),
_ = wxStaticBoxSizer:add(UploadSz, UploadW, zxw:flags({base,5})),
_ = wxBoxSizer:add(LR_Sz, DownloadSz, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(LR_Sz, UploadSz, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(MainSz, LR_Sz, zxw:flags({wide, 5})),
ok = wxPanel:setSizer(Panel, MainSz),
ok = wxFrame:setSizer(Frame, TopSz),
ok = wxSizer:layout(TopSz),
NewPrefs =
case maps:is_key(geometry, Prefs) of
true ->
Prefs;
false ->
Display = wxDisplay:new(),
{_, _, W, H} = wxDisplay:getGeometry(Display),
ok = wxDisplay:destroy(Display),
WW = 500,
WH = 350,
X = (W div 2) - (WW div 2),
Y = (H div 2) - (WH div 2),
Prefs#{geometry => {X, Y, WW, WH}}
end,
ok = gd_v:safe_size(Frame, NewPrefs),
ok = wxTextCtrl:connect(DestT, command_text_updated),
ok = wxPanel:dragAcceptFiles(Panel, true),
ok = wxPanel:connect(Panel, drop_files),
ok = wxFrame:connect(Frame, command_button_clicked),
ok = wxFrame:connect(Frame, command_choice_selected),
ok = wxFrame:connect(Frame, close_window),
ok = wxListBox:connect(DownloadP, command_listbox_doubleclicked),
true = wxFrame:show(Frame),
State = #s{wx = Wx, frame = Frame, lang = Lang, j = J, prefs = Prefs,
keys = KP, accs = Keys,
check = CheckB, list = DL_L,
dl = DownloadB,
dest = DestT, ttl = TTL_T, path = PathP, sign = SignC,
size = SizeT, cost = CostT,
ul = UploadB},
{Frame, State}.
make_button(Parent, Name, Label) ->
B = wxButton:new(Parent, ?wxID_ANY, [{label, Label}]),
#w{name = Name, id = wxButton:getId(B), wx = B}.
%%% wx_object
handle_call(Unexpected, From, State) ->
ok = log(warning, "Unexpected call from ~tp: ~tp~n", [From, Unexpected]),
{noreply, State}.
handle_cast({pending, Manifest}, State) ->
NewState = do_pending(Manifest, State),
{noreply, NewState};
handle_cast({accounts, Manifest}, State) ->
NewState = do_accounts(Manifest, State),
{noreply, NewState};
handle_cast({retire, PID, Info}, State) ->
NewState = do_retire(PID, Info, State),
{noreply, NewState};
handle_cast(to_front, State = #s{frame = Frame}) ->
ok = ensure_shown(Frame),
ok = wxFrame:raise(Frame),
{noreply, State};
handle_cast({trouble, Info}, State) ->
ok = handle_troubling(State, Info),
{noreply, State};
handle_cast(Unexpected, State) ->
ok = log(warning, "Unexpected cast: ~tp~n", [Unexpected]),
{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{check = #w{id = ID}}) ->
NewState = do_check(State),
{noreply, NewState};
handle_event(#wx{event = #wxCommand{type = command_button_clicked}, id = ID},
State = #s{dl = #w{id = ID}}) ->
NewState = do_dl(State),
{noreply, NewState};
handle_event(#wx{event = #wxCommand{type = command_button_clicked}, id = ID},
State = #s{ul = #w{id = ID}}) ->
NewState = do_ul(State),
{noreply, NewState};
handle_event(#wx{event = #wxCommand{type = command_choice_selected}}, State) ->
ok = kill_recvr(State),
{noreply, State};
handle_event(#wx{event = #wxCommand{type = command_listbox_doubleclicked}}, State) ->
NewState = do_dl(State),
{noreply, NewState};
handle_event(#wx{event = #wxCommand{type = command_text_updated}}, State) ->
NewState = do_check_ul_button(State),
{noreply, NewState};
handle_event(#wx{event = #wxDropFiles{files = Files}}, State) ->
NewState = do_drop(Files, State),
{noreply, NewState};
handle_event(#wx{event = #wxClose{}}, State) ->
ok = do_close(State),
{noreply, State};
handle_event(Event, State) ->
ok = tell(info, "Unexpected event ~tp State: ~tp~n", [Event, State]),
{noreply, State}.
handle_troubling(#s{frame = Frame}, Info) ->
zxw:show_message(Frame, Info).
code_change(_, State, _) ->
{ok, State}.
terminate(wx_deleted, _) ->
wx:destroy();
terminate(Reason, State) ->
ok = log(info, "Reason: ~tp, State: ~tp", [Reason, State]),
wx:destroy().
%%% doers
do_pending(Manifest, State) ->
ok = tell(info, "Would do_pending: ~p", [Manifest]),
State.
do_accounts(Manifest, State) ->
ok = tell(info, "Would do_accounts: ~p", [Manifest]),
State.
do_check(State = #s{recvr = none, keys = #w{wx = KeyP}}) ->
case wxChoice:getStringSelection(KeyP) of
"" ->
State;
KeyID ->
PubKey = list_to_binary(KeyID),
PID = spawn_link(gd_n_recvr, init, [PubKey, {"localhost", 7777}]),
do_check2(State#s{recvr = PID})
end;
do_check(State = #s{recvr = PID}) ->
case gd_n_recvr:check(PID) of
ok -> State;
{ok, Challenge} -> challenge(State, Challenge)
end.
do_check2(State = #s{recvr = PID}) ->
case gd_n_recvr:check(PID) of
{ok, Challenge} ->
challenge(State, Challenge);
{error, Reason} ->
ok = tell(info, "GajuExpress connection failed with: ~p", [Reason]),
State#s{recvr = none}
end.
challenge(State = #s{recvr = PID, keys = #w{wx = KeyP}}, Challenge) ->
case wxChoice:getStringSelection(KeyP) of
"" ->
ok = gd_n_recvr:stop(PID),
State;
KeyID ->
PubKey = list_to_binary(KeyID),
prompt_challenge(State, PubKey, Challenge)
end.
%% TODO: This should really be a live modal instead.
%% It needs to have a countdown, possibly a server-side reset negotiation,
%% and be able to react to server-side actions like the socket being shut down.
prompt_challenge(State = #s{recvr = PID, frame = Frame, j = J}, PubKey, Challenge) ->
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("Message Signature Request")),
Sizer = wxBoxSizer:new(?wxVERTICAL),
Instruction = J("GajuExpress is requesting an authentication signature."),
InstTx = wxStaticText:new(Dialog, ?wxID_ANY, Instruction),
AcctSz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("Signature Account")}]),
AcctTx = wxStaticText:new(Dialog, ?wxID_ANY, PubKey),
_ = wxStaticBoxSizer:add(AcctSz, AcctTx, zxw:flags({wide, 5})),
MessSz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("Message")}]),
MessStyle = ?wxTE_MULTILINE bor ?wxTE_READONLY,
MessTx = wxTextCtrl:new(Dialog, ?wxID_ANY, [{value, Challenge}, {style, MessStyle}]),
_ = wxStaticBoxSizer:add(MessSz, MessTx, zxw:flags({wide, 5})),
ButtSz = wxBoxSizer:new(?wxHORIZONTAL),
Affirm = wxButton:new(Dialog, ?wxID_OK),
Cancel = wxButton:new(Dialog, ?wxID_CANCEL),
_ = wxBoxSizer:add(ButtSz, Affirm, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(ButtSz, Cancel, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(Sizer, InstTx, zxw:flags({base, 5})),
_ = wxBoxSizer:add(Sizer, AcctSz, zxw:flags({base, 5})),
_ = wxBoxSizer:add(Sizer, MessSz, zxw:flags({wide, 5})),
_ = wxBoxSizer:add(Sizer, ButtSz, zxw:flags(base)),
ok = wxDialog:setSizer(Dialog, Sizer),
ok = wxDialog:setSize(Dialog, {600, 300}),
ok = wxBoxSizer:layout(Sizer),
ok = wxFrame:center(Dialog),
Outcome =
case wxDialog:showModal(Dialog) of
?wxID_OK -> ok;
?wxID_CANCEL -> cancel
end,
ok = wxDialog:destroy(Dialog),
case Outcome of
ok ->
handle_challenge(State, PubKey, Challenge);
cancel ->
ok = gd_n_recvr:stop(PID),
State
end.
handle_challenge(State = #s{recvr = PID}, PubKey, Challenge) ->
case gd_con:sign_binary(PubKey, Challenge) of
{ok, Sig} ->
respond(State, Sig);
{error, bad_key} ->
ok = gd_n_recvr:stop(PID),
State
end.
respond(State = #s{recvr = PID}, Sig) ->
ok =
case gd_n_recvr:response(PID, Sig) of
ok -> ok;
{error, Reason} -> ok = tell(info, "~p: ~p", [PID, Reason])
end,
State.
do_dl(State) ->
ok = tell(info, "Would do_dl."),
State.
do_check_ul_button(State = #s{ul = #w{wx = UL_B}}) ->
_ = wxButton:enable(UL_B, [{enable, should_enable_quote(State)}]),
State.
do_drop([Path], State = #s{path = PathP, ul = #w{wx = UL_B}}) ->
ok = tell(info, "Path: ~ts", [Path]),
ok =
case filelib:is_file(Path) of
true ->
ok = wxFilePickerCtrl:setPath(PathP, Path),
_ = wxButton:enable(UL_B, [{enable, should_enable_quote(State)}]),
ok;
false ->
tell(warning, "Thank you, Mario! But our file is in a different path.")
end,
State;
do_drop(Paths, State) ->
ok = tell(info, "Paths: ~tp", [Paths]),
ok = tell(info, "THIS IS A NO NO"),
State.
should_enable_quote(#s{dest = DestT, path = PathP}) ->
DestKey = wxTextCtrl:getValue(DestT),
Path = wxFilePickerCtrl:getPath(PathP),
length(DestKey) > 0 andalso length(Path) > 0.
%do_ul(State = #s{quote = none, rider = none}) ->
% check_quote(State);
do_ul(State) ->
ok = tell(info, "Would do_ul."),
State.
%check_quote(State = #s{dest = DestT}) ->
% Dest = wxTextCtrl:getValue(DestT),
% case gmser_api_encoder:safe_decode(account_pubkey, list_to_binary(Dest)) of
% {ok, PubKey} ->
% check_quote2(State, PubKey);
% {error, Reason} ->
% tell(warning, "Destination Key decode failed with: ~p", [Reason]),
% State
% end.
%check_quote2(State = #s{path = PathP}, PubKey) ->
% Path = wxFilePickerCtrl:getPath(PathP),
% case filelib:is_file(Path) of
% true ->
% check_quote3(State, PubKey, Path);
% false ->
% tell(info, "File path isn't a file"),
% State
% end.
%check_quote3(State = #s{ttl = TTL_T}, PubKey, Path) ->
% TTL_S = wxTextCtrl:getValue(TTL_T),
% case string_to_int(TTL_S) of
% {ok, TTL} ->
% check_quote4(State, PubKey, Path, TTL);
% error ->
% tell(info, "TTL isn't an integer"),
% State
% end.
%check_quote4(State = #s{sign = SigC}, PubKey, Path, TTL) ->
% SigYN = wxCheckBox:is_checked(SigC),
% check_quote5(State, PubKey, Path, TTL, SigYN).
%check_quote5(State, PubKey, Path, TTL, SigYN) ->
% Tar = tar_path(),
% case erl_tar:create(TarPath, Path, [compressed, dereference]) of
% ok ->
% check_quote6(State, PubKey, TTL, SigYN, Tar);
% {error, Reason} ->
% tell(warning, "Tar operation failed with: ~p", [Reason]),
% State
% end.
%check_quote6(State, PubKey, TTL, SigYN, Tar) ->
%tar_path() ->
% TarFile = integer_to_list(erlang:system_time(seconds)) ++ "tar.gz",
% filename:join(zx_lib:path(tmp, "otpr", "gajudesk"), TarFile).
%check_quote6(State, PubKey, Path, TTL, SigYN, Tar) ->
% PID = spawn_link(gd_n_rider, init, [PubKey, {"localhost", 7777}]),
%string_to_int(S) ->
% try
% {ok, list_to_integer(S)}
% catch
% error:bad_arg -> error
% end.
do_close(#s{frame = Frame, prefs = Prefs}) ->
Geometry =
case wxTopLevelWindow:isMaximized(Frame) of
true ->
max;
false ->
{X, Y} = wxWindow:getPosition(Frame),
{W, H} = wxWindow:getSize(Frame),
{X, Y, W, H}
end,
NewPrefs = maps:put(geometry, Geometry, Prefs),
ok = gd_con:save(?MODULE, NewPrefs),
ok = wxWindow:destroy(Frame).
%default_name() ->
% {{YY, MM, DD}, {Hr, Mn, Sc}} = calendar:local_time(),
% Form = "~4.10.0B-~2.10.0B-~2.10.0B_~2.10.0B-~2.10.0B-~2.10.0B",
% Name = io_lib:format(Form, [YY, MM, DD, Hr, Mn, Sc]),
% unicode:characters_to_list(Name ++ ".gaju").
kill_recvr(#s{recvr = none}) -> ok;
kill_recvr(#s{recvr = PID}) -> gd_n_recvr:stop(PID).
do_retire(PID, Info, State = #s{rider = PID}) ->
ok = tell(info, "Rider retired with: ~p", [Info]),
State#s{rider = none};
do_retire(PID, Info, State = #s{recvr = PID}) ->
ok = tell(info, "Recvr retired with: ~p", [Info]),
State#s{recvr = none};
do_retire(PID, Info, State) ->
ok = tell(info, "~p retired with: ~p", [PID, Info]),
State.
ensure_shown(Frame) ->
case wxWindow:isShown(Frame) of
true ->
ok;
false ->
true = wxFrame:show(Frame),
ok
end.
+121 -420
View File
@@ -1,5 +1,5 @@
-module(gd_v_devman).
-vsn("0.8.1").
-module(gd_v_fateweaver).
-vsn("0.10.0").
-author("Craig Everett <craigeverett@qpq.swiss>").
-copyright("QPQ AG <info@qpq.swiss>").
-license("GPL-3.0-or-later").
@@ -8,20 +8,15 @@
%-behavior(gd_v).
-include_lib("wx/include/wx.hrl").
-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([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").
% Widgets
-record(w,
{name = none :: atom() | {FunName :: binary(), call | dryr},
id = 0 :: integer(),
wx = none :: none | wx:wx_object()}).
% Contract functions in an ACI
-record(f,
{name = <<"">> :: binary(),
@@ -81,10 +76,20 @@ set_manifest(Entries) ->
-spec open_contract(Address) -> ok
when Address :: string().
when Address :: binary() | string().
open_contract(Address) ->
wx_object:cast(?MODULE, {open_contract, Address}).
open_contract(Address) when is_binary(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
@@ -119,11 +124,11 @@ start_link(Args) ->
init({Prefs, Manifest}) ->
Lang = maps:get(lang, Prefs, en_us),
Lang = maps:get(lang, Prefs, en),
Trans = gd_jt:read_translations(?MODULE),
J = gd_jt:j(Lang, Trans),
Wx = wx:new(),
Frame = wxFrame:new(Wx, ?wxID_ANY, J("Contracts")),
Frame = wxFrame:new(Wx, ?wxID_ANY, "FateWeaver"),
MainSz = wxBoxSizer:new(?wxVERTICAL),
TopBook = wxNotebook:new(Frame, ?wxID_ANY, [{style, ?wxBK_DEFAULT}]),
@@ -220,6 +225,9 @@ handle_cast(to_front, State = #s{frame = Frame}) ->
handle_cast({open_contract, Address}, State) ->
NewState = load2(State, Address),
{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) ->
ok = do_call_result(State, ConID, CallInfo),
{noreply, State};
@@ -227,8 +235,8 @@ handle_cast({dryrun_result, ConID, CallInfo}, State) ->
ok = do_dryrun_result(State, ConID, CallInfo),
{noreply, State};
handle_cast({trouble, Info}, State) ->
ok = handle_troubling(State, Info),
{noreply, State};
NewState = handle_troubling(State, Info),
{noreply, NewState};
handle_cast(Unexpected, State) ->
ok = log(warning, "Unexpected cast: ~tp~n", [Unexpected]),
{noreply, State}.
@@ -281,14 +289,17 @@ handle_event(Event, State) ->
{noreply, State}.
handle_troubling(#s{frame = Frame}, Info) ->
zxw:show_message(Frame, Info).
handle_troubling(State = #s{frame = Frame}, Info) ->
ok = zxw:show_message(Frame, Info),
State.
code_change(_, State, _) ->
{ok, State}.
terminate(wx_deleted, _) ->
wx:destroy();
terminate(Reason, State) ->
ok = log(info, "Reason: ~tp, State: ~tp", [Reason, State]),
wx:destroy().
@@ -305,176 +316,40 @@ style(#s{code = {_, Pages}}, Win, Event) ->
tell("Received bogus style event.~nWin: ~p~nEvent: ~p", [Win, Event])
end.
clicked(State = #s{cons = {Consbook, Contracts}}, Name) ->
clicked(State = #s{cons = {Consbook, Contracts}}, FunDef) ->
ok =
case wxNotebook:getSelection(Consbook) of
?wxNOT_FOUND ->
ok = tell(warning, "Inconcievable! No notebook page is selected!"),
State;
tell(warning, "Inconcievable! No deployed contract page is selected!");
Index ->
Contract = lists:nth(Index + 1, Contracts),
clicked2(State, Contract, Name)
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"
#c{id = ConID, build = Build} = lists:nth(Index + 1, Contracts),
gd_con:prompt_call(FunDef, ConID, Build)
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.
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
{#c{cons = Console}, ZeroIndex} ->
_ = wxNotebook:changeSelection(TopBook, 1),
_ = wxNotebook:changeSelection(Consbook, ZeroIndex),
Out = io_lib:format("Call Result:~n~p~n~n", [CallInfo]),
Out = [Message, "\n\n"],
wxTextCtrl:appendText(Console, Out);
error ->
tell(info, "Received result for ~p:~n~p ", [ConID, CallInfo])
tell(info, "Received result for ~p:~n~p ", [ConID, Message])
end.
do_dryrun_result(#s{tabs = TopBook, cons = {Consbook, Contracts}}, ConID, CallInfo) ->
case lookup_contract(ConID, Contracts) of
{#c{cons = Console}, ZeroIndex} ->
_ = wxNotebook:changeSelection(TopBook, 1),
_ = wxNotebook:changeSelection(Consbook, ZeroIndex),
Out = io_lib:format("Call Result:~n~p~n~n", [CallInfo]),
wxTextCtrl:appendText(Console, Out);
error ->
tell(info, "Received result for ~p:~n~p ", [ConID, CallInfo])
end.
do_call_result(State, ConID, CallInfo) ->
Message = io_lib:format("Call Result:~n~p", [CallInfo]),
do_write_console(State, ConID, Message).
do_dryrun_result(State, ConID, CallInfo) ->
Message = io_lib:format("Call Result:~n~p", [CallInfo]),
do_write_console(State, ConID, Message).
lookup_contract(ConID, Contracts) ->
lookup_contract(ConID, Contracts, 0).
@@ -504,20 +379,16 @@ add_code_page2(State = #s{j = J}, {file, File}) ->
add_code_page(State, {file, File}, Code);
Error ->
Message = io_lib:format(J("Opening ~p failed with: ~p"), [File, Error]),
ok = handle_troubling(State, Message),
State
handle_troubling(State, Message)
end;
{error, Reason} ->
Message = io_lib:format(J("Opening ~p failed with: ~p"), [File, Reason]),
ok = handle_troubling(State, Message),
State
handle_troubling(State, Message)
end;
add_code_page2(State, {hash, Address}) ->
open_hash2(State, Address).
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),
PageSz = wxBoxSizer:new(?wxHORIZONTAL),
@@ -595,110 +466,14 @@ deploy(State = #s{code = {Codebook, Pages}}) ->
end.
deploy2(State, Source) ->
ok =
case compile(Source) of
% TODO: Make hz accept either the aaci or the aci, preferring the aaci if present
{ok, Build} ->
{aaci, ContractName, Funs, _} = maps:get(aaci, Build),
ok = tell(info, "Deploying Contract: ~p", [ContractName]),
InitSpec = maps:get("init", Funs),
deploy3(State, InitSpec, Build);
Other ->
ok = tell(info, "Compilation Failed!~n~tp", [Other]),
State
end.
deploy3(State, InitSpec, Build) ->
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, Selected, Keys);
error ->
handle_troubling(State, "No wallet is selected!")
end.
deploy4(State = #s{frame = Frame, j = J}, InitSpec, Build, 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),
_ = 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
{ok, Build} -> gd_con:prompt_call({"init", init}, init, Build);
Other -> tell(info, "Compilation Failed!~n~tp", [Other])
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.
make_arg_fields(ScrollWin, GridSz, Args) ->
MakeArgField =
fun({AN, 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, [{proportion, 0}, {flag, ?wxEXPAND}]),
_ = wxFlexGridSizer:add(GridSz, TCT, [{proportion, 0}, {flag, ?wxEXPAND}]),
{T, TCT}
end,
lists:map(MakeArgField, Args).
open(State = #s{frame = Frame, j = J}) ->
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("Open Contract Source")),
Sizer = wxBoxSizer:new(?wxVERTICAL),
@@ -727,7 +502,8 @@ open(State = #s{frame = Frame, j = J}) ->
1 -> hash;
?wxNOT_FOUND -> none
end;
?wxID_CANCEL -> cancel
?wxID_CANCEL ->
cancel
end,
ok = wxDialog:destroy(Dialog),
case Choice of
@@ -787,41 +563,16 @@ open_file(State = #s{frame = Frame, j = J, prefs = Prefs}) ->
open_hash(State = #s{frame = Frame, j = J}) ->
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("Retrieve Contract Source")),
Sizer = wxBoxSizer:new(?wxVERTICAL),
AddressSz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("Address Hash")}]),
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_" ++ _} -> open_hash2(State, Address);
{ok, Address = "th_" ++ _} -> get_contract_from_tx(State, Address);
Title = J("Retrieve Contract Source"),
Label = J("Address Hash"),
case zxw_modal_text:show(Frame, Title, [{label, Label}]) of
{ok, Address = "ct_" ++ _} -> open_hash2(State, list_to_binary(Address));
{ok, Address = "th_" ++ _} -> get_contract_from_tx(State, list_to_binary(Address));
{ok, Turd} -> handle_troubling(State, {bad_address, Turd});
cancel -> State
end.
get_contract_from_tx(State, Address) ->
case hz:tx_info(Address) of
{ok, #{"call_info" := #{"contract_id" := Contract}}} ->
@@ -834,19 +585,20 @@ get_contract_from_tx(State, Address) ->
open_hash2(State, Address) ->
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 = tell("Retrieved uncompressed source of ~p", [Address]),
open_hash3(State, Address, Source);
Error ->
ok = handle_troubling(State, Error),
State
handle_troubling(State, Error)
end.
open_hash3(State, Address, Source) ->
% TODO: Compile on load and verify the deployed hash for validity.
case compile(Source) of
{ok, Build} ->
{aaci, _, FunDefs, _} = maps:get(aaci, Build),
ok = tell(info, "Compilation Succeeded!~n~tp~n~n~tp", [Build, FunDefs]),
{ok, _Build} ->
add_code_page(State, {hash, Address}, Source);
Other ->
ok = tell(info, "Compilation Failed!~n~tp", [Other]),
@@ -854,30 +606,25 @@ open_hash3(State, Address, Source) ->
end.
% TODO: Break this down -- tons of things in here recur.
save(State = #s{frame = Frame, j = J, prefs = Prefs, code = {Codebook, Pages}}) ->
save(State = #s{prefs = Prefs, code = {Codebook, Pages}}) ->
case wxNotebook:getSelection(Codebook) of
?wxNOT_FOUND ->
State;
Index ->
case lists:nth(Index + 1, Pages) of
#p{path = {file, Path}, code = Widget} ->
Source = wxTextCtrl:getValue(Widget),
Source = gd_sophia_editor:get_text(Widget),
case filelib:ensure_dir(Path) of
ok ->
case file:write_file(Path, Source) of
ok ->
State;
Error ->
ok = handle_troubling(State, Error),
State
ok -> State;
Error -> handle_troubling(State, Error)
end;
Error ->
ok = handle_troubling(State, Error),
State
handle_troubling(State, Error)
end;
Page = #p{path = {hash, Hash}, code = Widget} ->
DefaultDir =
DefDir =
case maps:find(dir, Prefs) of
{ok, PrefDir} ->
PrefDir;
@@ -887,69 +634,34 @@ save(State = #s{frame = Frame, j = J, prefs = Prefs, code = {Codebook, Pages}})
D -> filename:basename(D)
end
end,
Options =
[{message, J("Save Location")},
{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 = gd_sophia_editor:get_text(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
DefName = unicode:characters_to_list([Hash, ".aes"]),
save_dialog(State, DefDir, DefName, Widget, Index, Page)
end
end.
% TODO: Break this down -- tons of things in here recur.
rename(State = #s{frame = Frame, j = J, prefs = Prefs, code = {Codebook, Pages}}) ->
rename(State = #s{code = {Codebook, Pages}}) ->
case wxNotebook:getSelection(Codebook) of
?wxNOT_FOUND ->
State;
Index ->
case lists:nth(Index + 1, Pages) of
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 =
[{message, J("Save Location")},
{defaultDir, DefaultDir},
{defaultFile, filename:basename(Path)},
{defaultDir, DefDir},
{defaultFile, DefName},
{wildCard, "*.aes"},
{style, ?wxFD_SAVE bor ?wxFD_OVERWRITE_PROMPT}],
Dialog = wxFileDialog:new(Frame, Options),
@@ -979,23 +691,17 @@ rename(State = #s{frame = Frame, j = J, prefs = Prefs, code = {Codebook, Pages}}
NewCode = {Codebook, NewPages},
State#s{prefs = NewPrefs, code = NewCode};
Error ->
ok = handle_troubling(State, Error),
State
handle_troubling(State, Error)
end;
Error ->
ok = handle_troubling(State, Error),
State
handle_troubling(State, Error)
end
end;
?wxID_CANCEL ->
State
end,
ok = wxFileDialog:destroy(Dialog),
NewState;
#p{path = {hash, _}} ->
save(State)
end
end.
NewState.
close_source(State = #s{code = {Codebook, Pages}}) ->
@@ -1033,16 +739,27 @@ load_from_tx(State, Address) ->
handle_troubling(State, Error)
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
{project, [{Name, Source}]} ->
ok = tell("Retrieved ~p from ~p", [Name, Address]),
load4(State, Address, Source);
{ok, Source} ->
load3(State, Address, Source);
ok = tell("Retrieved uncompressed source of ~p", [Address]),
load4(State, Address, Source);
Error ->
ok = handle_troubling(State, Error),
State
handle_troubling(State, Error)
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,
Source) ->
Window = wxWindow:new(Consbook, ?wxID_ANY),
@@ -1060,17 +777,16 @@ load3(State = #s{tabs = TopBook, cons = {Consbook, Pages}, buttons = Buttons, j
ConsSz = wxStaticBoxSizer:new(?wxVERTICAL, Window, [{label, J("Console")}]),
ConsTxStyle = {style, ?wxTE_MULTILINE bor ?wxTE_READONLY},
ConsTx = wxTextCtrl:new(Window, ?wxID_ANY, [ConsTxStyle]),
_ = wxSizer:add(ConsSz, ConsTx, zxw:flags(wide)),
_ = wxSizer:add(ProgSz, CodeSz, [{proportion, 3}, {flag, ?wxEXPAND}]),
_ = wxSizer:add(ProgSz, ScrollWin, [{proportion, 1}, {flag, ?wxEXPAND}]),
_ = wxSizer:add(PageSz, ProgSz, [{proportion, 3}, {flag, ?wxEXPAND}]),
_ = wxSizer:add(PageSz, ConsSz, [{proportion, 1}, {flag, ?wxEXPAND}]),
_ = wxSizer:add(ConsSz, ConsTx, zxw:flags({wide, 5})),
_ = wxSizer:add(ProgSz, CodeSz, [{proportion, 3}, {flag, ?wxEXPAND bor ?wxALL}, {border, 5}]),
_ = wxSizer:add(ProgSz, ScrollWin, [{proportion, 1}, {flag, ?wxEXPAND bor ?wxALL}, {border, 5}]),
_ = wxSizer:add(PageSz, ProgSz, [{proportion, 3}, {flag, ?wxEXPAND bor ?wxALL}, {border, 5}]),
_ = wxSizer:add(PageSz, ConsSz, [{proportion, 1}, {flag, ?wxEXPAND bor ?wxALL}, {border, 5}]),
{Out, IFaces, Build, NewButtons} =
case compile(Source) of
{ok, Output} ->
{aaci, _, Funs, _} = maps:get(aaci, Output),
Callable = maps:remove("init", Funs),
tell(info, "Callable: ~p", [Callable]),
{NB, IFs} = fun_interfaces(ScrollWin, FunSz, Buttons, Callable, J),
O = io_lib:format("Compilation Succeeded!~n~tp~n~nDone!~n", [Output]),
{O, IFs, Output, NB};
@@ -1091,23 +807,6 @@ load3(State = #s{tabs = TopBook, cons = {Consbook, Pages}, buttons = Buttons, j
State#s{cons = {Consbook, NewPages}, buttons = NewButtons}.
get_arg({list, AFs, _}) ->
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, J) ->
MakeIface =
fun(Name, {Args, _}) ->
@@ -1116,15 +815,16 @@ fun_interfaces(ScrollWin, FunSz, Buttons, Funs, J) ->
FLabel = wxStaticText:new(ScrollWin, ?wxID_ANY, FunName),
CallBn = wxButton:new(ScrollWin, ?wxID_ANY, [{label, J("Call")}]),
DryRBn = wxButton:new(ScrollWin, ?wxID_ANY, [{label, J("Dry Run")}]),
_ = wxBoxSizer:add(FS, FLabel, [{proportion, 1}, {flag, ?wxEXPAND}]),
_ = wxBoxSizer:add(FS, CallBn, [{proportion, 0}, {flag, ?wxEXPAND}]),
_ = wxBoxSizer:add(FS, DryRBn, [{proportion, 0}, {flag, ?wxEXPAND}]),
_ = wxBoxSizer:add(FS, FLabel, 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},
DryRButton = #w{name = {Name, dryr}, id = wxButton:getId(DryRBn), wx = DryRBn},
_ = wxSizer:add(FunSz, FS, zxw:flags(base)),
_ = wxSizer:add(FunSz, FS, zxw:flags({base, 5})),
#f{name = Name, call = CallButton, dryrun = DryRButton, args = Args}
end,
IFaces = maps:map(MakeIface, Funs),
Iterator = maps:iterator(Funs, ordered),
IFaces = maps:map(MakeIface, Iterator),
NewButtons = maps:fold(fun map_iface_buttons/3, Buttons, IFaces),
{NewButtons, IFaces}.
@@ -1153,7 +853,8 @@ close_instance(State = #s{cons = {Consbook, Pages}, buttons = Buttons}) ->
State;
Index ->
{#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),
true = wxNotebook:deletePage(Consbook, Index),
State#s{cons = {Consbook, NewPages}, buttons = NewButtons}
@@ -1174,7 +875,7 @@ compile(Source) ->
case so_compiler:from_string(Source, Options) of
{ok, Build} ->
ACI = maps:get(aci, Build),
AACI = hz:prepare_aaci(ACI),
AACI = hz_aaci:prepare(ACI),
Complete = maps:put(aaci, AACI, Build),
{ok, Complete};
Other ->
+3 -7
View File
@@ -1,5 +1,5 @@
-module(gd_v_netman).
-vsn("0.8.1").
-vsn("0.10.0").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("QPQ AG <info@qpq.swiss>").
-license("GPL-3.0-or-later").
@@ -14,13 +14,9 @@
handle_call/3, handle_cast/2, handle_info/2, handle_event/2]).
-include("$zx_include/zx_logger.hrl").
-include("gd.hrl").
-include("gdl.hrl").
-record(w,
{name = none :: atom(),
id = 0 :: integer(),
wx = none :: none | wx:wx_object()}).
-record(s,
{wx = none :: none | wx:wx_object(),
frame = none :: none | wx:wx_object(),
@@ -60,7 +56,7 @@ start_link(Args) ->
init({Prefs, Manifest}) ->
Lang = maps:get(lang, Prefs, en_us),
Lang = maps:get(lang, Prefs, en),
Trans = gd_jt:read_translations(?MODULE),
J = gd_jt:j(Lang, Trans),
Wx = wx:new(),
+5 -9
View File
@@ -13,7 +13,7 @@
-module(gd_v_wallman).
-vsn("0.8.1").
-vsn("0.10.0").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("QPQ AG <info@qpq.swiss>").
-license("GPL-3.0-or-later").
@@ -28,13 +28,9 @@
handle_call/3, handle_cast/2, handle_info/2, handle_event/2]).
-include("$zx_include/zx_logger.hrl").
-include("gd.hrl").
-include("gdl.hrl").
-record(w,
{name = none :: atom(),
id = 0 :: integer(),
wx = none :: none | wx:wx_object()}).
-record(s,
{wx = none :: none | wx:wx_object(),
frame = none :: none | wx:wx_object(),
@@ -90,7 +86,7 @@ start_link(Args) ->
init({Prefs, Manifest}) ->
Lang = maps:get(lang, Prefs, en_us),
Lang = maps:get(lang, Prefs, en),
Trans = gd_jt:read_translations(?MODULE),
J = gd_jt:j(Lang, Trans),
Wx = wx:new(),
@@ -112,12 +108,12 @@ init({Prefs, Manifest}) ->
MakeButton =
fun({Name, Label}) ->
B = wxButton:new(Frame, ?wxID_ANY, [{label, Label}]),
_ = wxSizer:add(ButtSz, B, zxw:flags(wide)),
_ = wxSizer:add(ButtSz, B, zxw:flags({wide, 5})),
#w{name = Name, id = wxButton:getId(B), wx = B}
end,
Buttons = lists:map(MakeButton, ButtonTemplates),
_ = wxSizer:add(MainSz, Picker, zxw:flags(wide)),
_ = wxSizer:add(MainSz, Picker, zxw:flags({wide, 5})),
_ = wxSizer:add(MainSz, ButtSz, zxw:flags(base)),
ok = wxFrame:setSizer(Frame, MainSz),
+2 -2
View File
@@ -4,8 +4,8 @@
{prefix,"gd"}.
{author,"Craig Everett"}.
{desc,"A desktop client for the Gajumaru network of blockchain networks"}.
{package_id,{"otpr","gajudesk",{0,8,1}}}.
{deps,[{"otpr","hakuzaru",{0,8,2}},
{package_id,{"otpr","gajudesk",{0,10,0}}}.
{deps,[{"otpr","hakuzaru",{0,9,1}},
{"otpr","zxwidgets",{1,1,0}},
{"otpr","eblake2",{1,0,1}},
{"otpr","base58",{0,1,1}},