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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
use crate::miner::MinerInfo;
use crate::Result;
use async_trait::async_trait;
use serde::{de::DeserializeOwned, Serialize};
use std::fmt::Debug;
use std::sync::Arc;
pub trait SubscribeResult: DeserializeOwned + Serialize + Sync + Send + Clone + Debug {
fn id(&self) -> String;
}
pub trait StratumParams {
type Submit: DeserializeOwned + Serialize + Sync + Send + Clone + Debug;
type Notify: DeserializeOwned + Serialize + Sync + Send + Clone + Debug;
}
pub trait PoolParams {
type Authorize: DeserializeOwned + Serialize + Sync + Send + Clone + Debug;
type Authorized: DeserializeOwned + Serialize + Sync + Send + Clone + Debug;
type Subscribe: DeserializeOwned + Serialize + Sync + Send + Clone + Debug;
type SubscribeResult: SubscribeResult;
}
#[async_trait]
pub trait StratumManager: Sync + Send + Clone {
type StratumParams: StratumParams + DeserializeOwned + Serialize + Clone;
type PoolParams: PoolParams + DeserializeOwned + Serialize + Clone;
type AuthManager: AuthManager<
Authorize = <Self::PoolParams as PoolParams>::Authorize,
Authorized = <Self::PoolParams as PoolParams>::Authorized,
Subscribe = <Self::PoolParams as PoolParams>::Subscribe,
SubscribeResult = <Self::PoolParams as PoolParams>::SubscribeResult,
>;
type DataProvider: DataProvider<Job = <Self::StratumParams as StratumParams>::Notify>;
type BlockValidator: BlockValidator<
Job = <Self::StratumParams as StratumParams>::Notify,
Submit = <Self::StratumParams as StratumParams>::Submit,
>;
}
#[async_trait]
pub trait AuthManager: Sync + Send + Clone {
type Authorize: DeserializeOwned + Serialize + Sync + Send + Clone + Debug;
type Authorized: DeserializeOwned + Serialize + Sync + Send + Clone + Debug;
type Subscribe: DeserializeOwned + Serialize + Sync + Send + Clone + Debug;
type SubscribeResult: SubscribeResult;
async fn init(&self) -> Result<()>;
async fn authorize(
&self,
info: Arc<MinerInfo>,
auth: &Self::Authorize,
) -> Result<Self::Authorized>;
async fn subscribe(
&self,
info: Arc<MinerInfo>,
subscribe_info: &Self::Subscribe,
) -> Result<Self::SubscribeResult>;
}
#[async_trait]
pub trait DataProvider: Sync + Send + Clone {
type Job: DeserializeOwned + Serialize + Sync + Send + Clone + Debug;
async fn init(&self) -> Result<()>;
async fn get_job(&self) -> Result<Self::Job>;
async fn poll_template(&self) -> Result<bool>;
}
#[async_trait]
pub trait BlockValidator: Sync + Send + Clone {
type Submit: DeserializeOwned + Serialize + Sync + Send + Clone + Debug;
type Job: DeserializeOwned + Serialize + Sync + Send + Clone + Debug;
async fn init(&self) -> Result<()>;
async fn validate_share(&self, info: Arc<MinerInfo>, share: Self::Submit) -> Result<bool>;
}