forked from BeamMW/beam-cuda-miner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
beamStratum.h
96 lines (74 loc) · 2.16 KB
/
beamStratum.h
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
// BEAM OpenCL Miner
// Stratum interface class
// Copyright 2018 The Beam Team
// Copyright 2018 Wilke Trei
#include <iostream>
#include <thread>
#include <cstdlib>
#include <string>
#include <sstream>
#include <vector>
#include <deque>
#include <random>
#include <boost/scoped_ptr.hpp>
#include <boost/asio.hpp>
#include <boost/asio/ssl.hpp>
#include <boost/bind.hpp>
#include <boost/thread.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include "core/difficulty.h"
#include "core/uintBig.h"
using namespace std;
using namespace boost::asio;
using boost::asio::ip::tcp;
namespace pt = boost::property_tree;
namespace beamMiner {
#ifndef beamMiner_H
#define beamMiner_H
class beamStratum {
private:
// Definitions belonging to the physical connection
boost::asio::io_service io_service;
boost::scoped_ptr< boost::asio::ssl::stream<tcp::socket> > socket;
tcp::resolver res;
boost::asio::streambuf requestBuffer;
boost::asio::streambuf responseBuffer;
boost::asio::ssl::context context;
// User Data
string host;
string port;
string apiKey;
bool debug = true;
// Storage for received work
int64_t workId;
std::vector<uint8_t> serverWork;
std::atomic<uint64_t> nonce;
beam::Difficulty powDiff;
std::vector<uint8_t> poolNonce;
//Stratum sending subsystem
bool activeWrite = false;
void queueDataSend(string);
void syncSend(string);
void activateWrite();
void writeHandler(const boost::system::error_code&);
std::deque<string> writeRequests;
// Stratum receiving subsystem
void readStratum(const boost::system::error_code&);
boost::mutex updateMutex;
// Connection handling
void connect();
void handleConnect(const boost::system::error_code& err, tcp::resolver::iterator);
void handleHandshake(const boost::system::error_code& err);
bool verifyCertificate(bool,boost::asio::ssl::verify_context& );
// Solution Check & Submit
void testAndSubmit(int64_t, uint64_t, std::vector<uint32_t>);
public:
beamStratum(string, string, string, bool);
void startWorking();
bool hasWork();
void getWork(int64_t*, uint64_t*, uint8_t*);
void handleSolution(int64_t&, uint64_t&, std::vector<uint32_t>&);
};
#endif
}