use super::SweetZome;
use crate::conductor::{api::error::ConductorApiResult, ConductorHandle};
use holochain_types::prelude::*;
#[derive(shrinkwraprs::Shrinkwrap, derive_more::From)]
pub struct SweetConductorHandle(pub(crate) ConductorHandle);
impl SweetConductorHandle {
pub async fn call<I, O>(
&self,
zome: &SweetZome,
fn_name: impl Into<FunctionName>,
payload: I,
) -> O
where
I: serde::Serialize + std::fmt::Debug,
O: serde::de::DeserializeOwned + std::fmt::Debug,
{
self.call_fallible(zome, fn_name, payload).await.unwrap()
}
pub async fn call_fallible<I, O>(
&self,
zome: &SweetZome,
fn_name: impl Into<FunctionName>,
payload: I,
) -> ConductorApiResult<O>
where
I: serde::Serialize + std::fmt::Debug,
O: serde::de::DeserializeOwned + std::fmt::Debug,
{
self.call_from_fallible(zome.cell_id().agent_pubkey(), None, zome, fn_name, payload)
.await
}
pub async fn call_from<I, O>(
&self,
provenance: &AgentPubKey,
cap_secret: Option<CapSecret>,
zome: &SweetZome,
fn_name: impl Into<FunctionName>,
payload: I,
) -> O
where
I: Serialize + std::fmt::Debug,
O: serde::de::DeserializeOwned + std::fmt::Debug,
{
self.call_from_fallible(provenance, cap_secret, zome, fn_name, payload)
.await
.unwrap()
}
pub async fn call_from_fallible<I, O>(
&self,
provenance: &AgentPubKey,
cap_secret: Option<CapSecret>,
zome: &SweetZome,
fn_name: impl Into<FunctionName>,
payload: I,
) -> ConductorApiResult<O>
where
I: Serialize + std::fmt::Debug,
O: serde::de::DeserializeOwned + std::fmt::Debug,
{
self.0
.easy_call_zome(
provenance,
cap_secret,
zome.cell_id().clone(),
zome.name().clone(),
fn_name,
payload,
)
.await
}
pub(super) fn clone_privately(&self) -> Self {
Self(self.0.clone())
}
}