WIP
This commit is contained in:
parent
54b65413d5
commit
8045853324
@ -26,6 +26,7 @@ start(normal, _Args) ->
|
||||
ok = tell(error, "DANGER! This node is in distributed mode!"),
|
||||
init:stop(1)
|
||||
end,
|
||||
{ok, _} = application:ensure_all_started(ssl),
|
||||
ok = application:ensure_started(hakuzaru),
|
||||
ok = application:ensure_started(zxwidgets),
|
||||
gmc_sup:start_link().
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
-behavior(gen_server).
|
||||
-export([start_stop/0]).
|
||||
-export([unlock/1, make_key/2, load_key/3, end_setup/0, exec_bin_dir/0]).
|
||||
-export([unlock/1, make_key/2, load_key/3, end_setup/0, bin_dir/0]).
|
||||
-export([network/0]).
|
||||
-export([start_link/0, stop/0]).
|
||||
-export([init/1, terminate/2, code_change/3,
|
||||
@ -25,7 +25,7 @@
|
||||
-record(s,
|
||||
{version = 1 :: integer(),
|
||||
window = none :: none | wx:wx_object(),
|
||||
network = none :: none | mainnet | testnet,
|
||||
network = <<"testnet">> :: binary(), % <<"testnet">> | <<"mainnet">>
|
||||
exec_dir = platform_dir() :: file:filename(),
|
||||
key = none :: none | {blob, binary()} | #key{},
|
||||
pass = none :: none | binary()}).
|
||||
@ -117,8 +117,8 @@ init(none) ->
|
||||
NewState = start_gui(#s{key = {blob, Binary}}),
|
||||
ok = gmc_gui:ask_passphrase(),
|
||||
{ok, NewState};
|
||||
{ok, Wallet} ->
|
||||
NewState = start_gui(#s{key = Wallet}),
|
||||
{ok, Wallet, NetworkID} ->
|
||||
NewState = start_gui(#s{key = Wallet, network = NetworkID}),
|
||||
{ok, NewState};
|
||||
error ->
|
||||
Window = gmc_setup:start_link(#{}),
|
||||
@ -140,9 +140,9 @@ open_wallet() ->
|
||||
case file:read_file(Path) of
|
||||
{ok, Binary} ->
|
||||
% TODO: Comply with GD's wallet upgrade system
|
||||
{ok, #wallet{keys = Keys}} = zx_lib:b_to_t(Binary),
|
||||
{ok, #wallet{keys = Keys, nets = [#net{id = NetID}]}} = zx_lib:b_to_t(Binary),
|
||||
Key = lists:keyfind(gm_name(), #key.name, Keys),
|
||||
{ok, Key};
|
||||
{ok, Key, NetID};
|
||||
Error ->
|
||||
Error
|
||||
end;
|
||||
@ -184,7 +184,7 @@ handle_call(end_setup, _, State) ->
|
||||
{reply, ok, NewState};
|
||||
handle_call(network, _, State = #s{network = Network}) ->
|
||||
{reply, Network, State};
|
||||
handle_call(bin_dir, _, State = #s{exec = {BinDir, _}}) ->
|
||||
handle_call(bin_dir, _, State = #s{exec_dir = BinDir}) ->
|
||||
{reply, BinDir, State};
|
||||
handle_call(Unexpected, From, State) ->
|
||||
ok = log(warning, "Unexpected call from ~tp: ~tp~n", [From, Unexpected]),
|
||||
@ -278,13 +278,14 @@ load_key(Phrase, Mnemonic, Network, State) ->
|
||||
|
||||
|
||||
finalize_key(Phrase, ID, Pair, Network, State) ->
|
||||
NetBin = atom_to_binary(Network),
|
||||
Pass =
|
||||
case Phrase =:= "" of
|
||||
false -> pass(unicode:characters_to_binary(Phrase));
|
||||
true -> none
|
||||
end,
|
||||
Key = #key{id = ID} = add_wallet(Pass, ID, Pair, Network),
|
||||
State#s{key = Key, pass = Pass, network = Network}.
|
||||
Key = #key{id = ID} = add_wallet(Pass, ID, Pair, NetBin),
|
||||
State#s{key = Key, pass = Pass, network = NetBin}.
|
||||
|
||||
|
||||
add_wallet(Pass, ID, Pair = #{secret := Secret}, Network) ->
|
||||
@ -297,11 +298,9 @@ add_wallet(Pass, ID, Pair = #{secret := Secret}, Network) ->
|
||||
Wallets = gd_get_prefs(wallets, GDPrefs, []),
|
||||
WalletPath = gajumining_wallet(),
|
||||
Created = #key{name = gm_name(), id = ID, pair = Pair},
|
||||
{Net, ChainID, Node} =
|
||||
case Network of
|
||||
mainnet -> {#net{id = <<"mainnet">>}, <<"groot.mainnet">>, #node{ip = "groot.mainnet.gajumaru.io"}};
|
||||
testnet -> {#net{id = <<"testnet">>}, <<"groot.testnet">>, #node{ip = "groot.testnet.gajumaru.io"}}
|
||||
end,
|
||||
Net = #net{id = Network},
|
||||
ChainID = <<"groot.", Network/binary>>,
|
||||
Node = #node{ip = unicode:characters_to_list(lists:join($., ["groot", Network, "gajumaru", "io"]))},
|
||||
New = #wallet{name = gm_name(),
|
||||
poas = [#poa{name = gm_name(), id = ID}],
|
||||
keys = [Created],
|
||||
@ -331,27 +330,32 @@ do_start_stop(#s{key = #key{id = PubKey}, network = Network}) ->
|
||||
% smrt guy stuff happens here
|
||||
{Bits, Eureka} =
|
||||
case Network of
|
||||
mainnet -> {"29", <<"https://gajumining.com/api/workers/", PubKey/binary>>};
|
||||
testnet -> {"15", <<"https://test.gajumining.com/api/workers/", PubKey/binary>>}
|
||||
<<"mainnet">> -> {"29", <<"https://gajumining.com/api/workers/", PubKey/binary>>};
|
||||
<<"testnet">> -> {"15", <<"https://test.gajumining.com/api/workers/", PubKey/binary>>}
|
||||
end,
|
||||
{Fatness, Type} =
|
||||
case {os:type(), Network} of
|
||||
case os:type() of
|
||||
{unix, linux} ->
|
||||
% Check memory. >7gb gets mean, <7gb gets lean
|
||||
% Check avx2.
|
||||
case Network of
|
||||
<<"mainnet">> -> {"mean", "avx2"};
|
||||
<<"testnet">> -> {"mean", "generic"}
|
||||
end;
|
||||
{unix, darwin} ->
|
||||
% Check memory. >7gb gets mean, <7gb gets lean
|
||||
{"mean", "generic"};
|
||||
{win32, nt} ->
|
||||
% Check memory. >7gb gets mean, <7gb gets lean
|
||||
% Check avx2.
|
||||
% Both should be provided by the F# start program
|
||||
{"mean", "avx2"}
|
||||
end,
|
||||
Miner = string:join([Fatness, Bits, "-", Type]),
|
||||
Miner = unicode:characters_to_binary([Fatness, Bits, "-", Type]),
|
||||
Profile =
|
||||
[{pubkey, PubKey},
|
||||
{mining, #{executable => Miner, executable_group => <<"gajumine">>}},
|
||||
{mining, [#{<<"executable">> => Miner, <<"executable_group">> => <<"gajumine">>}]},
|
||||
{pool_admin_url, Eureka}],
|
||||
gmmpc_app:start(Profile).
|
||||
{ok, Apps} = gmmpc_app:start(Profile),
|
||||
log(info, "Apps started: ~p", [Apps]).
|
||||
|
||||
|
||||
%%% Utils
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
-behavior(wx_object).
|
||||
-include_lib("wx/include/wx.hrl").
|
||||
-export([ask_passphrase/0, set_account/1, message/1]).
|
||||
-export([ask_passphrase/0, set_account/1, difficulty/1, speed/1, candidate/1, message/1]).
|
||||
-export([start_link/1]).
|
||||
-export([init/1, terminate/2, code_change/3,
|
||||
handle_call/3, handle_cast/2, handle_info/2, handle_event/2]).
|
||||
@ -23,28 +23,48 @@
|
||||
wx = none :: none | wx:wx_object()}).
|
||||
|
||||
-record(s,
|
||||
{wx = none :: none | wx:wx_object(),
|
||||
frame = none :: none | wx:wx_object(),
|
||||
lang = en :: en | jp,
|
||||
j = none :: none | fun(),
|
||||
id = none :: none | wx:wx_object(),
|
||||
diff = none :: none | wx:wx_object(),
|
||||
perf = none :: none | wx:wx_object(),
|
||||
candy = none :: none | wx:wx_object(),
|
||||
mess = none :: none | wx:wx_object(),
|
||||
buff = [] :: [string()],
|
||||
buttons = [] :: [#w{}]}).
|
||||
{wx = none :: none | wx:wx_object(),
|
||||
frame = none :: none | wx:wx_object(),
|
||||
lang = en :: en | jp,
|
||||
j = none :: none | fun(),
|
||||
id = none :: none | wx:wx_object(),
|
||||
diff = none :: none | wx:wx_object(),
|
||||
perf = none :: none | wx:wx_object(),
|
||||
candy = none :: none | wx:wx_object(),
|
||||
mess = none :: none | wx:wx_object(),
|
||||
buff = new_buff() :: buff(),
|
||||
buttons = [] :: [#w{}]}).
|
||||
|
||||
new_buff() ->
|
||||
{10, 0, 10, 0, []}.
|
||||
|
||||
-type buff() :: {OMax :: non_neg_integer(),
|
||||
OCur :: non_neg_integer(),
|
||||
IMax :: non_neg_integer(),
|
||||
ICur :: non_neg_integer(),
|
||||
Buff :: [[string()]]}.
|
||||
|
||||
|
||||
%%% Interface functions
|
||||
|
||||
ask_passphrase() ->
|
||||
wx_object:cast(?MODULE, ask_passphrase).
|
||||
|
||||
|
||||
set_account(ID) ->
|
||||
wx_object:cast(?MODULE, {set_account, ID}).
|
||||
|
||||
|
||||
ask_passphrase() ->
|
||||
wx_object:cast(?MODULE, ask_passphrase).
|
||||
difficulty(N) ->
|
||||
wx_object:cast(?MODULE, {difficulty, N}).
|
||||
|
||||
|
||||
speed(N) ->
|
||||
wx_object:cast(?MODULE, {speed, N}).
|
||||
|
||||
|
||||
candidate(Block) ->
|
||||
wx_object:cast(?MODULE, {candidate, Block}).
|
||||
|
||||
|
||||
message(Terms) ->
|
||||
@ -145,9 +165,18 @@ handle_cast(ask_passphrase, State) ->
|
||||
handle_cast({set_account, ID}, State) ->
|
||||
ok = set_account(ID, State),
|
||||
{noreply, State};
|
||||
handle_cast({message, Terms}, State) ->
|
||||
ok = do_message(Terms, State),
|
||||
handle_cast({difficulty, N}, State) ->
|
||||
ok = difficulty(N, State),
|
||||
{noreply, State};
|
||||
handle_cast({speed, N}, State) ->
|
||||
ok = speed(N, State),
|
||||
{noreply, State};
|
||||
handle_cast({candidate, Block}, State) ->
|
||||
ok = candidate(Block, State),
|
||||
{noreply, State};
|
||||
handle_cast({message, Terms}, State) ->
|
||||
NewState = do_message(Terms, State),
|
||||
{noreply, NewState};
|
||||
handle_cast(Unexpected, State) ->
|
||||
ok = log(warning, "Unexpected cast: ~tp~n", [Unexpected]),
|
||||
{noreply, State}.
|
||||
@ -218,9 +247,33 @@ set_account(ID, #s{id = Widget}) ->
|
||||
wxStaticText:setLabel(Widget, ID).
|
||||
|
||||
|
||||
do_message(Terms, #s{mess = Mess}) ->
|
||||
String = io_lib:format("Received args: ~tp", [Terms]),
|
||||
wxTextCtrl:changeValue(Mess, String).
|
||||
difficulty(N, #s{diff = Widget}) ->
|
||||
wxStaticText:setLabel(Widget, integer_to_list(N)).
|
||||
|
||||
|
||||
speed(N, #s{perf = Widget}) ->
|
||||
wxStaticText:setLabel(Widget, float_to_list(N)).
|
||||
|
||||
|
||||
candidate(Block, #s{candy = Widget}) ->
|
||||
wxStaticText:setLabel(Widget, Block).
|
||||
|
||||
|
||||
do_message(Terms, State = #s{mess = Mess, buff = Buff}) ->
|
||||
Entry = io_lib:format("Received args: ~tp~n", [Terms]),
|
||||
NewBuff = add_message(Entry, Buff),
|
||||
String = unicode:characters_to_list(element(5, NewBuff)),
|
||||
ok = wxTextCtrl:changeValue(Mess, String),
|
||||
State#s{buff = NewBuff}.
|
||||
|
||||
add_message(Entry, {OMax, OMax, IMax, IMax, Buff}) ->
|
||||
{OMax, OMax, IMax, 1, [[Entry] | lists:droplast(Buff)]};
|
||||
add_message(Entry, {OMax, OMax, IMax, ICur, [H | Buff]}) ->
|
||||
{OMax, OMax, IMax, ICur + 1, [[Entry | H] | Buff]};
|
||||
add_message(Entry, {OMax, OCur, IMax, IMax, Buff}) ->
|
||||
{OMax, OCur + 1, IMax, 1, [[Entry] | Buff]};
|
||||
add_message(Entry, {OMax, OCur, IMax, ICur, [H | Buff]}) ->
|
||||
{OMax, OCur, IMax, ICur + 1, [[Entry | H] | Buff]}.
|
||||
|
||||
|
||||
start_stop(State) ->
|
||||
|
@ -2,14 +2,15 @@
|
||||
{type,gui}.
|
||||
{modules,[]}.
|
||||
{prefix,"gmc"}.
|
||||
{author,"Craig Everett"}.
|
||||
{desc,"Mining client for the Gajumaru Root"}.
|
||||
{author,"Craig Everett"}.
|
||||
{package_id,{"qpq","gajumine",{0,1,0}}}.
|
||||
{deps,[{"uwiger","gm_mining_pool_protocol",{0,2,0}},
|
||||
{"uwiger","gmmp_client",{0,3,0}},
|
||||
{deps,[{"uwiger","gmmp_client",{0,3,5}},
|
||||
{"uwiger","gmminer",{1,1,0}},
|
||||
{"qpq","cuckoo_cpu",{0,1,0}},
|
||||
{"uwiger","gm_mining_pool_protocol",{0,2,0}},
|
||||
{"uwiger","gproc",{1,0,0}},
|
||||
{"uwiger","enoise",{1,3,0}},
|
||||
{"uwiger","gmminer",{1,0,1}},
|
||||
{"uwiger","gmcuckoo",{1,1,0}},
|
||||
{"uwiger","setup",{2,2,4}},
|
||||
{"uwiger","gmconfig",{0,1,1}},
|
||||
|
Loading…
x
Reference in New Issue
Block a user