holochain_zome_types/
call.rs

1use crate::prelude::*;
2use holo_hash::AgentPubKey;
3use holochain_wasmer_common::WasmError;
4
5/// Identifier for an App Role, a foundational concept in the App manifest.
6pub type RoleName = String;
7
8#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
9pub enum CallTargetCell {
10    OtherCell(CellId),
11    OtherRole(RoleName),
12    Local,
13}
14
15#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
16pub enum CallTarget {
17    NetworkAgent(AgentPubKey),
18    ConductorCell(CallTargetCell),
19}
20
21#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
22pub struct Call {
23    pub target: CallTarget,
24    pub zome_name: ZomeName,
25    pub fn_name: FunctionName,
26    pub cap_secret: Option<CapSecret>,
27    pub payload: ExternIO,
28}
29
30impl Call {
31    pub fn new(
32        target: CallTarget,
33        zome_name: ZomeName,
34        fn_name: FunctionName,
35        cap_secret: Option<CapSecret>,
36        payload: ExternIO,
37    ) -> Self {
38        Self {
39            target,
40            zome_name,
41            fn_name,
42            cap_secret,
43            payload,
44        }
45    }
46
47    pub fn target(&self) -> &CallTarget {
48        &self.target
49    }
50
51    pub fn zome_name(&self) -> &ZomeName {
52        &self.zome_name
53    }
54
55    pub fn fn_name(&self) -> &FunctionName {
56        &self.fn_name
57    }
58
59    pub fn cap_secret(&self) -> Option<&CapSecret> {
60        self.cap_secret.as_ref()
61    }
62
63    pub fn payload(&self) -> &ExternIO {
64        &self.payload
65    }
66}
67
68#[allow(missing_docs)]
69pub trait CallbackResult: Sized {
70    /// if a callback result is definitive we should halt any further iterations over remaining
71    /// calls e.g. over sparse names or subsequent zomes
72    /// typically a clear failure is definitive but success and missing dependencies are not
73    /// in the case of success or missing deps, a subsequent callback could give us a definitive
74    /// answer like a fail, and we don't want to over-optimise wasm calls and miss a clear failure
75    fn is_definitive(&self) -> bool;
76    /// when a WasmError is returned from a callback (e.g. via `?` operator) it might mean either:
77    ///
78    /// - There was an error that prevented the callback from coming to a CallbackResult (e.g. failing to connect to database)
79    /// - There was an error that should be interpreted as a CallbackResult::Fail (e.g. data failed to deserialize)
80    ///
81    /// Typically this can be split as host/wasm errors are the former, and serialization/guest errors the latter.
82    /// This function allows each CallbackResult to explicitly map itself.
83    fn try_from_wasm_error(wasm_error: WasmError) -> Result<Self, WasmError>;
84}