/** * mining_work.hpp */ #include "nlohmann/json.hpp" #include "bitcoin_block_header.hpp" #ifndef EE382N_BITCOIN_MINING_WORK_HPP #define EE382N_BITCOIN_MINING_WORK_HPP using json = nlohmann::json; namespace stratum_v1 { class MiningWork { public: MiningWork(json ¶ms, const std::string& xnonce1, size_t xnonce2_size); std::string generate_coinbase(); void increment_xnonce2(); std::string generate_merkle_root(); // std::string generate_block_header(uint32_t nonce); // void generate_block_header(uint8_t header[80], uint32_t nonce); BitcoinBlockHeader generate_header_template(); bool get_clean_jobs() const; std::string get_job_id() const; std::string get_prev_hash() const; std::string get_version() const; std::string get_nbits() const; std::string get_ntime() const; std::string get_xnonce2() const; static void hex2bin(const std::string &hex_str, uint8_t *out); static uint32_t hex2bin32(const std::string& hex); static std::string bin2hex(const uint8_t *bin, size_t len); private: // Inputs from mining.notify std::string _job_id; std::string _prev_hash; std::string _coin_base1; std::string _coin_base2; std::vector _merkle_branch; std::string _version; std::string _nbits; std::string _ntime; bool _clean_jobs; // Session context from mining.subscribe response std::string _xnonce1; size_t _xnonce1_size; size_t _xnonce2_size; // Extra nonce field to increment if we try all nonce * version hashes std::vector _xnonce2; }; } // namespace stratum_v1 #endif //EE382N_BITCOIN_MINING_WORK_HPP