Skip to main content

dfns_sdk_rust/staking/
mod.rs

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