versa 1.9.0-rc2

Versa types and utilities for developing Versa client applications in Rust
Documentation
use std::future::Future;

use crate::protocol::{CheckRegistryResponse, TransactionHandles};

use super::{ClientError, VersaClient};

/// **DEPRECATED**: This trait is deprecated and will be removed in a future version.
///
/// This trait was used to provide a `check_registry` method for querying the registry
/// about receiver configurations. It is being deprecated as part of API simplification.

#[deprecated(
  since = "1.2.0",
  note = "The CheckRegistry trait is deprecated and will be removed in a future version"
)]
pub trait CheckRegistry {
  #[deprecated(
    since = "1.2.0",
    note = "The check_registry method is deprecated and will be removed in a future version; please use query_receivers instead"
  )]
  fn check_registry(
    &self,
    handles: TransactionHandles,
  ) -> impl Future<Output = Result<CheckRegistryResponse, ClientError>> + Send;
}

impl CheckRegistry for VersaClient {
  async fn check_registry(
    &self,
    handles: TransactionHandles,
  ) -> Result<CheckRegistryResponse, ClientError> {
    let credential = self.authorization_header_val();
    let url = format!("{}/check_registry", self.registry_url);
    let payload_json = serde_json::to_string(&handles).unwrap();

    let client = reqwest::Client::new();
    let response_result = client
      .post(url)
      .header("Accept", "application/json")
      .header("Authorization", credential)
      .header("Content-Type", "application/json")
      .body(payload_json)
      .send()
      .await;

    match response_result {
      Ok(response) => {
        if response.status().is_success() {
          let response: CheckRegistryResponse = match response.json().await {
            Ok(response) => response,
            Err(e) => return Err(ClientError::DeserializationError(e)),
          };
          Ok(response)
        } else {
          Err(ClientError::RegistryError(
            response.status(),
            response.text().await.unwrap(),
          ))
        }
      }
      Err(e) => Err(ClientError::NetworkError(e)),
    }
  }
}