// // Created by biimi on 4/20/2024. // #include #ifndef EE382N_BITCOIN_STRATUM_H #define EE382N_BITCOIN_STRATUM_H namespace Stratum { class StratumMessage { public: virtual uint16_t get_extension_type() const = 0; virtual uint8_t get_msg_type() const = 0; }; namespace Common { class SetupConnection : public StratumMessage { public: uint8_t protocol; uint16_t min_version; uint16_t max_version; uint32_t flags; std::string endpoint_host; uint16_t endpoint_port; std::string vendor; std::string hardware_version; std::string firmware; std::string device_id; static const int EXTENSION_TYPE = 0; uint16_t get_extension_type() { return EXTENSION_TYPE; }; static const uint8_t MSG_TYPE = 0x00; uint8_t get_msg_type() { return MSG_TYPE; }; static constexpr uint32_t FLAG_MINING_REQUIRES_STANDARD_JOBS = 1; static constexpr uint32_t FLAG_MINING_REQUIRES_WORK_SELECTION = 2; static constexpr uint32_t FLAG_MINING_REQUIRES_VERSION_ROLLING = 4; }; class SetupConnectionSuccess : public StratumMessage { public: uint16_t used_version; uint32_t flags; static const int EXTENSION_TYPE = 0; uint16_t get_extension_type() { return EXTENSION_TYPE; }; static const uint8_t MSG_TYPE = 0x01; uint8_t get_msg_type() { return MSG_TYPE; }; static constexpr uint32_t FLAG_MINING_REQUIRES_FIXED_VERSION = 1; static constexpr uint32_t FLAG_MINING_REQUIRES_EXTENDED_CHANNELS = 2; }; class SetupConnectionError : public StratumMessage { public: uint32_t flags; std::string error_code; static const int EXTENSION_TYPE = 0; uint16_t get_extension_type() { return EXTENSION_TYPE; }; static const uint8_t MSG_TYPE = 0x02; uint8_t get_msg_type() { return MSG_TYPE; }; }; class ChannelEndpointChanged : public StratumMessage { public: uint32_t channel_id; static const int EXTENSION_TYPE = 0; uint16_t get_extension_type() { return EXTENSION_TYPE; }; static const uint8_t MSG_TYPE = 0x03; uint8_t get_msg_type() { return MSG_TYPE; }; }; } // namespace Common namespace MiningProtocol { class OpenStandardMiningChannel : public StratumMessage { public: uint32_t request_id; std::string user_identity; float nominal_hash_rate; uint8_t max_target[256 / 8]; static const int EXTENSION_TYPE = 0; uint16_t get_extension_type() { return EXTENSION_TYPE; }; static const uint8_t MSG_TYPE = 0x10; uint8_t get_msg_type() { return MSG_TYPE; }; }; class OpenStandardMiningChannelSuccess : public StratumMessage { public: uint32_t request_id; uint32_t channel_id; uint8_t target[256 / 8]; std::vector extranonce_prefix; uint32_t group_channel_id; static const int EXTENSION_TYPE = 0; uint16_t get_extension_type() { return EXTENSION_TYPE; }; static const uint8_t MSG_TYPE = 0x11; uint8_t get_msg_type() { return MSG_TYPE; }; }; class OpenMiningChannelError : public StratumMessage { public: uint32_t request_id; std::string error_code; static const int EXTENSION_TYPE = 0; uint16_t get_extension_type() { return EXTENSION_TYPE; }; static const uint8_t MSG_TYPE = 0x12; uint8_t get_msg_type() { return MSG_TYPE; }; }; class CloseChannel : public StratumMessage { public: uint32_t channel_id; std::string reason_code; static const int EXTENSION_TYPE = 0; uint16_t get_extension_type() { return EXTENSION_TYPE; }; static const uint8_t MSG_TYPE = 0x18; uint8_t get_msg_type() { return MSG_TYPE; }; }; class NewMiningJob : public StratumMessage { public: uint32_t channel_id; uint32_t job_id; bool has_min_ntime; uint32_t min_ntime; uint32_t version; uint32_t merkle_root; static const int EXTENSION_TYPE = 0; uint16_t get_extension_type() { return EXTENSION_TYPE; }; static const uint8_t MSG_TYPE = 0x15; uint8_t get_msg_type() { return MSG_TYPE; }; }; class SetNewPrevHash : public StratumMessage { public: uint32_t channel_id; uint32_t job_id; uint8_t prev_hash[256 / 8]; uint32_t min_ntime; uint32_t nbits; static const int EXTENSION_TYPE = 0; uint16_t get_extension_type() { return EXTENSION_TYPE; }; static const uint8_t MSG_TYPE = 0x20; uint8_t get_msg_type() { return MSG_TYPE; }; }; class SetTarget : public StratumMessage { public: uint32_t channel_id; uint8_t maximum_target[256 / 8]; static const int EXTENSION_TYPE = 0; uint16_t get_extension_type() { return EXTENSION_TYPE; }; static const uint8_t MSG_TYPE = 0x21; uint8_t get_msg_type() { return MSG_TYPE; }; }; class SubmitSharesStandard : public StratumMessage { public: uint32_t channel_id; uint32_t sequence_number; uint32_t job_id; uint32_t nonce; uint32_t ntime; uint32_t version; static const int EXTENSION_TYPE = 0; uint16_t get_extension_type() { return EXTENSION_TYPE; }; static const uint8_t MSG_TYPE = 0x1a; uint8_t get_msg_type() { return MSG_TYPE; }; }; class SubmitSharesSuccess : public StratumMessage { public: uint32_t channel_id; uint32_t last_sequence_number; uint32_t new_submits_accepted_count; uint64_t new_shares_sum; static const int EXTENSION_TYPE = 0; uint16_t get_extension_type() { return EXTENSION_TYPE; }; static const uint8_t MSG_TYPE = 0x1c; uint8_t get_msg_type() { return MSG_TYPE; }; }; class SubmitSharesError : public StratumMessage { public: uint32_t channel_id; uint32_t sequence_number; std::string error_code; static const int EXTENSION_TYPE = 0; uint16_t get_extension_type() { return EXTENSION_TYPE; }; static const uint8_t MSG_TYPE = 0x1d; uint8_t get_msg_type() { return MSG_TYPE; }; }; } // namespace MiningProtocol } // namespace Stratum #endif //EE382N_BITCOIN_STRATUM_H