dfns-sdk-rust 0.2.0

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

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

/// Delegated client for networks operations. Signed operations are split into
/// init/complete pairs so the challenge can be signed on the user side.
#[derive(Clone)]
pub struct DelegatedNetworksClient {
    client: crate::client::Client,
}

impl DelegatedNetworksClient {
    pub fn new(client: crate::client::Client) -> Self {
        DelegatedNetworksClient { 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
    }

    /// Starts delegated signing for updateCantonValidator: returns the challenge to sign.
    /// Pass the signed assertion to update_canton_validator_complete with the same arguments.
    pub async fn update_canton_validator_init(
        &self,
        network: String,
        validator_id: String,
        body: UpdateCantonValidatorRequest,
    ) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
        let path = format!(
            "/networks/{}/validators/{}",
            urlencoding::encode(&network),
            urlencoding::encode(&validator_id)
        );
        let body = serde_json::to_value(&body)?;
        self.client
            .create_user_action_challenge(reqwest::Method::PUT, &path, Some(&body))
            .await
    }

    /// Finishes delegated signing for updateCantonValidator: submits the signed challenge
    /// and issues the request.
    pub async fn update_canton_validator_complete(
        &self,
        network: String,
        validator_id: String,
        body: UpdateCantonValidatorRequest,
        challenge_identifier: String,
        assertion: crate::signer::CredentialAssertion,
    ) -> Result<UpdateCantonValidatorResponse, crate::error::Error> {
        let path = format!(
            "/networks/{}/validators/{}",
            urlencoding::encode(&network),
            urlencoding::encode(&validator_id)
        );
        let body = serde_json::to_value(&body)?;
        let user_action = self
            .client
            .complete_user_action_signing(challenge_identifier, &assertion)
            .await?;
        self.client
            .request_with_user_action::<UpdateCantonValidatorResponse>(
                reqwest::Method::PUT,
                &path,
                Some(&body),
                &user_action,
            )
            .await
    }

    /// Starts delegated signing for deleteCantonValidator: returns the challenge to sign.
    /// Pass the signed assertion to delete_canton_validator_complete with the same arguments.
    pub async fn delete_canton_validator_init(
        &self,
        network: String,
        validator_id: String,
    ) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
        let path = format!(
            "/networks/{}/validators/{}",
            urlencoding::encode(&network),
            urlencoding::encode(&validator_id)
        );
        self.client
            .create_user_action_challenge(reqwest::Method::DELETE, &path, None)
            .await
    }

    /// Finishes delegated signing for deleteCantonValidator: submits the signed challenge
    /// and issues the request.
    pub async fn delete_canton_validator_complete(
        &self,
        network: String,
        validator_id: String,
        challenge_identifier: String,
        assertion: crate::signer::CredentialAssertion,
    ) -> Result<DeleteCantonValidatorResponse, crate::error::Error> {
        let path = format!(
            "/networks/{}/validators/{}",
            urlencoding::encode(&network),
            urlencoding::encode(&validator_id)
        );
        let user_action = self
            .client
            .complete_user_action_signing(challenge_identifier, &assertion)
            .await?;
        self.client
            .request_with_user_action::<DeleteCantonValidatorResponse>(
                reqwest::Method::DELETE,
                &path,
                None,
                &user_action,
            )
            .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
    }

    /// Starts delegated signing for createCantonValidator: returns the challenge to sign.
    /// Pass the signed assertion to create_canton_validator_complete with the same arguments.
    pub async fn create_canton_validator_init(
        &self,
        network: String,
        body: CreateCantonValidatorRequest,
    ) -> Result<crate::signer::UserActionChallenge, crate::error::Error> {
        let path = format!("/networks/{}/validators", urlencoding::encode(&network));
        let body = serde_json::to_value(&body)?;
        self.client
            .create_user_action_challenge(reqwest::Method::POST, &path, Some(&body))
            .await
    }

    /// Finishes delegated signing for createCantonValidator: submits the signed challenge
    /// and issues the request.
    pub async fn create_canton_validator_complete(
        &self,
        network: String,
        body: CreateCantonValidatorRequest,
        challenge_identifier: String,
        assertion: crate::signer::CredentialAssertion,
    ) -> Result<CreateCantonValidatorResponse, crate::error::Error> {
        let path = format!("/networks/{}/validators", urlencoding::encode(&network));
        let body = serde_json::to_value(&body)?;
        let user_action = self
            .client
            .complete_user_action_signing(challenge_identifier, &assertion)
            .await?;
        self.client
            .request_with_user_action::<CreateCantonValidatorResponse>(
                reqwest::Method::POST,
                &path,
                Some(&body),
                &user_action,
            )
            .await
    }
}