Skip to main content

monedero_solana_stake/
lib.rs

1mod error;
2pub use error::Error;
3use solana_pubkey::Pubkey;
4mod account;
5mod client;
6mod create;
7mod delegate;
8mod withdrawal;
9pub use account::*;
10use {
11    std::fmt::{Debug, Display, Formatter},
12    wasm_client_solana::SolanaRpcClient,
13};
14pub type Result<T> = std::result::Result<T, Error>;
15
16#[derive(Clone)]
17pub struct StakeClient {
18    rpc: SolanaRpcClient,
19    owner: Pubkey,
20}
21
22impl Display for StakeClient {
23    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
24        self.fmt_common(f)
25    }
26}
27impl Debug for StakeClient {
28    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
29        self.fmt_common(f)
30    }
31}
32
33impl StakeClient {
34    pub fn new(owner: &Pubkey, rpc: &SolanaRpcClient) -> Self {
35        Self {
36            owner: *owner,
37            rpc: rpc.clone(),
38        }
39    }
40
41    pub async fn minimum_delegation(&self) -> Result<u64> {
42        Ok(self.rpc.get_stake_minimum_delegation().await?)
43    }
44
45    pub fn owner(&self) -> &Pubkey {
46        &self.owner
47    }
48
49    fn fmt_common(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
50        write!(f, "[StakeClient][{}]", self.owner)
51    }
52}