koios_sdk/api/
network.rs

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
use crate::{
    error::Result,
    models::network::{CliProtocolParams, Genesis, ParamUpdate, ReserveWithdrawal, Tip, Totals},
    types::EpochNo,
    Client,
};
use urlencoding::encode;

impl Client {
    /// Get the tip info about the latest block seen by chain
    pub async fn get_tip(&self) -> Result<Vec<Tip>> {
        self.get("/tip").await
    }

    /// Get the Genesis parameters used to start specific era on chain
    pub async fn get_genesis(&self) -> Result<Vec<Genesis>> {
        self.get("/genesis").await
    }

    /// Get the circulating utxo, treasury, rewards, supply and reserves in
    /// lovelace for specified epoch, all epochs if empty
    pub async fn get_totals(&self, epoch_no: Option<EpochNo>) -> Result<Vec<Totals>> {
        let endpoint = match epoch_no {
            Some(epoch) => format!("/totals?_epoch_no={}", encode(epoch.value())),
            None => "/totals".to_string(),
        };
        self.get(&endpoint).await
    }

    /// Get all parameter update proposals submitted to the chain starting Shelley era
    pub async fn get_param_updates(&self) -> Result<Vec<ParamUpdate>> {
        self.get("/param_updates").await
    }

    /// Get Current Protocol Parameters as published by cardano-cli
    pub async fn get_cli_protocol_params(&self) -> Result<Vec<CliProtocolParams>> {
        self.get("/cli_protocol_params").await
    }

    /// List of all withdrawals from reserves against stake accounts
    pub async fn get_reserve_withdrawals(&self) -> Result<Vec<ReserveWithdrawal>> {
        self.get("/reserve_withdrawals").await
    }

    /// List of all withdrawals from treasury against stake accounts
    pub async fn get_treasury_withdrawals(&self) -> Result<Vec<ReserveWithdrawal>> {
        self.get("/treasury_withdrawals").await
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use tokio;

    #[tokio::test]
    async fn test_get_tip() {
        let client = Client::new().unwrap();
        let result = client.get_tip().await;
        assert!(result.is_ok());
    }

    #[tokio::test]
    async fn test_get_genesis() {
        let client = Client::new().unwrap();
        let result = client.get_genesis().await;
        assert!(result.is_ok());
    }

    #[tokio::test]
    async fn test_get_totals() {
        let client = Client::new().unwrap();
        let result = client.get_totals(None).await;
        assert!(result.is_ok());

        let result = client.get_totals(Some(EpochNo::new("320"))).await;
        assert!(result.is_ok());
    }

    // Add more tests for other endpoints...
}