1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use crate::stratum_error::StratumError;
use std::net::IpAddr;
#[derive(Clone, Debug)]
pub struct MinerInfo {
pub ip: IpAddr,
pub auth: Option<MinerAuth>,
pub sid: Option<String>,
pub job_stats: Option<MinerJobStats>,
}
#[derive(Clone, Debug)]
pub struct MinerAuth {
pub id: String,
pub username: String,
pub client: String,
}
#[derive(Clone, Debug)]
pub struct MinerJobStats {
pub expected_difficulty: f64,
}
impl MinerInfo {
pub fn get_auth(&self) -> std::result::Result<MinerAuth, StratumError> {
match &self.auth {
Some(auth) => Ok(auth.clone()),
None => Err(StratumError::Unauthorized),
}
}
pub fn get_sid(&self) -> std::result::Result<String, StratumError> {
match &self.sid {
Some(sid) => Ok(sid.clone()),
None => Err(StratumError::NotSubscribed),
}
}
pub fn get_job_stats(&self) -> std::result::Result<MinerJobStats, StratumError> {
match &self.job_stats {
Some(job_stats) => Ok(job_stats.clone()),
None => Err(StratumError::Internal),
}
}
}