1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! Defines a Record, the basic unit of Holochain data.

use crate::signature::Signature;
use crate::Action;
use holo_hash::hash_type;
use holo_hash::HashableContent;
use holo_hash::HashableContentBytes;
use holochain_serialized_bytes::prelude::*;

pub use holochain_integrity_types::record::*;

#[cfg(feature = "test_utils")]
pub mod facts;

/// A combination of an action and its signature.
///
/// Has implementations From and Into its tuple form.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, SerializedBytes)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub struct SignedAction(pub Action, pub Signature);

impl SignedAction {
    /// Accessor for the Action
    pub fn action(&self) -> &Action {
        &self.0
    }

    /// Accessor for the Signature
    pub fn signature(&self) -> &Signature {
        &self.1
    }
}

impl HashableContent for SignedAction {
    type HashType = hash_type::Action;

    fn hash_type(&self) -> Self::HashType {
        hash_type::Action
    }

    fn hashable_content(&self) -> HashableContentBytes {
        HashableContentBytes::Content(
            (&self.0)
                .try_into()
                .expect("Could not serialize HashableContent"),
        )
    }
}

impl From<(Action, Signature)> for SignedAction {
    fn from((h, s): (Action, Signature)) -> Self {
        Self(h, s)
    }
}

impl From<SignedAction> for (Action, Signature) {
    fn from(s: SignedAction) -> Self {
        (s.0, s.1)
    }
}

impl From<SignedActionHashed> for SignedAction {
    fn from(shh: SignedActionHashed) -> SignedAction {
        (shh.hashed.content, shh.signature).into()
    }
}