Skip to main content

dfns_sdk_rust/networks/
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 networks operations.
9#[derive(Clone)]
10pub struct NetworksClient {
11    client: crate::client::Client,
12}
13
14impl NetworksClient {
15    pub fn new(client: crate::client::Client) -> Self {
16        NetworksClient { client }
17    }
18
19    /// Gets real-time fee details for a given network, allowing users to make decisions based on their preferences for transaction speed/priority. Three levels of priority will be displayed: `slow`, `standard`, `fast`.
20    pub async fn estimate_fees(
21        &self,
22        query: Option<EstimateFeesQuery>,
23    ) -> Result<serde_json::Value, crate::error::Error> {
24        let mut path = String::from("/networks/fees");
25        if let Some(query) = &query {
26            let mut q: Vec<String> = Vec::new();
27            q.push(format!(
28                "network={}",
29                urlencoding::encode(&query.network.to_string())
30            ));
31            if !q.is_empty() {
32                path.push('?');
33                path.push_str(&q.join("&"));
34            }
35        }
36        self.client
37            .request::<serde_json::Value>(reqwest::Method::GET, &path, None, false)
38            .await
39    }
40
41    /// Call a read-only function on a smart contract. In Solidity, these are functions with the state mutability set to `view`.
42    ///
43    ///   <Note>
44    ///   Currently only works on EVM compatible chains.
45    pub async fn call_function(
46        &self,
47        network: String,
48        body: CallFunctionRequest,
49    ) -> Result<serde_json::Value, crate::error::Error> {
50        let path = format!("/networks/{}/call-function", urlencoding::encode(&network));
51        let body = serde_json::to_value(&body)?;
52        self.client
53            .request::<serde_json::Value>(reqwest::Method::POST, &path, Some(&body), false)
54            .await
55    }
56
57    /// Return a configured Canton Validator in your organization.
58    pub async fn get_canton_validator(
59        &self,
60        network: String,
61        validator_id: String,
62    ) -> Result<GetCantonValidatorResponse, crate::error::Error> {
63        let path = format!(
64            "/networks/{}/validators/{}",
65            urlencoding::encode(&network),
66            urlencoding::encode(&validator_id)
67        );
68        self.client
69            .request::<GetCantonValidatorResponse>(reqwest::Method::GET, &path, None, false)
70            .await
71    }
72
73    /// Update an existing Canton Validator configuration.
74    ///   
75    ///   Read details about the process [here](https://docs.dfns.co/networks/canton).
76    pub async fn update_canton_validator(
77        &self,
78        network: String,
79        validator_id: String,
80        body: UpdateCantonValidatorRequest,
81    ) -> Result<UpdateCantonValidatorResponse, crate::error::Error> {
82        let path = format!(
83            "/networks/{}/validators/{}",
84            urlencoding::encode(&network),
85            urlencoding::encode(&validator_id)
86        );
87        let body = serde_json::to_value(&body)?;
88        self.client
89            .request::<UpdateCantonValidatorResponse>(
90                reqwest::Method::PUT,
91                &path,
92                Some(&body),
93                true,
94            )
95            .await
96    }
97
98    /// Delete a specific Canton Validator configuration.
99    pub async fn delete_canton_validator(
100        &self,
101        network: String,
102        validator_id: String,
103    ) -> Result<DeleteCantonValidatorResponse, crate::error::Error> {
104        let path = format!(
105            "/networks/{}/validators/{}",
106            urlencoding::encode(&network),
107            urlencoding::encode(&validator_id)
108        );
109        self.client
110            .request::<DeleteCantonValidatorResponse>(reqwest::Method::DELETE, &path, None, true)
111            .await
112    }
113
114    /// Retrieve the list of configured Canton Validators in your organization.
115    pub async fn list_canton_validators(
116        &self,
117        network: String,
118        query: Option<ListCantonValidatorsQuery>,
119    ) -> Result<ListCantonValidatorsResponse, crate::error::Error> {
120        let mut path = format!("/networks/{}/validators", urlencoding::encode(&network));
121        if let Some(query) = &query {
122            let mut q: Vec<String> = Vec::new();
123            if let Some(v) = &query.limit {
124                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
125            }
126            if let Some(v) = &query.pagination_token {
127                q.push(format!(
128                    "paginationToken={}",
129                    urlencoding::encode(&v.to_string())
130                ));
131            }
132            if !q.is_empty() {
133                path.push('?');
134                path.push_str(&q.join("&"));
135            }
136        }
137        self.client
138            .request::<ListCantonValidatorsResponse>(reqwest::Method::GET, &path, None, false)
139            .await
140    }
141
142    /// Link a Canton Validator to your organization. This is required in order to create wallets or interact with the Canton network.
143    ///
144    ///   The `Shared` option allows you to use a shared validator hosted by Dfns and get started in seconds, while the `Custom` option allows you to connect your own validator and ledger nodes using OAuth2 authentication.
145    ///
146    pub async fn create_canton_validator(
147        &self,
148        network: String,
149        body: CreateCantonValidatorRequest,
150    ) -> Result<CreateCantonValidatorResponse, crate::error::Error> {
151        let path = format!("/networks/{}/validators", urlencoding::encode(&network));
152        let body = serde_json::to_value(&body)?;
153        self.client
154            .request::<CreateCantonValidatorResponse>(
155                reqwest::Method::POST,
156                &path,
157                Some(&body),
158                true,
159            )
160            .await
161    }
162}