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
use crate::auth_types::AuthAccount;
use crate::errors::TerraRustAPIError;
use crate::staking_types::{Validator, ValidatorDelegation, ValidatorUnbondingDelegation};
use crate::{LCDResult, LCDResultVec, LCDTypeValue, Terra};

pub struct Auth<'a> {
    terra: &'a Terra,
}
impl Auth<'_> {
    pub fn create(terra: &'_ Terra) -> Auth<'_> {
        Auth { terra }
    }
    pub async fn account(
        &self,
        account_address: &str,
    ) -> Result<LCDResult<LCDTypeValue<AuthAccount>>, TerraRustAPIError> {
        self.terra
            .send_cmd::<LCDResult<LCDTypeValue<AuthAccount>>>(
                &format!("/auth/accounts/{}", account_address),
                None,
            )
            .await
    }
    /// all delegations for a given account
    pub async fn validator_delegations(
        &self,
        account_address: &str,
    ) -> Result<LCDResultVec<ValidatorDelegation>, TerraRustAPIError> {
        self.terra
            .send_cmd::<LCDResultVec<ValidatorDelegation>>(
                &format!("/staking/delegators/{}/delegations", account_address),
                None,
            )
            .await
    }
    /// all unbonding delegations for a given account
    pub async fn validator_unbonding_delegations(
        &self,
        account_address: &str,
    ) -> Result<LCDResult<ValidatorUnbondingDelegation>, TerraRustAPIError> {
        self.terra
            .send_cmd::<LCDResult<ValidatorUnbondingDelegation>>(
                &format!(
                    "/staking/delegators/{}/unbonding_delegations",
                    account_address
                ),
                None,
            )
            .await
    }
    /// all validators for a given account
    pub async fn delegated_validators(
        &self,
        account_address: &str,
    ) -> Result<LCDResult<Vec<Validator>>, TerraRustAPIError> {
        self.terra
            .send_cmd::<LCDResult<Vec<Validator>>>(
                &format!("/staking/delegators/{}/validators", account_address),
                None,
            )
            .await
    }
}