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

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

    /// Retrieves the list of address watches in your organization. Pagination is supported via limit and paginationToken parameters.
    pub async fn list_address_watches(
        &self,
        query: Option<ListAddressWatchesQuery>,
    ) -> Result<ListAddressWatchesResponse, crate::error::Error> {
        let mut path = String::from("/address-watches");
        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::<ListAddressWatchesResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Registers an on chain address to watch. An address watch is not controlled by Dfns: it holds no key, it cannot sign or move funds. The indexer matches on chain activity touching the address and sends the corresponding webhooks.
    ///
    /// The address must already exist on chain and is normalized to the form the indexer matches on (lowercase for EVM networks). Only networks that support address watches are accepted. A given address can only be watched once per network within an organization while the watch is Active.
    pub async fn create_address_watch(
        &self,
        body: CreateAddressWatchRequest,
    ) -> Result<CreateAddressWatchResponse, crate::error::Error> {
        let path = String::from("/address-watches");
        let body = serde_json::to_value(&body)?;
        self.client
            .request::<CreateAddressWatchResponse>(reqwest::Method::POST, &path, Some(&body), true)
            .await
    }

    /// Retrieves an address watch by its ID.
    pub async fn get_address_watch(
        &self,
        address_watch_id: String,
    ) -> Result<GetAddressWatchResponse, crate::error::Error> {
        let path = format!(
            "/address-watches/{}",
            urlencoding::encode(&address_watch_id)
        );
        self.client
            .request::<GetAddressWatchResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Retrieves the list of assets held by the address watch, as tracked by the indexer. Balances are tracked from the moment the watch is created.
    pub async fn get_address_watch_assets(
        &self,
        address_watch_id: String,
        query: Option<GetAddressWatchAssetsQuery>,
    ) -> Result<GetAddressWatchAssetsResponse, crate::error::Error> {
        let mut path = format!(
            "/address-watches/{}/assets",
            urlencoding::encode(&address_watch_id)
        );
        if let Some(query) = &query {
            let mut q: Vec<String> = Vec::new();
            if let Some(v) = &query.net_worth {
                q.push(format!("netWorth={}", urlencoding::encode(&v.to_string())));
            }
            if !q.is_empty() {
                path.push('?');
                path.push_str(&q.join("&"));
            }
        }
        self.client
            .request::<GetAddressWatchAssetsResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }

    /// Retrieves a list of decoded blockchain events indexed for the specified address watch.
    ///
    /// Blockchain events are not value transfers: asset and token transfers are listed by
    /// [Get Address Watch History](https://docs.dfns.co/api-reference/address-watches/get-address-watch-history) instead.
    pub async fn get_address_watch_blockchain_events(
        &self,
        address_watch_id: String,
        query: Option<GetAddressWatchBlockchainEventsQuery>,
    ) -> Result<GetAddressWatchBlockchainEventsResponse, crate::error::Error> {
        let mut path = format!(
            "/address-watches/{}/blockchain-events",
            urlencoding::encode(&address_watch_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.name {
                q.push(format!("name={}", urlencoding::encode(&v.to_string())));
            }
            if let Some(v) = &query.contract {
                q.push(format!("contract={}", urlencoding::encode(&v.to_string())));
            }
            if let Some(v) = &query.tx_hash {
                q.push(format!("txHash={}", urlencoding::encode(&v.to_string())));
            }
            if !q.is_empty() {
                path.push('?');
                path.push_str(&q.join("&"));
            }
        }
        self.client
            .request::<GetAddressWatchBlockchainEventsResponse>(
                reqwest::Method::GET,
                &path,
                None,
                false,
            )
            .await
    }

    /// Retrieves the list of indexed on chain activities for the specified address watch.
    ///
    /// The list reflects the indexed on chain activity from the moment the watch was created. Events from before the watch are not backfilled.
    pub async fn get_address_watch_history(
        &self,
        address_watch_id: String,
        query: Option<GetAddressWatchHistoryQuery>,
    ) -> Result<GetAddressWatchHistoryResponse, crate::error::Error> {
        let mut path = format!(
            "/address-watches/{}/history",
            urlencoding::encode(&address_watch_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.direction {
                q.push(format!("direction={}", 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.contract {
                q.push(format!("contract={}", urlencoding::encode(&v.to_string())));
            }
            if !q.is_empty() {
                path.push('?');
                path.push_str(&q.join("&"));
            }
        }
        self.client
            .request::<GetAddressWatchHistoryResponse>(reqwest::Method::GET, &path, None, false)
            .await
    }
}