holochain_types 0.1.0

Holochain common types
Documentation
//! Signals which can be emitted from within Holochain, out across an interface.
//! There are two main kinds of Signal: system-defined, and app-defined:
//! - App-defined signals are produced via the `emit_signal` host function.
//! - System-defined signals are produced in various places in the system

use crate::impl_from;
use holochain_serialized_bytes::prelude::*;
use holochain_zome_types::prelude::*;

/// A Signal is some information emitted from within Holochain out through
/// an Interface
#[derive(Clone, Debug, Serialize, Deserialize, SerializedBytes, PartialEq, Eq)]
pub enum Signal {
    /// Signal from a Cell, generated by `emit_signal`
    App {
        /// The Cell from which the signal was emitted
        cell_id: CellId,
        /// The Zome from which the signal was emitted
        zome_name: ZomeName,
        /// The actual signal that was emitted
        signal: AppSignal,
    },
    /// System-defined signals
    System(SystemSignal),
}

/// A Signal which originates from within the Holochain system, as opposed to
/// from within a Cell
///
/// TODO, decide what these will be. For instance, maybe there is a
/// DataAvailable signal for doing async network requests
#[derive(Clone, Debug, Serialize, Deserialize, SerializedBytes, PartialEq, Eq)]
pub enum SystemSignal {
    /// Since we have no real system signals, we use a test signal for testing
    /// TODO: replace instances of this with something real
    Test(String),
    /// A countersigning session has successfully completed.
    SuccessfulCountersigning(holo_hash::EntryHash),
}

/// Create a test signal
pub fn test_signal(s: &str) -> Signal {
    SystemSignal::Test(s.to_string()).into()
}

impl_from! {
    SystemSignal => Signal, |s| { Self::System(s) },
}