Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 57c5253513 | |||
| 547cbc319d | |||
| 8335e326bd | |||
| 7a65a8c50f | |||
| c3888d1c2f | |||
| cf4a3856b9 |
+46
-42
@@ -85,35 +85,39 @@ 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"),
|
% case is_sus(Challenge) of
|
||||||
From ! {Ref, {ok, Challenge}},
|
% false ->
|
||||||
authenticate(State);
|
% tell(info, "Not sus"),
|
||||||
true ->
|
% From ! {Ref, {ok, Challenge}},
|
||||||
tell(info, "Sus"),
|
% authenticate(State);
|
||||||
From ! {Ref, {error, "Challenge was sus."}},
|
% true ->
|
||||||
retire(State, normal)
|
% tell(info, "Sus"),
|
||||||
end;
|
% 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 +126,32 @@ handshake(State = #s{socket = Socket}, Ref, From) ->
|
|||||||
retire(State, normal, "Handshake timed out")
|
retire(State, normal, "Handshake timed out")
|
||||||
end.
|
end.
|
||||||
|
|
||||||
is_sus(Challenge) ->
|
%is_sus(Challenge) ->
|
||||||
case string:split(Challenge, "_", all) of
|
% case string:split(Challenge, "_", all) of
|
||||||
[<<"GajuExpress-Challenge">>, <<"TS-", TS/binary>>, Rand] -> is_sus2(TS, Rand);
|
% [<<"GajuExpress-Challenge">>, <<"TS-", TS/binary>>, Rand] -> is_sus2(TS, Rand);
|
||||||
_ -> true
|
% _ -> true
|
||||||
end.
|
% end.
|
||||||
|
%
|
||||||
is_sus2(TS, Rand) ->
|
%is_sus2(TS, Rand) ->
|
||||||
case decode_challenge(TS, Rand) of
|
% case decode_challenge(TS, Rand) of
|
||||||
{ok, Seconds} -> is_sus3(Seconds);
|
% {ok, Seconds} -> is_sus3(Seconds);
|
||||||
error -> true
|
% error -> true
|
||||||
end.
|
% end.
|
||||||
|
%
|
||||||
is_sus3(Seconds) ->
|
%is_sus3(Seconds) ->
|
||||||
Now = erlang:system_time(seconds),
|
% Now = erlang:system_time(seconds),
|
||||||
FiveMins = 5 * 60,
|
% FiveMins = 5 * 60,
|
||||||
abs(Seconds - Now) > FiveMins.
|
% abs(Seconds - Now) > FiveMins.
|
||||||
|
%
|
||||||
decode_challenge(TS, Rand) ->
|
%decode_challenge(TS, Rand) ->
|
||||||
try
|
% try
|
||||||
Seconds = binary_to_integer(TS),
|
% Seconds = binary_to_integer(TS),
|
||||||
true = is_binary(base64:decode(Rand)),
|
% true = is_binary(base64:decode(Rand)),
|
||||||
{ok, Seconds}
|
% {ok, Seconds}
|
||||||
catch
|
% catch
|
||||||
error:_ ->
|
% error:_ ->
|
||||||
error
|
% error
|
||||||
end.
|
% end.
|
||||||
|
|
||||||
|
|
||||||
authenticate(State = #s{socket = Socket}) ->
|
authenticate(State = #s{socket = Socket}) ->
|
||||||
|
|||||||
+9
-3
@@ -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
@@ -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}) ->
|
||||||
|
|||||||
@@ -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}]),
|
||||||
|
|||||||
Reference in New Issue
Block a user