Crate parsers_sv2

Crate parsers_sv2 

Source
Expand description

§Parsing, Serializing, and Message Type Identification

Provides logic to convert raw Stratum V2 (Sv2) message data into Rust types, as well as logic to handle conversions among Sv2 rust types. The crate is no_std compatible by default.

Most of the logic on this module is tightly coupled with the binary_sv2 crate.

§Responsibilities

  • Parsing: Converts raw Sv2 message bytes into Rust enums (CommonMessages, Mining, etc.).
  • Serialization: Converts Rust enums back into binary format for transmission.
  • Protocol Abstraction: Separates logic for different Sv2 subprotocols, ensuring modular and extensible design.
  • Message Metadata: Identifies message types and channel bits for routing and processing.

§Supported Subprotocols

  • Common Messages: Shared across all Sv2 roles.
  • Template Distribution: Handles block templates updates and transaction data.
  • Job Declaration: Manages custom mining job declarations, transactions, and solutions.
  • Mining Protocol: Manages standard mining communication (e.g., job dispatch, shares submission).

Re-exports§

pub use error::ParserError;

Modules§

error

Structs§

Tlv
A single TLV (Type-Length-Value) field.

Enums§

AnyMessage
A parser of all possible SV2 messages
CommonMessageTypes
A list of 8-bit message type variants that are common to all Sv2 subprotocols
CommonMessages
Common Sv2 protocol messages used across all subprotocols.
ExtensionError
Errors that can occur when working with TLV extension fields.
Extensions
Extensions protocol messages for negotiating optional protocol features.
ExtensionsNegotiation
Extensions Negotiation protocol messages (extension_type=0x0001).
ExtensionsNegotiationTypes
Extension message types enum for Extensions Negotiation (extension_type=0x0001)
JobDeclaration
A parser of messages of Job Declaration subprotocol, to be used for parsing raw messages
JobDeclarationTypes
A list of 8-bit message type variants under Job Declaration subprotocol
Mining
Mining subprotocol messages: categorization, encapsulation, and parsing.
MiningDeviceMessages
A parser of messages that a Mining Device could send
MiningTypes
A list of 8-bit message type variants under Mining subprotocol
TemplateDistribution
A parser of messages of Template Distribution subprotocol, to be used for parsing raw messages
TemplateDistributionTypes
A list of 8-bit message type variants under Template Distribution subprotocol
TlvError
Generic errors that can occur during TLV field encoding and decoding.
TlvList
A collection of TLV fields that can be used for both parsing and building.
UserIdentityError
Errors specific to the Worker-Specific Hashrate Tracking extension.

Constants§

TLV_HEADER_SIZE
TLV header size in bytes (3 bytes Type + 2 bytes Length)

Traits§

IsSv2Message
A trait that every Sv2 message parser must implement. It helps parsing from Rust types to raw messages.
TlvField
Trait for types that can be encoded/decoded as TLV fields.

Functions§

message_type_to_name
Converts a message type number to a human-readable name
parse_message_frame_with_tlvs
Single entry point for parsing any SV2 protocol message frame with TLV support.