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. 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}], 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 case gen_tcp:connect(Addr, Port, Options, 5000) of
{ok, Socket} -> {ok, Socket} ->
ok = tell(info, "Socket: ~p", [Socket]), ok = tell(info, "Socket: ~p", [Socket]),
NextState = State#s{socket = Socket}, NextState = State#s{socket = Socket},
ok = send(Socket, <<"GajuExpress 1 RECVR:", ID/binary>>), ok = send(Socket, <<"GajuExpress:001:RECVR:", TPK/binary>>),
handshake(NextState, Ref, From); handshake(NextState, Ref, From, TempKey);
Error -> Error ->
ok = tell(warning, "Failed to connect to ~p with ~p", [Host, Error]), ok = tell(warning, "Failed to connect to ~p with ~p", [Host, Error]),
retire(State, normal, "Connect failed") retire(State, normal, "Connect failed")
end. end.
handshake(State = #s{socket = Socket}, Ref, From) ->
handshake(State = #s{socket = Socket}, Ref, From, TempKey) ->
ok = active_once(State), ok = active_once(State),
receive receive
{tcp, Socket, <<"GajuExpress 1 RECVR:", Challenge/binary>>} -> {tcp, Socket, <<"GajuExpress:001:RECVR:", PPK:32/binary, EPK:32/binary>>} ->
tell(info, "Got challenge ~p", [Challenge]), PermanentID = gmser_api_encoder:encode(account_pubkey, PPK),
case is_sus(Challenge) of EphemeralID = gmser_api_encoder:encode(account_pubkey, EPK),
false -> tell(info, "Got keys ~s, ~s", [PermanentID, EphemeralID]),
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_closed, Socket} -> {tcp_closed, Socket} ->
From ! {Ref, {error, tcp_closed}}, From ! {Ref, {error, tcp_closed}},
retire(State, normal, "Handshake died") retire(State, normal, "Handshake died")
@@ -122,32 +117,44 @@ handshake(State = #s{socket = Socket}, Ref, From) ->
retire(State, normal, "Handshake timed out") retire(State, normal, "Handshake timed out")
end. 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 is_sus(Challenge) of
case decode_challenge(TS, Rand) of % false ->
{ok, Seconds} -> is_sus3(Seconds); % tell(info, "Not sus"),
error -> true % From ! {Ref, {ok, Challenge}},
end. % authenticate(State);
% true ->
% tell(info, "Sus"),
% From ! {Ref, {error, "Challenge was sus."}},
% retire(State, normal)
% end;
is_sus3(Seconds) -> %is_sus(Challenge) ->
Now = erlang:system_time(seconds), % case string:split(Challenge, "_", all) of
FiveMins = 5 * 60, % [<<"GajuExpress-Challenge">>, <<"TS-", TS/binary>>, Rand] -> is_sus2(TS, Rand);
abs(Seconds - Now) > FiveMins. % _ -> true
% end.
decode_challenge(TS, Rand) -> %
try %is_sus2(TS, Rand) ->
Seconds = binary_to_integer(TS), % case decode_challenge(TS, Rand) of
true = is_binary(base64:decode(Rand)), % {ok, Seconds} -> is_sus3(Seconds);
{ok, Seconds} % error -> true
catch % end.
error:_ -> %
error %is_sus3(Seconds) ->
end. % 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}) -> 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. end.
dry_run2(State = #s{funret = ReturnType, dry_run2(State = #s{j = J,
funret = ReturnType,
return = #w{wx = ReturnT}, return = #w{wx = ReturnT},
copy = #w{wx = CopyB}, copy = #w{wx = CopyB},
tx_data = TXData, tx_data = TXData,
@@ -458,16 +459,21 @@ dry_run2(State = #s{funret = ReturnType,
case TXInfo of case TXInfo of
#{"results" := #{"results" :=
[#{"call_obj" := [#{"call_obj" :=
#{"return_type" := "revert", #{"return_type" := "revert",
"return_value" := ReturnCB}, "return_value" := ReturnCB},
"result" := "ok","type" := "contract_call"}]} -> "result" := "ok","type" := "contract_call"}]} ->
io_lib:format("Revert: ~ts", [hz:decode_bytearray(ReturnCB, sophia)]); io_lib:format("Revert: ~ts", [hz:decode_bytearray(ReturnCB, sophia)]);
#{"results" := #{"results" :=
[#{"call_obj" := [#{"call_obj" :=
#{"return_type" := "ok", #{"return_type" := "ok",
"return_value" := ReturnCB}, "return_value" := ReturnCB},
"result" := "ok","type" := "contract_call"}]} -> "result" := "ok","type" := "contract_call"}]} ->
hz:decode_bytearray(ReturnCB, {sophia, ReturnType}); 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 -> Other ->
io_lib:format("???: ~tp", [Other]) io_lib:format("???: ~tp", [Other])
end, end,
+52 -52
View File
@@ -470,76 +470,76 @@ should_enable_quote(#s{dest = DestT, path = PathP}) ->
length(DestKey) > 0 andalso length(Path) > 0. length(DestKey) > 0 andalso length(Path) > 0.
do_ul(State = #s{quote = none, rider = none}) -> %do_ul(State = #s{quote = none, rider = none}) ->
check_quote(State); % check_quote(State);
do_ul(State) -> do_ul(State) ->
ok = tell(info, "Would do_ul."), ok = tell(info, "Would do_ul."),
State. State.
check_quote(State = #s{dest = DestT}) -> %check_quote(State = #s{dest = DestT}) ->
Dest = wxTextCtrl:getValue(DestT), % Dest = wxTextCtrl:getValue(DestT),
case gmser_api_encoder:safe_decode(account_pubkey, list_to_binary(Dest)) of % case gmser_api_encoder:safe_decode(account_pubkey, list_to_binary(Dest)) of
{ok, PubKey} -> % {ok, PubKey} ->
check_quote2(State, PubKey); % check_quote2(State, PubKey);
{error, Reason} -> % {error, Reason} ->
tell(warning, "Destination Key decode failed with: ~p", [Reason]), % tell(warning, "Destination Key decode failed with: ~p", [Reason]),
State % State
end. % end.
check_quote2(State = #s{path = PathP}, PubKey) -> %check_quote2(State = #s{path = PathP}, PubKey) ->
Path = wxFilePickerCtrl:getPath(PathP), % Path = wxFilePickerCtrl:getPath(PathP),
case filelib:is_file(Path) of % case filelib:is_file(Path) of
true -> % true ->
check_quote3(State, PubKey, Path); % check_quote3(State, PubKey, Path);
false -> % false ->
tell(info, "File path isn't a file"), % tell(info, "File path isn't a file"),
State % State
end. % end.
check_quote3(State = #s{ttl = TTL_T}, PubKey, Path) -> %check_quote3(State = #s{ttl = TTL_T}, PubKey, Path) ->
TTL_S = wxTextCtrl:getValue(TTL_T), % TTL_S = wxTextCtrl:getValue(TTL_T),
case string_to_int(TTL_S) of % case string_to_int(TTL_S) of
{ok, TTL} -> % {ok, TTL} ->
check_quote4(State, PubKey, Path, TTL); % check_quote4(State, PubKey, Path, TTL);
error -> % error ->
tell(info, "TTL isn't an integer"), % tell(info, "TTL isn't an integer"),
State % State
end. % end.
check_quote4(State = #s{sign = SigC}, PubKey, Path, TTL) -> %check_quote4(State = #s{sign = SigC}, PubKey, Path, TTL) ->
SigYN = wxCheckBox:is_checked(SigC), % SigYN = wxCheckBox:is_checked(SigC),
check_quote5(State, PubKey, Path, TTL, SigYN). % check_quote5(State, PubKey, Path, TTL, SigYN).
check_quote5(State, PubKey, Path, TTL, SigYN) -> %check_quote5(State, PubKey, Path, TTL, SigYN) ->
Tar = tar_path(), % Tar = tar_path(),
case erl_tar:create(TarPath, Path, [compressed, dereference]) of % case erl_tar:create(TarPath, Path, [compressed, dereference]) of
ok -> % ok ->
check_quote6(State, PubKey, TTL, SigYN, Tar); % check_quote6(State, PubKey, TTL, SigYN, Tar);
{error, Reason} -> % {error, Reason} ->
tell(warning, "Tar operation failed with: ~p", [Reason]), % tell(warning, "Tar operation failed with: ~p", [Reason]),
State % State
end. % end.
check_quote6(State, PubKey, TTL, SigYN, Tar) -> %check_quote6(State, PubKey, TTL, SigYN, Tar) ->
tar_path() -> %tar_path() ->
TarFile = integer_to_list(erlang:system_time(seconds)) ++ "tar.gz", % TarFile = integer_to_list(erlang:system_time(seconds)) ++ "tar.gz",
filename:join(zx_lib:path(tmp, "otpr", "gajudesk"), TarFile). % 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}]), % PID = spawn_link(gd_n_rider, init, [PubKey, {"localhost", 7777}]),
string_to_int(S) -> %string_to_int(S) ->
try % try
{ok, list_to_integer(S)} % {ok, list_to_integer(S)}
catch % catch
error:bad_arg -> error % error:bad_arg -> error
end. % end.
do_close(#s{frame = Frame, prefs = Prefs}) -> do_close(#s{frame = Frame, prefs = Prefs}) ->
+1 -1
View File
@@ -128,7 +128,7 @@ init({Prefs, Manifest}) ->
Trans = gd_jt:read_translations(?MODULE), Trans = gd_jt:read_translations(?MODULE),
J = gd_jt:j(Lang, Trans), J = gd_jt:j(Lang, Trans),
Wx = wx:new(), Wx = wx:new(),
Frame = wxFrame:new(Wx, ?wxID_ANY, J("Contracts")), Frame = wxFrame:new(Wx, ?wxID_ANY, "FateWeaver"),
MainSz = wxBoxSizer:new(?wxVERTICAL), MainSz = wxBoxSizer:new(?wxVERTICAL),
TopBook = wxNotebook:new(Frame, ?wxID_ANY, [{style, ?wxBK_DEFAULT}]), TopBook = wxNotebook:new(Frame, ?wxID_ANY, [{style, ?wxBK_DEFAULT}]),