pub mod delegated;
pub mod types;
#[allow(unused_imports)]
use types::*;
#[derive(Clone)]
pub struct VaultsClient {
client: crate::client::Client,
}
impl VaultsClient {
pub fn new(client: crate::client::Client) -> Self {
VaultsClient { client }
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
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
}
}