holochain_types/
signal.rs

1//! Signals which can be emitted from within Holochain, out across an interface.
2//! There are two main kinds of Signal: system-defined, and app-defined:
3//! - App-defined signals are produced via the `emit_signal` host function.
4//! - System-defined signals are produced in various places in the system
5
6use crate::impl_from;
7use holochain_serialized_bytes::prelude::*;
8use holochain_zome_types::prelude::*;
9
10/// A Signal is some information emitted from within Holochain out through
11/// an Interface
12#[derive(Clone, Debug, Serialize, Deserialize, SerializedBytes, PartialEq, Eq)]
13#[serde(tag = "type", content = "value", rename_all = "snake_case")]
14pub enum Signal {
15    /// Signal from a Cell, generated by `emit_signal`
16    App {
17        /// The Cell from which the signal was emitted
18        cell_id: CellId,
19        /// The Zome from which the signal was emitted
20        zome_name: ZomeName,
21        /// The actual signal that was emitted
22        signal: AppSignal,
23    },
24    /// System-defined signals
25    System(SystemSignal),
26}
27
28impl Signal {
29    /// Parse from vec.
30    pub fn try_from_vec(v: Vec<u8>) -> Result<Self, SerializedBytesError> {
31        Self::try_from(SerializedBytes::from(UnsafeBytes::from(v)))
32    }
33}
34
35/// A Signal which originates from within the Holochain system, as opposed to
36/// from within a Cell
37#[derive(Clone, Debug, Serialize, Deserialize, SerializedBytes, PartialEq, Eq)]
38#[serde(tag = "type", content = "value", rename_all = "snake_case")]
39pub enum SystemSignal {
40    /// A countersigning session has successfully completed.
41    SuccessfulCountersigning(EntryHash),
42    /// A countersigning session has been abandoned.
43    AbandonedCountersigning(EntryHash),
44}
45
46impl_from! {
47    SystemSignal => Signal, |s| { Self::System(s) },
48}