Fix interface somewhat
This commit is contained in:
parent
5b93ebab93
commit
f29389ded7
@ -9,7 +9,7 @@
|
|||||||
-license("GPL-3.0-or-later").
|
-license("GPL-3.0-or-later").
|
||||||
|
|
||||||
-behavior(gen_server).
|
-behavior(gen_server).
|
||||||
-export([start_stop/0]).
|
-export([start_stop/0, gajudesk/0]).
|
||||||
-export([unlock/1, make_key/2, load_key/3, end_setup/0, bin_dir/0]).
|
-export([unlock/1, make_key/2, load_key/3, end_setup/0, bin_dir/0]).
|
||||||
-export([network/0]).
|
-export([network/0]).
|
||||||
-export([start_link/0, stop/0]).
|
-export([start_link/0, stop/0]).
|
||||||
@ -42,6 +42,12 @@ start_stop() ->
|
|||||||
gen_server:cast(?MODULE, start_stop).
|
gen_server:cast(?MODULE, start_stop).
|
||||||
|
|
||||||
|
|
||||||
|
-spec gajudesk() -> ok.
|
||||||
|
|
||||||
|
gajudesk() ->
|
||||||
|
gen_server:cast(?MODULE, gajudesk).
|
||||||
|
|
||||||
|
|
||||||
-spec unlock(Phrase) -> ok
|
-spec unlock(Phrase) -> ok
|
||||||
when Phrase :: string().
|
when Phrase :: string().
|
||||||
|
|
||||||
@ -203,6 +209,9 @@ handle_cast({load_key, Phrase, Mnemonic, Network}, State) ->
|
|||||||
handle_cast(start_stop, State) ->
|
handle_cast(start_stop, State) ->
|
||||||
ok = do_start_stop(State),
|
ok = do_start_stop(State),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
|
handle_cast(gajudesk, State) ->
|
||||||
|
ok = do_gajudesk(),
|
||||||
|
{noreply, State};
|
||||||
handle_cast(stop, State) ->
|
handle_cast(stop, State) ->
|
||||||
ok = do_stop(),
|
ok = do_stop(),
|
||||||
ok = log(info, "Received a 'stop' message."),
|
ok = log(info, "Received a 'stop' message."),
|
||||||
@ -358,17 +367,50 @@ do_start_stop(#s{key = #key{id = PubKey}, network = Network}) ->
|
|||||||
Miner = unicode:characters_to_binary([Fatness, Bits, "-", Type]),
|
Miner = unicode:characters_to_binary([Fatness, Bits, "-", Type]),
|
||||||
Profile =
|
Profile =
|
||||||
[{pubkey, PubKey},
|
[{pubkey, PubKey},
|
||||||
{mining, [#{<<"executable">> => Miner, <<"executable_group">> => <<"gajumine">>}]},
|
{workers, [#{<<"executable">> => Miner, <<"executable_group">> => <<"gajumine">>},
|
||||||
|
#{<<"executable">> => Miner, <<"executable_group">> => <<"gajumine">>},
|
||||||
|
#{<<"executable">> => Miner, <<"executable_group">> => <<"gajumine">>},
|
||||||
|
#{<<"executable">> => Miner, <<"executable_group">> => <<"gajumine">>},
|
||||||
|
#{<<"executable">> => Miner, <<"executable_group">> => <<"gajumine">>},
|
||||||
|
#{<<"executable">> => Miner, <<"executable_group">> => <<"gajumine">>},
|
||||||
|
#{<<"executable">> => Miner, <<"executable_group">> => <<"gajumine">>},
|
||||||
|
#{<<"executable">> => Miner, <<"executable_group">> => <<"gajumine">>}]},
|
||||||
{pool_admin_url, Eureka}],
|
{pool_admin_url, Eureka}],
|
||||||
{ok, Apps} = gmmpc_app:start(Profile),
|
ok = gmc_gui:message({notice, "Starting..."}),
|
||||||
ok = log(info, "Apps started: ~p", [Apps]),
|
ok = gmc_gui:message({notice, ["Miner: ", Miner]}),
|
||||||
|
ok = gmc_gui:message(Profile),
|
||||||
|
{ok, Apps} = gmhc_app:start(Profile),
|
||||||
|
Started = io_lib:format("Apps started: ~p", [Apps]),
|
||||||
|
ok = log(info, Started),
|
||||||
|
ok = gmc_gui:message({notice, Started}),
|
||||||
Events =
|
Events =
|
||||||
[pool_notification,
|
[pool_notification,
|
||||||
{pool_notification, new_generation},
|
|
||||||
connected,
|
connected,
|
||||||
|
puzzle,
|
||||||
|
result,
|
||||||
error,
|
error,
|
||||||
disconnected],
|
disconnected],
|
||||||
lists:foreach(fun gmmpc_events:ensure_subscribed/1, Events).
|
lists:foreach(fun gmhc_events:ensure_subscribed/1, Events).
|
||||||
|
|
||||||
|
|
||||||
|
do_gajudesk() ->
|
||||||
|
ok = tell(info, "Running gajudesk"),
|
||||||
|
PID = spawn(fun run_gajudesk/0),
|
||||||
|
tell(info, "GajuDesk launched at PID: ~p", [PID]).
|
||||||
|
|
||||||
|
run_gajudesk() ->
|
||||||
|
R = "otpr",
|
||||||
|
N = "gajudesk",
|
||||||
|
{ok, V} = zx:latest({R, N}),
|
||||||
|
{ok, PackageString} = zx_lib:package_string({R, N, V}),
|
||||||
|
try
|
||||||
|
case zx:run(PackageString, []) of
|
||||||
|
ok -> ok;
|
||||||
|
Error -> tell(error, "gajudesk died with: ~p", [Error])
|
||||||
|
end
|
||||||
|
catch
|
||||||
|
E:R -> tell(error, "gajudesk died with: ~p", [{E, R}])
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
%%% Utils
|
%%% Utils
|
||||||
|
113
src/gmc_gui.erl
113
src/gmc_gui.erl
@ -30,13 +30,20 @@
|
|||||||
id = none :: none | wx:wx_object(),
|
id = none :: none | wx:wx_object(),
|
||||||
diff = none :: none | wx:wx_object(),
|
diff = none :: none | wx:wx_object(),
|
||||||
perf = none :: none | wx:wx_object(),
|
perf = none :: none | wx:wx_object(),
|
||||||
|
hist = {ts(), 0} :: {LastTS :: integer(), Average :: integer()},
|
||||||
candy = none :: none | wx:wx_object(),
|
candy = none :: none | wx:wx_object(),
|
||||||
|
height = none :: none | wx:wx_object(),
|
||||||
|
block = none :: none | wx:wx_object(),
|
||||||
mess = none :: none | wx:wx_object(),
|
mess = none :: none | wx:wx_object(),
|
||||||
buff = new_buff() :: buff(),
|
buff = new_buff() :: buff(),
|
||||||
buttons = [] :: [#w{}]}).
|
buttons = [] :: [#w{}]}).
|
||||||
|
|
||||||
|
ts() ->
|
||||||
|
erlang:system_time(microsecond).
|
||||||
|
|
||||||
|
|
||||||
new_buff() ->
|
new_buff() ->
|
||||||
{10, 0, 10, 0, []}.
|
{9, 0, 10, 0, []}.
|
||||||
|
|
||||||
-type buff() :: {OMax :: non_neg_integer(),
|
-type buff() :: {OMax :: non_neg_integer(),
|
||||||
OCur :: non_neg_integer(),
|
OCur :: non_neg_integer(),
|
||||||
@ -91,8 +98,8 @@ init(Prefs) ->
|
|||||||
Left = wxBoxSizer:new(?wxVERTICAL),
|
Left = wxBoxSizer:new(?wxVERTICAL),
|
||||||
Right = wxBoxSizer:new(?wxVERTICAL),
|
Right = wxBoxSizer:new(?wxVERTICAL),
|
||||||
|
|
||||||
Labels = [J("ID"), J("Difficulty"), J("Maps/s"), J("Candidate")],
|
Labels = [J("ID"), J("Target"), J("Maps/s"), J("Candidate"), J("Height"), J("BlockHash")],
|
||||||
{Grid, [ID_C, DiffC, PerfC, CandyC]} = display_box(Frame, Labels),
|
{Grid, [ID_C, DiffC, PerfC, CandyC, HeightC, BlockC]} = display_box(Frame, Labels),
|
||||||
|
|
||||||
Style = ?wxDEFAULT bor ?wxTE_MULTILINE bor ?wxTE_READONLY,
|
Style = ?wxDEFAULT bor ?wxTE_MULTILINE bor ?wxTE_READONLY,
|
||||||
MessSz = wxStaticBoxSizer:new(?wxVERTICAL, Frame, [{label, J("Messages")}]),
|
MessSz = wxStaticBoxSizer:new(?wxVERTICAL, Frame, [{label, J("Messages")}]),
|
||||||
@ -126,13 +133,13 @@ init(Prefs) ->
|
|||||||
|
|
||||||
ok = wxFrame:connect(Frame, command_button_clicked),
|
ok = wxFrame:connect(Frame, command_button_clicked),
|
||||||
ok = wxFrame:connect(Frame, close_window),
|
ok = wxFrame:connect(Frame, close_window),
|
||||||
ok = wxFrame:setSize(Frame, {650, 200}),
|
ok = wxFrame:setSize(Frame, {650, 300}),
|
||||||
ok = wxFrame:center(Frame),
|
ok = wxFrame:center(Frame),
|
||||||
true = wxFrame:show(Frame),
|
true = wxFrame:show(Frame),
|
||||||
State =
|
State =
|
||||||
#s{wx = WX, frame = Frame,
|
#s{wx = WX, frame = Frame,
|
||||||
lang = Lang, j = J,
|
lang = Lang, j = J,
|
||||||
id = ID_C, diff = DiffC, perf = PerfC, candy = CandyC,
|
id = ID_C, diff = DiffC, perf = PerfC, candy = CandyC, height = HeightC, block = BlockC,
|
||||||
mess = MessC,
|
mess = MessC,
|
||||||
buttons = Buttons},
|
buttons = Buttons},
|
||||||
{Frame, State}.
|
{Frame, State}.
|
||||||
@ -145,7 +152,7 @@ display_box(Parent, Labels) ->
|
|||||||
fun(S) ->
|
fun(S) ->
|
||||||
L = [S, ":"],
|
L = [S, ":"],
|
||||||
T_L = wxStaticText:new(Parent, ?wxID_ANY, L),
|
T_L = wxStaticText:new(Parent, ?wxID_ANY, L),
|
||||||
T_C = wxStaticText:new(Parent, ?wxID_ANY, "", [{style, ?wxALIGN_RIGHT}]),
|
T_C = wxStaticText:new(Parent, ?wxID_ANY, "---", [{style, ?wxALIGN_LEFT}]),
|
||||||
_ = wxFlexGridSizer:add(Grid, T_L, zxw:flags(base)),
|
_ = wxFlexGridSizer:add(Grid, T_L, zxw:flags(base)),
|
||||||
_ = wxFlexGridSizer:add(Grid, T_C, zxw:flags(wide)),
|
_ = wxFlexGridSizer:add(Grid, T_C, zxw:flags(wide)),
|
||||||
T_C
|
T_C
|
||||||
@ -259,23 +266,76 @@ candidate(Block, #s{candy = Widget}) ->
|
|||||||
wxStaticText:setLabel(Widget, Block).
|
wxStaticText:setLabel(Widget, Block).
|
||||||
|
|
||||||
|
|
||||||
do_message(Terms, State = #s{mess = Mess, buff = Buff}) ->
|
do_message({notice, Notice}, State) ->
|
||||||
Entry = io_lib:format("~tp~n", [Terms]),
|
Entry = io_lib:format("~n~ts", [Notice]),
|
||||||
NewBuff = add_message(Entry, Buff),
|
do_message2(Entry, State);
|
||||||
String = unicode:characters_to_list(element(5, NewBuff)),
|
do_message({puzzle, #{info := {_, Diff, Nonce, _}}}, State = #s{diff = DiffT}) ->
|
||||||
|
DiffS = integer_to_list(Diff),
|
||||||
|
ok = wxStaticText:setLabel(DiffT, DiffS),
|
||||||
|
Entry = io_lib:format("~nTrying Nonce: ~p", [Nonce]),
|
||||||
|
do_message2(Entry, State);
|
||||||
|
do_message({result, #{info := Info}}, State = #s{perf = PerfT, hist = {LastTS, AvgDiff}}) ->
|
||||||
|
Now = ts(),
|
||||||
|
NewAvgDiff = avg20(Now, LastTS, AvgDiff),
|
||||||
|
PerfS = io_lib:format("~w", [1_000_000 / NewAvgDiff]),
|
||||||
|
ok = wxStaticText:setLabel(PerfT, PerfS),
|
||||||
|
NewState = State#s{hist = {Now, NewAvgDiff}},
|
||||||
|
case Info of
|
||||||
|
{error, no_solution} ->
|
||||||
|
NewState;
|
||||||
|
{ok, Cycles} ->
|
||||||
|
Entry = io_lib:format("~nFound! Reporting ~w cycles to leader.", [length(Cycles)]),
|
||||||
|
do_message2(Entry, NewState);
|
||||||
|
Other ->
|
||||||
|
Entry = io_lib:format("~nUnexpected: ~tp", [Other]),
|
||||||
|
do_message2(Entry, NewState)
|
||||||
|
end;
|
||||||
|
do_message({pool_notification, #{info := #{msg := MSG}}}, State = #s{height = HeightT, block = BlockT, candy = CandT}) ->
|
||||||
|
case MSG of
|
||||||
|
#{new_generation := #{height := Height, block_hash := BlockHash}} ->
|
||||||
|
ok = wxStaticText:setLabel(HeightT, integer_to_list(Height)),
|
||||||
|
ok = wxStaticText:setLabel(BlockT, BlockHash),
|
||||||
|
State;
|
||||||
|
#{candidate := #{candidate := Candidate}} ->
|
||||||
|
ok = wxStaticText:setLabel(CandT, Candidate),
|
||||||
|
State;
|
||||||
|
Other ->
|
||||||
|
Entry = io_lib:format("~nUnexpected: ~tp", [Other]),
|
||||||
|
do_message2(Entry, State)
|
||||||
|
end;
|
||||||
|
do_message(Terms, State) ->
|
||||||
|
tell(info, "~p", [Terms]),
|
||||||
|
Entry = io_lib:format("~n~tp", [Terms]),
|
||||||
|
do_message2(Entry, State).
|
||||||
|
|
||||||
|
avg20(Now, LastTS, AvgDiff) ->
|
||||||
|
Diff = Now - LastTS,
|
||||||
|
((AvgDiff * 19) + Diff) div 20.
|
||||||
|
|
||||||
|
do_message2(Entry, State = #s{mess = Mess, buff = Buff}) ->
|
||||||
|
NewBuff =
|
||||||
|
case add_message(Entry, Buff) of
|
||||||
|
{flush, Updated} ->
|
||||||
|
String = unicode:characters_to_list(lists:reverse(element(5, Updated))),
|
||||||
ok = wxTextCtrl:changeValue(Mess, String),
|
ok = wxTextCtrl:changeValue(Mess, String),
|
||||||
|
ok = wxTextCtrl:setInsertionPointEnd(Mess),
|
||||||
|
Updated;
|
||||||
|
{append, Updated} ->
|
||||||
|
ok = wxTextCtrl:appendText(Mess, Entry),
|
||||||
|
Updated
|
||||||
|
end,
|
||||||
State#s{buff = NewBuff}.
|
State#s{buff = NewBuff}.
|
||||||
|
|
||||||
add_message(Entry, {OMax, OMax, IMax, IMax, Buff}) ->
|
add_message(Entry, {OMax, OMax, IMax, IMax, [H | T]}) ->
|
||||||
{OMax, OMax, IMax, 1, [[Entry] | lists:droplast(Buff)]};
|
{flush, {OMax, OMax, IMax, 1, [[Entry] , lists:reverse(H) | lists:droplast(T)]}};
|
||||||
add_message(Entry, {OMax, OMax, IMax, ICur, [H | Buff]}) ->
|
add_message(Entry, {OMax, OMax, IMax, ICur, [H | Buff]}) ->
|
||||||
{OMax, OMax, IMax, ICur + 1, [[Entry | H] | Buff]};
|
{append, {OMax, OMax, IMax, ICur + 1, [[Entry | H] | Buff]}};
|
||||||
add_message(Entry, {OMax, OCur, IMax, IMax, Buff}) ->
|
add_message(Entry, {OMax, OCur, IMax, IMax, [H | T]}) ->
|
||||||
{OMax, OCur + 1, IMax, 1, [[Entry] | Buff]};
|
{append, {OMax, OCur + 1, IMax, 1, [[Entry], lists:reverse(H) | T]}};
|
||||||
add_message(Entry, {OMax, OCur, IMax, ICur, [H | Buff]}) ->
|
add_message(Entry, {OMax, OCur, IMax, ICur, [H | Buff]}) ->
|
||||||
{OMax, OCur, IMax, ICur + 1, [[Entry | H] | Buff]};
|
{append, {OMax, OCur, IMax, ICur + 1, [[Entry | H] | Buff]}};
|
||||||
add_message(Entry, {OMax, 0, IMax, 0, []}) ->
|
add_message(Entry, {OMax, 0, IMax, 0, []}) ->
|
||||||
{OMax, 1, IMax, 1, [[Entry]]}.
|
{append, {OMax, 1, IMax, 1, [[Entry]]}}.
|
||||||
|
|
||||||
|
|
||||||
start_stop(State) ->
|
start_stop(State) ->
|
||||||
@ -284,24 +344,7 @@ start_stop(State) ->
|
|||||||
|
|
||||||
|
|
||||||
gajudesk(State) ->
|
gajudesk(State) ->
|
||||||
ok = tell(info, "Running gajudesk"),
|
ok = gmc_con:gajudesk(),
|
||||||
Launch =
|
|
||||||
fun() ->
|
|
||||||
R = "otpr",
|
|
||||||
N = "gajudesk",
|
|
||||||
{ok, V} = zx:latest({R, N}),
|
|
||||||
{ok, PackageString} = zx_lib:package_string({R, N, V}),
|
|
||||||
try
|
|
||||||
case zx:run(PackageString, []) of
|
|
||||||
ok -> ok;
|
|
||||||
Error -> tell(error, "gajudesk died with: ~p", [Error])
|
|
||||||
end
|
|
||||||
catch
|
|
||||||
E:R -> tell(error, "gajudesk died with: ~p", [{E, R}])
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
PID = spawn(Launch),
|
|
||||||
ok = tell(info, "GajuDesk launched at PID: ~p", [PID]),
|
|
||||||
State.
|
State.
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,10 +5,10 @@
|
|||||||
{desc,"Mining client for the Gajumaru Root"}.
|
{desc,"Mining client for the Gajumaru Root"}.
|
||||||
{author,"Craig Everett"}.
|
{author,"Craig Everett"}.
|
||||||
{package_id,{"qpq","gajumine",{0,1,0}}}.
|
{package_id,{"qpq","gajumine",{0,1,0}}}.
|
||||||
{deps,[{"uwiger","gmmp_client",{0,3,5}},
|
{deps,[{"uwiger","gmhive_worker",{0,1,1}},
|
||||||
{"uwiger","gmminer",{1,1,0}},
|
{"uwiger","gmhive_protocol",{0,1,1}},
|
||||||
|
{"uwiger","gmhive_client",{0,1,3}},
|
||||||
{"qpq","cuckoo_cpu",{0,1,0}},
|
{"qpq","cuckoo_cpu",{0,1,0}},
|
||||||
{"uwiger","gm_mining_pool_protocol",{0,2,0}},
|
|
||||||
{"uwiger","gproc",{1,0,0}},
|
{"uwiger","gproc",{1,0,0}},
|
||||||
{"uwiger","enoise",{1,3,0}},
|
{"uwiger","enoise",{1,3,0}},
|
||||||
{"uwiger","gmcuckoo",{1,1,0}},
|
{"uwiger","gmcuckoo",{1,1,0}},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user