1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
// Bitflash entry point -- starts node threads then runs GUI (or headless).
#include "headers_core.h"
#ifndef _WIN32
#include <csignal>
#endif
int RunGUI(int argc, char* argv[]);
// Global definitions (were in ui.cpp, now here)
map<string,string> mapAddressBook;
bool gPoolServerRunning = false;
static bool arg(int argc, char* argv[], const char* key)
{
for (int i=1;i<argc;i++) { string s=argv[i]; if(s==key||s.substr(0,s.find('='))==key) return true; }
return false;
}
static string argval(int argc, char* argv[], const char* key)
{
for (int i=1;i<argc;i++) {
string s=argv[i]; size_t eq=s.find('=');
if(eq!=string::npos && s.substr(0,eq)==key) return s.substr(eq+1);
}
return "";
}
static string argval2(int argc, char* argv[], const char* keySlash, const char* keyDash)
{
string v = argval(argc, argv, keySlash);
if (!v.empty())
return v;
return argval(argc, argv, keyDash);
}
static void PrintUsage()
{
printf("Bitflash command-line options\n");
printf("\n");
printf("General:\n");
printf(" /help, -help, --help, /?\n");
printf(" /datadir=PATH\n");
printf(" /debug\n");
printf(" /gen\n");
printf(" /nogui or /daemon\n");
printf("\n");
printf("Mining mode:\n");
printf(" /operator\n");
printf(" /participant=POOL_BTF_ADDRESS\n");
printf(" /solomine\n");
printf("\n");
printf("Pool operator announcement:\n");
printf(" /poolname=NAME\n");
printf(" /poolfee=PCT\n");
printf(" /pooldashboard=URL (alias: /pooldash=URL)\n");
printf("\n");
printf(".btf and rendezvous:\n");
printf(" /connectbtf=PEER_BTF_ADDRESS\n");
printf(" /rvrelay=HOST:PORT\n");
printf(" /announcerelay=HOST:PORT\n");
printf("\n");
printf("Each option also accepts '-' instead of '/'.\n");
}
static void ParseStartupArguments(int argc, char* argv[])
{
if (arg(argc,argv,"/datadir") || arg(argc,argv,"-datadir"))
strSetDataDir = argval2(argc, argv, "/datadir", "-datadir");
if (arg(argc,argv,"/debug") || arg(argc,argv,"-debug"))
fDebug = true;
if (arg(argc,argv,"/gen") || arg(argc,argv,"-gen"))
fGenerateBitcoins = 1;
if (arg(argc,argv,"/solomine") || arg(argc,argv,"-solomine"))
fSoloMineTest = true;
if (arg(argc,argv,"/operator") || arg(argc,argv,"-operator"))
nMineMode = MINE_OPERATOR;
if (arg(argc,argv,"/participant") || arg(argc,argv,"-participant"))
{
nMineMode = MINE_PARTICIPANT;
strParticipantPool = argval2(argc, argv, "/participant", "-participant");
}
string poolName = argval2(argc, argv, "/poolname", "-poolname");
if (!poolName.empty())
strPoolName = poolName;
string poolDash = argval2(argc, argv, "/pooldashboard", "-pooldashboard");
if (poolDash.empty())
poolDash = argval2(argc, argv, "/pooldash", "-pooldash");
if (!poolDash.empty())
strPoolDashboardUrl = poolDash;
string poolFee = argval2(argc, argv, "/poolfee", "-poolfee");
if (!poolFee.empty())
dPoolFeePercent = atof(poolFee.c_str());
string btfConnect = argval2(argc, argv, "/connectbtf", "-connectbtf");
if (!btfConnect.empty())
strBtfConnect = btfConnect;
string rvRelay = argval2(argc, argv, "/rvrelay", "-rvrelay");
if (!rvRelay.empty())
{
vBtfMeetingRelays.clear();
vBtfMeetingRelays.push_back(rvRelay);
}
string announceRelay = argval2(argc, argv, "/announcerelay", "-announcerelay");
if (!announceRelay.empty())
strBtfAnnounceRelay = announceRelay;
}
int main(int argc, char* argv[])
{
if (arg(argc,argv,"/help") || arg(argc,argv,"-help") ||
arg(argc,argv,"--help") || arg(argc,argv,"/?"))
{
PrintUsage();
return 0;
}
ParseStartupArguments(argc, argv);
printf("Loading block index...\n");
string strErrors;
if (!LoadBlockIndex()) { fprintf(stderr,"LoadBlockIndex failed\n"); return 1; }
printf("Loading wallet...\n");
if (!LoadWallet()) { fprintf(stderr,"LoadWallet failed\n"); return 1; }
printf("Height=%d\n", nBestHeight);
ReacceptWalletTransactions();
if (!StartNode(strErrors)) { fprintf(stderr,"StartNode: %s\n",strErrors.c_str()); return 1; }
if (nMineMode == MINE_OPERATOR) {
gPoolServerRunning = true;
gPoolRunning = true;
if (_beginthread(ThreadRPCServer, 0, NULL) == (uintptr_t)-1)
printf("Error: _beginthread(ThreadRPCServer) failed\n");
}
if (fGenerateBitcoins)
if (_beginthread(ThreadBitcoinMiner, 0, NULL) == (uintptr_t)-1)
printf("Error: _beginthread(ThreadBitcoinMiner) failed\n");
bool fHeadless = arg(argc,argv,"/nogui") || arg(argc,argv,"-nogui") ||
arg(argc,argv,"/daemon") || arg(argc,argv,"-daemon");
if (fHeadless) {
#ifndef _WIN32
auto sig=[](int){fShutdown=true;};
signal(SIGINT,sig); signal(SIGTERM,sig);
#endif
printf("Running headless. Ctrl-C to stop.\n");
while (!fShutdown) Sleep(500);
StopNode();
return 0;
}
int ret = RunGUI(argc, argv);
fShutdown = true;
StopNode();
return ret;
}
|