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
use crate::Result;
use async_trait::async_trait;
use serde::{de::DeserializeOwned, Serialize};
use std::fmt::Debug;

pub trait StratumPackets {
    type Authorize: Authorize;
    type Capabilities: Capabilities;
    type Submit: Submit;
    type Subscribe: Subscribe;
    type SuggestDifficulty: SuggestDifficulty;
    type SuggestTarget: SuggestTarget;
    type Notify: Notify;
    type SetDifficulty: SetDifficulty;
    type SetExtraNonce: SetExtraNonce;
    type SetGoal: SetGoal;
}

#[async_trait]
pub trait StratumManager: Sync + Send {
    //@todo change to stratum params
    type Params: StratumPackets + DeserializeOwned + Serialize;

    //@todo maybe redo this -> See autonomy
    async fn authorize(&self, auth: &<Self::Params as StratumPackets>::Authorize) -> Result<bool>;
    async fn submit(&self, share: &<Self::Params as StratumPackets>::Submit) -> Result<bool>;
    async fn subscribe(
        &self,
        subscribe_info: &<Self::Params as StratumPackets>::Subscribe,
    ) -> Result<bool>;
}

//@todo probably rename some of these, right now I just put the name of the param  in there,
//but some more syntctical names could make more sense in the future. Not high priority. P0
//(Prority 0)
// ===== Stratum Param Traits ===== //
// @todo review if we need serialize and deserializeOwned here.
// Review if we need all these other trait params;
pub trait Authorize: DeserializeOwned + Serialize + Sync + Send + Clone + Debug {}
pub trait Capabilities: DeserializeOwned + Serialize + Sync + Send + Clone + Debug {}
pub trait Submit: DeserializeOwned + Serialize + Sync + Send + Clone + Debug {}
pub trait Subscribe: DeserializeOwned + Serialize + Sync + Send + Clone + Debug {}
pub trait SuggestDifficulty: DeserializeOwned + Serialize + Sync + Send + Clone + Debug {}
pub trait SuggestTarget: DeserializeOwned + Serialize + Sync + Send + Clone + Debug {}
pub trait Notify: DeserializeOwned + Serialize + Sync + Send + Clone + Debug {}
pub trait SetDifficulty: DeserializeOwned + Serialize + Sync + Send + Clone + Debug {}
pub trait SetExtraNonce: DeserializeOwned + Serialize + Sync + Send + Clone + Debug {}
pub trait SetGoal: DeserializeOwned + Serialize + Sync + Send + Clone + Debug {}

//@todo I don't actually think we need any of the above traits? We could just put all the impls
//in here - taht way we drastically reduce the amount of boilerplate from my understanding.
//It makes it less child proof (As someone has to specifically impl Authorize for Authorize
//struct), but if they don't need specific functions it might be worth it.
//
//The only way I'd say we don't do this is if the params need functions baked into it. Which I
//think they probably might?
// pub trait StratumPackets: DeserializeOwned + Serialize + Sync + Send + Clone {