Skip to main content

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