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