Merge mining client interface
This commit is contained in:
+12
-58
@@ -17,73 +17,27 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "uv_util.h"
|
||||
|
||||
namespace p2pool {
|
||||
|
||||
class p2pool;
|
||||
|
||||
class MergeMiningClient
|
||||
class IMergeMiningClient
|
||||
{
|
||||
public:
|
||||
MergeMiningClient(p2pool* pool, const std::string& host, const std::string& wallet);
|
||||
~MergeMiningClient();
|
||||
|
||||
void merge_mining_submit_solution(const std::vector<uint8_t>& blob, const std::vector<hash>& merkle_proof);
|
||||
|
||||
FORCEINLINE hash aux_id() const { ReadLock lock(m_lock); return m_chainID; }
|
||||
FORCEINLINE hash aux_data() const { ReadLock lock(m_lock); return m_auxHash; }
|
||||
FORCEINLINE difficulty_type aux_diff() const { ReadLock lock(m_lock); return m_auxDiff; }
|
||||
|
||||
private:
|
||||
static void loop(void* data);
|
||||
|
||||
static void on_timer(uv_timer_t* timer) { reinterpret_cast<MergeMiningClient*>(timer->data)->on_timer(); }
|
||||
void on_timer();
|
||||
|
||||
void merge_mining_get_chain_id();
|
||||
bool parse_merge_mining_get_chain_id(const char* data, size_t size);
|
||||
|
||||
void merge_mining_get_job(uint64_t height, const hash& prev_id, const std::string& wallet, const hash& aux_hash);
|
||||
bool parse_merge_mining_get_job(const char* data, size_t size, bool& changed);
|
||||
|
||||
bool parse_merge_mining_submit_solution(const char* data, size_t size);
|
||||
|
||||
std::string m_host;
|
||||
uint32_t m_port;
|
||||
|
||||
mutable uv_rwlock_t m_lock;
|
||||
|
||||
std::string m_auxWallet;
|
||||
std::vector<uint8_t> m_auxBlob;
|
||||
hash m_auxHash;
|
||||
difficulty_type m_auxDiff;
|
||||
|
||||
hash m_chainID;
|
||||
double m_ping;
|
||||
|
||||
p2pool* m_pool;
|
||||
|
||||
uv_loop_t m_loop;
|
||||
uv_thread_t m_loopThread;
|
||||
|
||||
uv_timer_t m_timer;
|
||||
|
||||
bool m_getJobRunning;
|
||||
|
||||
uv_async_t m_shutdownAsync;
|
||||
|
||||
static void on_shutdown(uv_async_t* async)
|
||||
struct ChainParameters
|
||||
{
|
||||
MergeMiningClient* client = reinterpret_cast<MergeMiningClient*>(async->data);
|
||||
client->on_shutdown();
|
||||
hash aux_id;
|
||||
hash aux_hash;
|
||||
std::vector<uint8_t> aux_blob;
|
||||
difficulty_type aux_diff;
|
||||
};
|
||||
|
||||
uv_close(reinterpret_cast<uv_handle_t*>(&client->m_shutdownAsync), nullptr);
|
||||
public:
|
||||
static IMergeMiningClient* create(p2pool* pool, const std::string& host, const std::string& wallet) noexcept;
|
||||
virtual ~IMergeMiningClient() {}
|
||||
|
||||
delete GetLoopUserData(&client->m_loop, false);
|
||||
}
|
||||
|
||||
void on_shutdown();
|
||||
virtual bool get_params(ChainParameters& out_params) const = 0;
|
||||
virtual void submit_solution(const std::vector<uint8_t>& blob, const std::vector<hash>& merkle_proof) = 0;
|
||||
};
|
||||
|
||||
} // namespace p2pool
|
||||
|
||||
Reference in New Issue
Block a user