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 vaults operations.
#[derive(Clone)]
pub struct VaultsClient {
    client: crate::client::Client,
}

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

    /// Retrieves the list of Vaults in your organization.
    pub async fn list_vaults(
        &self,
        query: Option<ListVaultsQuery>,
    ) -> Result<ListVaultsResponse, crate::error::Error> {
        let mut path = String::from("/vaults");
        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::<ListVaultsResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Creates a new Vault.
    pub async fn create_vault(
        &self,
        body: CreateVaultRequest,
    ) -> Result<CreateVaultResponse, crate::error::Error> {
        let path = String::from("/vaults");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<CreateVaultResponse>(reqwest::Method::POST, &path, Some(&body), true)
            .await
    }

    /// Creates a vault address (managed wallet) on an EVM or Bitcoin network.
    pub async fn create_vault_address(
        &self,
        vault_id: String,
        body: CreateVaultAddressRequest,
    ) -> Result<CreateVaultAddressResponse, crate::error::Error> {
        let path = format!("/vaults/{}/addresses", urlencoding::encode(&vault_id));
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<CreateVaultAddressResponse>(reqwest::Method::POST, &path, Some(&body), true)
            .await
    }

    /// Lists a vault's locks, active and released.
    pub async fn list_vault_locks(
        &self,
        vault_id: String,
        query: Option<ListVaultLocksQuery>,
    ) -> Result<ListVaultLocksResponse, crate::error::Error> {
        let mut path = format!("/vaults/{}/locks", urlencoding::encode(&vault_id));
        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 let Some(v) = &query.network {
                q.push(format!("network={}", urlencoding::encode(&v.to_string())));
            }
            if let Some(v) = &query.tid {
                q.push(format!("tid={}", urlencoding::encode(&v.to_string())));
            }
            if !q.is_empty() {
                path.push('?');
                path.push_str(&q.join("&"));
            }
        }
        self.client
            .request::<ListVaultLocksResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Locks funds from the vault's available balance for off-chain settlement or escrow.
    pub async fn create_vault_lock(
        &self,
        vault_id: String,
        body: CreateVaultLockRequest,
    ) -> Result<CreateVaultLockResponse, crate::error::Error> {
        let path = format!("/vaults/{}/locks", urlencoding::encode(&vault_id));
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<CreateVaultLockResponse>(reqwest::Method::POST, &path, Some(&body), true)
            .await
    }

    /// Creates a transfer out of a vault, reserving the amount and estimated fee from the vault's available balance.
    pub async fn create_vault_transfer(
        &self,
        vault_id: String,
        body: CreateVaultTransferRequest,
    ) -> Result<CreateVaultTransferResponse, crate::error::Error> {
        let path = format!("/vaults/{}/transfers", urlencoding::encode(&vault_id));
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<CreateVaultTransferResponse>(reqwest::Method::POST, &path, Some(&body), true)
            .await
    }

    /// Retrieves a vault lock by its ID.
    pub async fn get_vault_lock(
        &self,
        vault_id: String,
        lock_id: String,
    ) -> Result<GetVaultLockResponse, crate::error::Error> {
        let path = format!(
            "/vaults/{}/locks/{}",
            urlencoding::encode(&vault_id),
            urlencoding::encode(&lock_id)
        );
        self.client
            .request::<GetVaultLockResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Releases a lock, returning the locked funds to the vault's available balance. Owner only.
    pub async fn delete_vault_lock(
        &self,
        vault_id: String,
        lock_id: String,
    ) -> Result<DeleteVaultLockResponse, crate::error::Error> {
        let path = format!(
            "/vaults/{}/locks/{}",
            urlencoding::encode(&vault_id),
            urlencoding::encode(&lock_id)
        );
        self.client
            .request::<DeleteVaultLockResponse>(reqwest::Method::DELETE, &path, None, true)
            .await
    }

    /// Retrieves a Vault by its ID.
    pub async fn get_vault(
        &self,
        vault_id: String,
    ) -> Result<GetVaultResponse, crate::error::Error> {
        let path = format!("/vaults/{}", urlencoding::encode(&vault_id));
        self.client
            .request::<GetVaultResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Updates an existing Vault.
    pub async fn update_vault(
        &self,
        vault_id: String,
        body: UpdateVaultRequest,
    ) -> Result<UpdateVaultResponse, crate::error::Error> {
        let path = format!("/vaults/{}", urlencoding::encode(&vault_id));
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<UpdateVaultResponse>(reqwest::Method::PUT, &path, Some(&body), true)
            .await
    }

    /// Lists a vault's assets with balances (available/quarantined/locked) and USD valuation.
    pub async fn list_vault_assets(
        &self,
        vault_id: String,
        query: Option<ListVaultAssetsQuery>,
    ) -> Result<ListVaultAssetsResponse, crate::error::Error> {
        let mut path = format!("/vaults/{}/assets", urlencoding::encode(&vault_id));
        if let Some(query) = &query {
            let mut q: Vec<String> = Vec::new();
            if let Some(v) = &query.show_unverified {
                q.push(format!(
                    "showUnverified={}",
                    urlencoding::encode(&v.to_string())
                ));
            }
            if let Some(v) = &query.network {
                q.push(format!("network={}", urlencoding::encode(&v.to_string())));
            }
            if !q.is_empty() {
                path.push('?');
                path.push_str(&q.join("&"));
            }
        }
        self.client
            .request::<ListVaultAssetsResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Lists a vault's balance entries.
    pub async fn list_vault_balances(
        &self,
        vault_id: String,
        query: Option<ListVaultBalancesQuery>,
    ) -> Result<ListVaultBalancesResponse, crate::error::Error> {
        let mut path = format!("/vaults/{}/balances", urlencoding::encode(&vault_id));
        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 let Some(v) = &query.kind {
                q.push(format!("kind={}", urlencoding::encode(&v.to_string())));
            }
            if let Some(v) = &query.network {
                q.push(format!("network={}", urlencoding::encode(&v.to_string())));
            }
            if let Some(v) = &query.tid {
                q.push(format!("tid={}", urlencoding::encode(&v.to_string())));
            }
            if !q.is_empty() {
                path.push('?');
                path.push_str(&q.join("&"));
            }
        }
        self.client
            .request::<ListVaultBalancesResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Releases quarantined funds into the available balance.
    pub async fn release_quarantine(
        &self,
        vault_id: String,
        quarantine_id: String,
        body: ReleaseQuarantineRequest,
    ) -> Result<ReleaseQuarantineResponse, crate::error::Error> {
        let path = format!(
            "/vaults/{}/quarantines/{}/release",
            urlencoding::encode(&vault_id),
            urlencoding::encode(&quarantine_id)
        );
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<ReleaseQuarantineResponse>(reqwest::Method::POST, &path, Some(&body), true)
            .await
    }

    /// Add tags to a vault.
    pub async fn tag_vault(
        &self,
        vault_id: String,
        body: TagVaultRequest,
    ) -> Result<TagVaultResponse, crate::error::Error> {
        let path = format!("/vaults/{}/tags", urlencoding::encode(&vault_id));
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<TagVaultResponse>(reqwest::Method::PUT, &path, Some(&body), true)
            .await
    }

    /// Removes the specified tags from a vault.
    pub async fn untag_vault(
        &self,
        vault_id: String,
        body: UntagVaultRequest,
    ) -> Result<UntagVaultResponse, crate::error::Error> {
        let path = format!("/vaults/{}/tags", urlencoding::encode(&vault_id));
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<UntagVaultResponse>(reqwest::Method::DELETE, &path, Some(&body), true)
            .await
    }
}