Skip to main content

dfns_sdk_rust/staking/
mod.rs

1// Code generated by rust-sdk-generator. DO NOT EDIT.
2
3pub mod delegated;
4pub mod types;
5
6#[allow(unused_imports)]
7use types::*;
8
9/// Client for staking operations.
10#[derive(Clone)]
11pub struct StakingClient {
12    client: crate::client::Client,
13}
14
15impl StakingClient {
16    pub fn new(client: crate::client::Client) -> Self {
17        StakingClient { client }
18    }
19
20    /// Retrieve the list of stakes.
21    pub async fn list_stakes(
22        &self,
23        query: Option<ListStakesQuery>,
24    ) -> Result<ListStakesResponse, crate::error::Error> {
25        let mut path = String::from("/staking/stakes");
26        if let Some(query) = &query {
27            let mut q: Vec<String> = Vec::new();
28            if let Some(v) = &query.limit {
29                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
30            }
31            if let Some(v) = &query.pagination_token {
32                q.push(format!(
33                    "paginationToken={}",
34                    urlencoding::encode(&v.to_string())
35                ));
36            }
37            if !q.is_empty() {
38                path.push('?');
39                path.push_str(&q.join("&"));
40            }
41        }
42        self.client
43            .request::<ListStakesResponse>(reqwest::Method::GET, &path, None, false)
44            .await
45    }
46
47    /// Create a new stake.
48    pub async fn create_stake(
49        &self,
50        body: CreateStakeRequest,
51    ) -> Result<CreateStakeResponse, crate::error::Error> {
52        let path = String::from("/staking/stakes");
53        let body = serde_json::to_value(&body)?;
54        self.client
55            .request::<CreateStakeResponse>(reqwest::Method::POST, &path, Some(&body), true)
56            .await
57    }
58
59    /// Retrieve the list of actions for a specific stake.
60    pub async fn list_stake_actions(
61        &self,
62        stake_id: String,
63        query: Option<ListStakeActionsQuery>,
64    ) -> Result<ListStakeActionsResponse, crate::error::Error> {
65        let mut path = format!("/staking/stakes/{}/actions", urlencoding::encode(&stake_id));
66        if let Some(query) = &query {
67            let mut q: Vec<String> = Vec::new();
68            if let Some(v) = &query.limit {
69                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
70            }
71            if let Some(v) = &query.pagination_token {
72                q.push(format!(
73                    "paginationToken={}",
74                    urlencoding::encode(&v.to_string())
75                ));
76            }
77            if !q.is_empty() {
78                path.push('?');
79                path.push_str(&q.join("&"));
80            }
81        }
82        self.client
83            .request::<ListStakeActionsResponse>(reqwest::Method::GET, &path, None, false)
84            .await
85    }
86
87    /// Create a new action for an existing stake.
88    pub async fn create_stake_action(
89        &self,
90        stake_id: String,
91        body: CreateStakeActionRequest,
92    ) -> Result<CreateStakeActionResponse, crate::error::Error> {
93        let path = format!("/staking/stakes/{}/actions", urlencoding::encode(&stake_id));
94        let body = serde_json::to_value(&body)?;
95        self.client
96            .request::<CreateStakeActionResponse>(reqwest::Method::POST, &path, Some(&body), true)
97            .await
98    }
99
100    /// Retrieve the details of a specific stake.
101    pub async fn get_stakes(
102        &self,
103        stake_id: String,
104        query: Option<GetStakesQuery>,
105    ) -> Result<GetStakesResponse, crate::error::Error> {
106        let mut path = format!("/staking/stakes/{}", urlencoding::encode(&stake_id));
107        if let Some(query) = &query {
108            let mut q: Vec<String> = Vec::new();
109            if let Some(v) = &query.limit {
110                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
111            }
112            if let Some(v) = &query.pagination_token {
113                q.push(format!(
114                    "paginationToken={}",
115                    urlencoding::encode(&v.to_string())
116                ));
117            }
118            if !q.is_empty() {
119                path.push('?');
120                path.push_str(&q.join("&"));
121            }
122        }
123        self.client
124            .request::<GetStakesResponse>(reqwest::Method::GET, &path, None, false)
125            .await
126    }
127
128    /// Retrieves the rewards linked to a specific stake.
129    pub async fn get_stake_rewards(
130        &self,
131        stake_id: String,
132    ) -> Result<GetStakeRewardsResponse, crate::error::Error> {
133        let path = format!("/staking/stakes/{}/rewards", urlencoding::encode(&stake_id));
134        self.client
135            .request::<GetStakeRewardsResponse>(reqwest::Method::GET, &path, None, false)
136            .await
137    }
138}