stratum_apps/utils/
types.rs1use stratum_core::{
2 codec_sv2::{EncodableFrame, MessageFrame, SerializedFrame},
3 parsers_sv2::{AnyMessageOwned, ParserError},
4};
5
6pub const GRACEFUL_SHUTDOWN_TIMEOUT_SECONDS: u64 = 5;
7
8pub const SUPPORTED_PROTOCOL_VERSION: u16 = 2;
10
11pub type TemplateId = u64;
12pub type UpstreamJobId = u32;
13pub type JobId = u32;
14pub type DownstreamId = usize;
15pub type RequestId = u32;
16pub type ChannelId = u32;
17pub type Hashrate = f32;
18pub type SharesPerMinute = f32;
19pub type SharesBatchSize = usize;
20pub type ExtensionType = u16;
21pub type MessageType = u8;
22pub type JdToken = u64;
23
24pub type Message = AnyMessageOwned;
25
26pub type InboundFrame = SerializedFrame;
28
29#[derive(Debug)]
32pub enum OutboundFrame {
33 Message(MessageFrame<Message>),
35
36 Raw(SerializedFrame),
38}
39
40impl OutboundFrame {
41 pub fn from_message(message: Message) -> Result<Self, ParserError> {
43 Ok(Self::Message(message.try_into()?))
44 }
45}
46
47impl From<MessageFrame<Message>> for OutboundFrame {
48 fn from(frame: MessageFrame<Message>) -> Self {
49 Self::Message(frame)
50 }
51}
52
53impl From<SerializedFrame> for OutboundFrame {
54 fn from(frame: SerializedFrame) -> Self {
55 Self::Raw(frame)
56 }
57}
58
59impl EncodableFrame for OutboundFrame {
60 fn encoded_length(&self) -> usize {
61 match self {
62 Self::Message(frame) => frame.encoded_length(),
63 Self::Raw(frame) => frame.encoded_length(),
64 }
65 }
66
67 fn encode_into(self, dst: &mut [u8]) -> Result<(), stratum_core::framing_sv2::Error> {
68 match self {
69 Self::Message(frame) => frame.encode_into(dst),
70 Self::Raw(frame) => frame.encode_into(dst),
71 }
72 }
73}
74
75#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
76pub struct VardiffKey {
77 pub downstream_id: DownstreamId,
78 pub channel_id: ChannelId,
79}
80
81impl From<(DownstreamId, ChannelId)> for VardiffKey {
82 fn from(value: (DownstreamId, ChannelId)) -> Self {
83 VardiffKey {
84 downstream_id: value.0,
85 channel_id: value.1,
86 }
87 }
88}
89
90pub trait CanDisconnect {}
93pub trait CanFallback {}
94pub trait CanShutdown {}