use stratum_core::{
codec_sv2::{EncodableFrame, MessageFrame, SerializedFrame},
parsers_sv2::{AnyMessageOwned, ParserError},
};
pub const GRACEFUL_SHUTDOWN_TIMEOUT_SECONDS: u64 = 5;
pub const SUPPORTED_PROTOCOL_VERSION: u16 = 2;
pub type TemplateId = u64;
pub type UpstreamJobId = u32;
pub type JobId = u32;
pub type DownstreamId = usize;
pub type RequestId = u32;
pub type ChannelId = u32;
pub type Hashrate = f32;
pub type SharesPerMinute = f32;
pub type SharesBatchSize = usize;
pub type ExtensionType = u16;
pub type MessageType = u8;
pub type JdToken = u64;
pub type Message = AnyMessageOwned;
pub type InboundFrame = SerializedFrame;
#[derive(Debug)]
pub enum OutboundFrame {
Message(MessageFrame<Message>),
Raw(SerializedFrame),
}
impl OutboundFrame {
pub fn from_message(message: Message) -> Result<Self, ParserError> {
Ok(Self::Message(message.try_into()?))
}
}
impl From<MessageFrame<Message>> for OutboundFrame {
fn from(frame: MessageFrame<Message>) -> Self {
Self::Message(frame)
}
}
impl From<SerializedFrame> for OutboundFrame {
fn from(frame: SerializedFrame) -> Self {
Self::Raw(frame)
}
}
impl EncodableFrame for OutboundFrame {
fn encoded_length(&self) -> usize {
match self {
Self::Message(frame) => frame.encoded_length(),
Self::Raw(frame) => frame.encoded_length(),
}
}
fn encode_into(self, dst: &mut [u8]) -> Result<(), stratum_core::framing_sv2::Error> {
match self {
Self::Message(frame) => frame.encode_into(dst),
Self::Raw(frame) => frame.encode_into(dst),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct VardiffKey {
pub downstream_id: DownstreamId,
pub channel_id: ChannelId,
}
impl From<(DownstreamId, ChannelId)> for VardiffKey {
fn from(value: (DownstreamId, ChannelId)) -> Self {
VardiffKey {
downstream_id: value.0,
channel_id: value.1,
}
}
}
pub trait CanDisconnect {}
pub trait CanFallback {}
pub trait CanShutdown {}