-
Notifications
You must be signed in to change notification settings - Fork 30
/
main.cpp
182 lines (145 loc) · 4.94 KB
/
main.cpp
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// BEAM OpenCL Miner
// Main Function
// Copyright 2018 The Beam Team
// Copyright 2018 Wilke Trei
#include "beamStratum.h"
#include "clHost.h"
// Defining global variables
const string StrVersionNumber = "v1.1.0";
const string StrVersionDate = "Jun 25th 2019";
inline vector<string> &split(const string &s, char delim, vector<string> &elems) {
stringstream ss(s);
string item;
while(getline(ss, item, delim)) {
elems.push_back(item);
}
return elems;
}
inline vector<string> split(const string &s, char delim) {
vector<string> elems;
return split(s, delim, elems);
}
uint32_t cmdParser(vector<string> args, string &host, string &port, string &apiCred, bool &debug, bool &beamHashI, vector<int32_t> &devices, bool &force3G ) {
bool hostSet = false;
bool apiSet = false;
for (uint32_t i=0; i<args.size(); i++) {
if (args[i][0] == '-') {
if ((args[i].compare("-h") == 0) || (args[i].compare("--help") == 0)) {
return 0x4;
}
if (args[i].compare("--server") == 0) {
if (i+1 < args.size()) {
vector<string> tmp = split(args[i+1], ':');
if (tmp.size() == 2) {
host = tmp[0];
port = tmp[1];
hostSet = true;
i++;
continue;
}
}
}
if (args[i].compare("--key") == 0) {
if (i+1 < args.size()) {
apiCred = args[i+1];
apiSet = true;
i++;
continue;
}
}
if (args[i].compare("--devices") == 0) {
if (i+1 < args.size()) {
vector<string> tmp = split(args[i+1], ',');
for (int j=0; j<tmp.size(); j++) {
devices.push_back(stoi(tmp[j]));
}
continue;
}
}
if (args[i].compare("--force3G") == 0) {
force3G = true;
}
if (args[i].compare("--beamHashI") == 0) {
beamHashI = true;
}
if (args[i].compare("--debug") == 0) {
debug = true;
}
if (args[i].compare("--version") == 0) {
cout << StrVersionNumber << " for BEAM main network " << "(" << StrVersionDate << ")" << endl;
exit(0);
}
}
}
uint32_t result = 0;
if (!hostSet) result += 1;
if (!apiSet) result += 2;
if (devices.size() == 0) devices.assign(1,-1);
sort(devices.begin(), devices.end());
return result;
}
int main(int argc, char* argv[]) {
vector<string> cmdLineArgs(argv, argv+argc);
string host;
string port;
string apiCred;
bool debug = false;
bool fbeamHashI = false;
bool useTLS = true;
vector<int32_t> devices;
bool force3G = false;
uint32_t parsing = cmdParser(cmdLineArgs, host, port, apiCred, debug, fbeamHashI, devices, force3G);
cout << "-====================================-" << endl;
cout << " " << endl;
cout << " BeamHash I / II OpenCL Miner " << endl;
cout << " version: " + StrVersionNumber << endl;
cout << " date: " + StrVersionDate << endl;
cout << " " << endl;
cout << "-====================================-" << endl;
cout << "" << endl;
cout << "Parameters: " << endl;
cout << " --server: " << host << ":" << port << endl;
cout << " --key: " << apiCred << endl;
cout << " --beamHashI: " << std::boolalpha << fbeamHashI << endl;
cout << " --force3G: " << std::boolalpha << force3G << endl;
cout << " --debug: " << std::boolalpha << debug << endl;
if (parsing != 0) {
if (parsing & 0x1) {
cout << "Error: Parameter --server missing" << endl;
}
if (parsing & 0x2) {
cout << "Error: Parameter --key missing" << endl;
}
cout << "Parameters: " << endl;
cout << " --help / -h Showing this message" << endl;
cout << " --server <server>:<port> The BEAM stratum server and port to connect to (required)" << endl;
cout << " --key <key> The BEAM stratum server API key (required), on a Beam mining pool the user name / wallet addres" << endl;
cout << " --devices <numbers> A comma seperated list of devices that should be used for mining (default: all in system)" << endl;
cout << " --beamHashI Force mining BeamHash I (pre fork)" << endl;
cout << " --debug Enable debug mode - verbose information will be displayed" << endl;
cout << " --force3G Force miner to use max 3G for all installed GPUs" << endl;
cout << " --version Prints the version number" << endl;
exit(0);
}
beamMiner::beamStratum myStratum(host, port, apiCred, debug);
beamMiner::clHost myClHost;
cout << endl;
cout << "Setup OpenCL devices:" << endl;
cout << "=====================" << endl;
myClHost.setup(&myStratum, devices, fbeamHashI, force3G);
cout << endl;
cout << "Waiting for work from stratum:" << endl;
cout << "==============================" << endl;
myStratum.startWorking();
while (!myStratum.hasWork()) {
this_thread::sleep_for(std::chrono::milliseconds(200));
}
cout << endl;
cout << "Start mining:" << endl;
cout << "=============" << endl;
myClHost.startMining();
}
#if defined(_MSC_VER) && (_MSC_VER >= 1900)
FILE _iob[] = { *stdin, *stdout, *stderr };
extern "C" FILE * __cdecl __iob_func(void) { return _iob; }
#endif