Compare commits

7 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
4 changed files with 109 additions and 96 deletions
+47 -40
View File
@@ -85,35 +85,30 @@ disconnected(State) ->
end.
do_connect(State = #s{host = Host = {Addr, Port}, id = ID}, Ref, From) ->
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 1 RECVR:", ID/binary>>),
handshake(NextState, Ref, From);
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) ->
handshake(State = #s{socket = Socket}, Ref, From, TempKey) ->
ok = active_once(State),
receive
{tcp, Socket, <<"GajuExpress 1 RECVR:", Challenge/binary>>} ->
tell(info, "Got challenge ~p", [Challenge]),
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;
{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")
@@ -122,32 +117,44 @@ handshake(State = #s{socket = Socket}, Ref, From) ->
retire(State, normal, "Handshake timed out")
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.
% 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_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.
%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}) ->
+9 -3
View File
@@ -447,7 +447,8 @@ do_dry_run(State = #s{action = #w{wx = ActionB}}, ConID, TX) ->
end.
dry_run2(State = #s{funret = ReturnType,
dry_run2(State = #s{j = J,
funret = ReturnType,
return = #w{wx = ReturnT},
copy = #w{wx = CopyB},
tx_data = TXData,
@@ -458,16 +459,21 @@ dry_run2(State = #s{funret = ReturnType,
case TXInfo of
#{"results" :=
[#{"call_obj" :=
#{"return_type" := "revert",
#{"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_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,
+52 -52
View File
@@ -470,76 +470,76 @@ should_enable_quote(#s{dest = DestT, path = PathP}) ->
length(DestKey) > 0 andalso length(Path) > 0.
do_ul(State = #s{quote = none, rider = none}) ->
check_quote(State);
%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_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_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_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_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_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) ->
%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).
%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) ->
%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.
%string_to_int(S) ->
% try
% {ok, list_to_integer(S)}
% catch
% error:bad_arg -> error
% end.
do_close(#s{frame = Frame, prefs = Prefs}) ->
+1 -1
View File
@@ -128,7 +128,7 @@ init({Prefs, Manifest}) ->
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}]),