use trust_tasks_rs::specs::vta::witness;
use super::VtaClient;
use crate::error::VtaError;
use crate::trust_tasks;
const WITNESS_TT_TIMEOUT: u64 = 30;
impl VtaClient {
async fn witness_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, WITNESS_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 witness_open(
&self,
req: &witness::open::v0_1::Payload,
) -> Result<witness::open::v0_1::Response, VtaError> {
self.witness_call(trust_tasks::TASK_VTA_WITNESS_OPEN_0_1, req)
.await
}
pub async fn witness_present(
&self,
req: &witness::present::v0_1::Payload,
) -> Result<witness::present::v0_1::Response, VtaError> {
self.witness_call(trust_tasks::TASK_VTA_WITNESS_PRESENT_0_1, req)
.await
}
pub async fn witness_accept(
&self,
req: &witness::accept::v0_1::Payload,
) -> Result<witness::accept::v0_1::Response, VtaError> {
self.witness_call(trust_tasks::TASK_VTA_WITNESS_ACCEPT_0_1, req)
.await
}
}