use vti_specs::vta::collection;
use super::VtaClient;
use crate::error::VtaError;
use crate::trust_tasks;
const COLLECTION_TT_TIMEOUT: u64 = 30;
impl VtaClient {
async fn collection_call<P: serde::Serialize, R: serde::de::DeserializeOwned>(
&self,
uri: &str,
payload: &P,
) -> Result<R, VtaError> {
let payload = serde_json::to_value(payload)
.map_err(|e| VtaError::Validation(format!("{uri} request: {e}")))?;
let answer = self
.dispatch_trust_task(uri, payload, COLLECTION_TT_TIMEOUT)
.await?;
serde_json::from_value(answer).map_err(|e| {
VtaError::Protocol(format!("{uri} response does not match its schema: {e}"))
})
}
pub async fn collection_claim(
&self,
req: &collection::claim::v0_1::Payload,
) -> Result<collection::claim::v0_1::Response, VtaError> {
self.collection_call(trust_tasks::TASK_VTA_COLLECTION_CLAIM_0_1, req)
.await
}
pub async fn collection_claim_json(
&self,
req: serde_json::Value,
) -> Result<serde_json::Value, VtaError> {
self.dispatch_trust_task(
trust_tasks::TASK_VTA_COLLECTION_CLAIM_0_1,
req,
COLLECTION_TT_TIMEOUT,
)
.await
}
pub async fn collection_release(
&self,
req: &collection::release::v0_1::Payload,
) -> Result<collection::release::v0_1::Response, VtaError> {
self.collection_call(trust_tasks::TASK_VTA_COLLECTION_RELEASE_0_1, req)
.await
}
pub async fn collection_release_json(
&self,
req: serde_json::Value,
) -> Result<serde_json::Value, VtaError> {
self.dispatch_trust_task(
trust_tasks::TASK_VTA_COLLECTION_RELEASE_0_1,
req,
COLLECTION_TT_TIMEOUT,
)
.await
}
pub async fn collection_list(
&self,
req: &collection::list::v0_1::Payload,
) -> Result<collection::list::v0_1::Response, VtaError> {
self.collection_call(trust_tasks::TASK_VTA_COLLECTION_LIST_0_1, req)
.await
}
pub async fn collection_list_json(
&self,
req: serde_json::Value,
) -> Result<serde_json::Value, VtaError> {
self.dispatch_trust_task(
trust_tasks::TASK_VTA_COLLECTION_LIST_0_1,
req,
COLLECTION_TT_TIMEOUT,
)
.await
}
}