-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
111 lines (90 loc) · 3.19 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
#include <iostream>
#include <fstream>
#include <string>
#include <jsoncpp/json/json.h>
#include <boost/process.hpp>
#include "miner_config.h"
#include "miner_stat.h"
#include "common.h"
using namespace std;
namespace bp = ::boost::process;
string decodealgo(int _algo)
{
vector<string> algolist = { "cc", "cc", "cc", "cc", "cc",
"c11", "cc", "cc", "cc", "cc", "cc", "cc",
"cc", "cc", "cc", "cc", "hmq1725", "cc", "cc", "cc",
"hsr", "cc", "cc", "cc", "lyra2z", "cc", "cc", "cc",
"cc", "cc", "cc", "cc", "cc", "cc", "cc", "cc",
"cc", "cc", "cc", "cc", "skunk", "cc", "cc", "tribus", "bitcore", "cc",
"cc", "cc", "cc", "cc", "x17", "cc", "cc", "cc", "cc",
"cc", "cc", "cc", "cc", "cc", "phi", "cc", "cc", "cc",
"cc", "polytimos", "sonoa", "x16r", "x16s", "cc", "cc", "cc", "balloon","bcd","renesis" };
//HSR 20, LBRY 21, LYRA2Z 24, phi2 25, SKUNK, 40,phi 60. x16r 67, bcd 73
if (_algo > 74)
return algolist[0];
else
return algolist[_algo];
}
int main() {
Json::Reader reader;
Json::Value root;
ifstream cfg("./config.json", ifstream::binary);
if(!reader.parse(cfg, root, false)) {
cout << "parse config file error!\n" << endl;
return 0;
}
cfg.close();
int uid = root["uid"].asInt();
string worker = root["worker"].asString();
miner_config minercfg(uid, worker);
miner_stat ms;
do{
if(!minercfg.getminercfg()) {
cout << "minercfg getminercfg error!\n" << endl;
return 0;
}
string pool = "stratum+tcp://" + minercfg.cfggproxy + ".yunpools.com:" + to_string(minercfg.getrandomport());
string user = minercfg.cfgusernameid +"."+ minercfg.workid;
string exec{"./t-rex"};
vector<string> args;
//args.push_back("t-rex");
args.push_back("-a");
args.push_back(decodealgo(stoi(minercfg.cfgalgo)));
args.push_back("-o");
args.push_back(pool);
args.push_back("-u");
args.push_back(user);
args.push_back("-p");
args.push_back("x");
args.push_back("--exit-on-cuda-error");
try {
bp::child cp(
bp::exe(exec),
bp::args(args)
);
int a=0, b=0;
while(!cp.wait_for(std::chrono::milliseconds(1000))) {
a++,b++;
if(a==60) {
a=0;
if(ms.reboottrex()) {
cp.terminate();
break;
}
}
if(b==600) {
b=0;
if(minercfg.isnewconfig()) {
cp.terminate();
break;
}
}
}
} catch (std::exception& e) {
std::cout << "bp::child error! create process failed. error info: " << e.what() << std::endl;
std::cout << "press any key exit!" << std::endl;
break;
}
}while (true);
return 0;
}