dfns-sdk-rust 0.2.0

Dfns API SDK for Rust
Documentation
// Code generated by rust-sdk-generator. DO NOT EDIT.

pub mod delegated;
pub mod types;

#[allow(unused_imports)]
use types::*;

/// Client for networks operations.
#[derive(Clone)]
pub struct NetworksClient {
    client: crate::client::Client,
}

impl NetworksClient {
    pub fn new(client: crate::client::Client) -> Self {
        NetworksClient { client }
    }

    /// 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`.
    pub async fn estimate_fees(
        &self,
        query: Option<EstimateFeesQuery>,
    ) -> Result<serde_json::Value, crate::error::Error> {
        let mut path = String::from("/networks/fees");
        if let Some(query) = &query {
            let mut q: Vec<String> = Vec::new();
            q.push(format!(
                "network={}",
                urlencoding::encode(&query.network.to_string())
            ));
            if !q.is_empty() {
                path.push('?');
                path.push_str(&q.join("&"));
            }
        }
        self.client
            .request::<serde_json::Value>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Call a read-only function on a smart contract. In Solidity, these are functions with the state mutability set to `view`.
    ///
    ///   <Note>
    ///   Currently only works on EVM compatible chains.
    pub async fn call_function(
        &self,
        network: String,
        body: CallFunctionRequest,
    ) -> Result<serde_json::Value, crate::error::Error> {
        let path = format!("/networks/{}/call-function", urlencoding::encode(&network));
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<serde_json::Value>(reqwest::Method::POST, &path, Some(&body), false)
            .await
    }

    /// Return a configured Canton Validator in your organization.
    pub async fn get_canton_validator(
        &self,
        network: String,
        validator_id: String,
    ) -> Result<GetCantonValidatorResponse, crate::error::Error> {
        let path = format!(
            "/networks/{}/validators/{}",
            urlencoding::encode(&network),
            urlencoding::encode(&validator_id)
        );
        self.client
            .request::<GetCantonValidatorResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Update an existing Canton Validator configuration.
    ///   
    ///   Read details about the process [here](https://docs.dfns.co/networks/canton).
    pub async fn update_canton_validator(
        &self,
        network: String,
        validator_id: String,
        body: UpdateCantonValidatorRequest,
    ) -> Result<UpdateCantonValidatorResponse, crate::error::Error> {
        let path = format!(
            "/networks/{}/validators/{}",
            urlencoding::encode(&network),
            urlencoding::encode(&validator_id)
        );
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<UpdateCantonValidatorResponse>(
                reqwest::Method::PUT,
                &path,
                Some(&body),
                true,
            )
            .await
    }

    /// Delete a specific Canton Validator configuration.
    pub async fn delete_canton_validator(
        &self,
        network: String,
        validator_id: String,
    ) -> Result<DeleteCantonValidatorResponse, crate::error::Error> {
        let path = format!(
            "/networks/{}/validators/{}",
            urlencoding::encode(&network),
            urlencoding::encode(&validator_id)
        );
        self.client
            .request::<DeleteCantonValidatorResponse>(reqwest::Method::DELETE, &path, None, true)
            .await
    }

    /// Retrieve the list of configured Canton Validators in your organization.
    pub async fn list_canton_validators(
        &self,
        network: String,
        query: Option<ListCantonValidatorsQuery>,
    ) -> Result<ListCantonValidatorsResponse, crate::error::Error> {
        let mut path = format!("/networks/{}/validators", urlencoding::encode(&network));
        if let Some(query) = &query {
            let mut q: Vec<String> = Vec::new();
            if let Some(v) = &query.limit {
                q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
            }
            if let Some(v) = &query.pagination_token {
                q.push(format!(
                    "paginationToken={}",
                    urlencoding::encode(&v.to_string())
                ));
            }
            if !q.is_empty() {
                path.push('?');
                path.push_str(&q.join("&"));
            }
        }
        self.client
            .request::<ListCantonValidatorsResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Link a Canton Validator to your organization. This is required in order to create wallets or interact with the Canton network.
    ///
    ///   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.
    ///
    pub async fn create_canton_validator(
        &self,
        network: String,
        body: CreateCantonValidatorRequest,
    ) -> Result<CreateCantonValidatorResponse, crate::error::Error> {
        let path = format!("/networks/{}/validators", urlencoding::encode(&network));
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<CreateCantonValidatorResponse>(
                reqwest::Method::POST,
                &path,
                Some(&body),
                true,
            )
            .await
    }
}