diff --git a/src/gmc_con.erl b/src/gmc_con.erl index c1b96fc..a562d88 100644 --- a/src/gmc_con.erl +++ b/src/gmc_con.erl @@ -196,11 +196,10 @@ handle_info(Unexpected, State) -> {noreply, State}. -gproc_ps_event(Info = {disconnect, #{info := #{reconnecting := false, error := #{code := Code, message := Message}}}}) -> +gproc_ps_event(Info = {disconnected, #{info := #{reconnecting := false, error := #{code := Code, message := Message}}}}) -> ok = log(error, "Error terminal event received. Code: ~p. Message: ~p", [Code, Message]), - Outcome = application:stop(gmhive_client), - ok = log(info, "application:stop(gmhivie_client) -> ~p", [Outcome]), - gmc_gui:message(Info); + ok = gmc_gui:message(Info), + gmc_gui:start_stop(); gproc_ps_event(Info) -> gmc_gui:message(Info). @@ -229,7 +228,7 @@ do_stop() -> do_start_stop(State = #s{toggle = {Last, TS}}) -> Now = erlang:system_time(second), - Clicklimit = Now - 5, + Clicklimit = Now - 1, case TS < Clicklimit of true -> case Last of @@ -286,6 +285,7 @@ do_start(State = #s{acc = PubKey, keys = Keys, network = Network, max_cores = Ma do_stop(State) -> + ok = gmc_gui:message({notice, "Stopping."}), ok = case application:stop(gmhive_client) of ok -> ok; diff --git a/src/gmc_conf.erl b/src/gmc_conf.erl index b092ca6..29521ce 100644 --- a/src/gmc_conf.erl +++ b/src/gmc_conf.erl @@ -213,9 +213,34 @@ done(State = #s{net = Network, acc = AccTx, keys = KeysTx, cores = CoresTx, memo MOAR_IDs = wxTextCtrl:getValue(KeysTx), CoreS = wxTextCtrl:getValue(CoresTx), GigsS = wxTextCtrl:getValue(MemTx), - ok = gmc_con:conf({Net, list_to_binary(AccID), binify_keys(MOAR_IDs), cores(CoreS), bytes(GigsS)}), + ok = gmc_con:conf({Net, list_to_binary(AccID), binify_keys(AccID, MOAR_IDs), cores(CoreS), bytes(GigsS)}), buh_bye(State). + +% NOTE: 32 is space, 12288 is full-width space. +binify_keys(AccID, MOAR) -> + Unwashed = lists:usort([K || K <- string:lexemes(MOAR, [$\r, $\n, 32, 12288, $\t, $,, $;])]), + Scrubbed = lists:delete(AccID, Unwashed), + Keys = + case lists:partition(fun is_key/1, Scrubbed) of + {Cleaned, []} -> + Cleaned; + {Cleaned, Trash} -> + Message = io_lib:format("The following keys are invalid:~n~p", [Trash]), + ok = gmc_gui:message({notice, Message}), + Cleaned + end, + lists:map(fun list_to_binary/1, Keys). + +is_key(Mystery) -> + try + {account_pubkey, _} = gmser_api_encoder:decode(Mystery), + true + catch + _:_ -> false + end. + + cores("") -> 2; cores(CoreS) -> @@ -225,6 +250,7 @@ cores(CoreS) -> _:_ -> 2 end. + bytes("") -> 3550722201; bytes(GigsS) -> @@ -240,11 +266,6 @@ bytes(GigsS) -> end. -% NOTE: 32 is space, 12288 is full-width space. -binify_keys(MOAR) -> - lists:usort([list_to_binary(K) || K <- string:lexemes(MOAR, [$\r, $\n, 32, 12288, $\t, $,, $;])]). - - acc(none) -> ""; acc(AKID) -> AKID. diff --git a/src/gmc_gui.erl b/src/gmc_gui.erl index 771f373..03be542 100644 --- a/src/gmc_gui.erl +++ b/src/gmc_gui.erl @@ -303,22 +303,7 @@ do_message({connected, _}, State) -> Entry = "\nConnected", do_message2(Entry, State); do_message({disconnected, #{info := #{error := #{code := Code, message := Message}}}}, State = #s{}) -> -% -32000 -> % mining_disabled -% -32001 -> % nyi -% -32002 -> % pool_not_found -% -32003 -> % pool_exists -% -32004 -> % unknown_contract -% -32005 -> % invalid_prefix -% -32006 -> % invalid_encoding -% -32007 -> % outdated -% -32008 -> % solution_mismatch -% -32009 -> % invalid_input -% -32010 -> % session_limit -% -32011 -> % accounts_limit -% -32012 -> % duplicate_accounts -% -32601 -> % unknown_method -% -32603 -> % internal error - Format = "~nAn issue has been reported by the Hive Leader.~nError code: ~p '~s'~nStopping.", + Format = "~nAn issue has been reported by the Hive Leader.~nError code: ~p '~s'", Entry = io_lib:format(Format, [Code, Message]), do_message2(Entry, State); do_message({disconnected, _}, State) -> @@ -396,11 +381,12 @@ add_message2(Entry, {OMax, 0, IMax, 0, []}) -> {append, {OMax, 1, IMax, 1, [[Entry]]}}. -start_stop(State = #s{buttons = Buttons, toggle = Last, toggle_t = none}) -> +start_stop(State = #s{buttons = Buttons, toggle = Last, toggle_t = T}) -> + ok = cancel_timer(T), #w{wx = SSB} = lists:keyfind(start_stop, #w.name, Buttons), _ = wxButton:disable(SSB), ok = gmc_con:start_stop(), - Timer = erlang:send_after(5000, self(), toggle), + Timer = erlang:send_after(2000, self(), toggle), Next = case Last of stop -> start; @@ -408,6 +394,9 @@ start_stop(State = #s{buttons = Buttons, toggle = Last, toggle_t = none}) -> end, State#s{toggle = Next, toggle_t = Timer}. +cancel_timer(none) -> ok; +cancel_timer(Time) -> erlang:cancel_timer(Time). + toggle(State = #s{buttons = Buttons, toggle = Next, j = J}) -> #w{wx = SSB} = lists:keyfind(start_stop, #w.name, Buttons), diff --git a/zomp.meta b/zomp.meta index 245d975..70f26a5 100644 --- a/zomp.meta +++ b/zomp.meta @@ -5,9 +5,9 @@ {prefix,"gmc"}. {desc,"Mining client for the Gajumaru Root"}. {package_id,{"qpq","gajumine",{0,4,0}}}. -{deps,[{"otpr","zxwidgets",{1,1,0}}, +{deps,[{"uwiger","gmhive_client",{0,10,0}}, + {"otpr","zxwidgets",{1,1,0}}, {"otpr","hakuzaru",{0,7,0}}, - {"uwiger","gmhive_client",{0,9,3}}, {"uwiger","gmhive_protocol",{0,2,0}}, {"uwiger","gmcuckoo",{1,2,4}}, {"uwiger","gmhive_worker",{0,5,1}},