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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use chrono::{DateTime, Utc};

use crate::entities::{
    CardanoTransactionsSnapshot, MithrilStakeDistribution, SignedEntityType, Snapshot,
};
use crate::signable_builder::Artifact;
#[cfg(any(test, feature = "test_tools"))]
use crate::test_utils::fake_data;

use super::CardanoStakeDistribution;
#[cfg(any(test, feature = "test_tools"))]
use super::{CardanoDbBeacon, Epoch};

/// Aggregate for signed entity
#[derive(Debug, Clone)]
pub struct SignedEntity<T>
where
    T: Artifact,
{
    /// Signed entity id.
    pub signed_entity_id: String,

    /// Signed entity type.
    pub signed_entity_type: SignedEntityType,

    /// Certificate id for this signed entity.
    pub certificate_id: String,

    /// Artifact
    pub artifact: T,

    /// Date and time when the signed_entity was created
    pub created_at: DateTime<Utc>,
}

impl SignedEntity<Snapshot> {
    cfg_test_tools! {
        /// Create a dummy [SignedEntity] for [Snapshot] entity
        pub fn dummy() -> Self {
            SignedEntity {
                signed_entity_id: "snapshot-id-123".to_string(),
                signed_entity_type: SignedEntityType::CardanoImmutableFilesFull(CardanoDbBeacon::default()),
                certificate_id: "certificate-hash-123".to_string(),
                artifact: fake_data::snapshots(1)[0].to_owned(),
                created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
                    .unwrap()
                    .with_timezone(&Utc),
            }
        }
    }
}

impl SignedEntity<MithrilStakeDistribution> {
    cfg_test_tools! {
        /// Create a dummy [SignedEntity] for [MithrilStakeDistribution] entity
        pub fn dummy() -> Self {
            SignedEntity {
                signed_entity_id: "mithril-stake-distribution-id-123".to_string(),
                signed_entity_type: SignedEntityType::MithrilStakeDistribution(Epoch(1)),
                certificate_id: "certificate-hash-123".to_string(),
                artifact: fake_data::mithril_stake_distributions(1)[0].to_owned(),
                created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
                    .unwrap()
                    .with_timezone(&Utc),
            }
        }
    }
}

impl SignedEntity<CardanoTransactionsSnapshot> {
    cfg_test_tools! {
        /// Create a dummy [SignedEntity] for [CardanoTransactionsSnapshot] entity
        pub fn dummy() -> Self {
            let block_number = crate::entities::BlockNumber(50);
            SignedEntity {
                signed_entity_id: "snapshot-id-123".to_string(),
                signed_entity_type: SignedEntityType::CardanoTransactions(Epoch(5), block_number),
                certificate_id: "certificate-hash-123".to_string(),
                artifact: CardanoTransactionsSnapshot::new("mkroot123".to_string(), block_number),
                created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
                    .unwrap()
                    .with_timezone(&Utc),
            }
        }
    }
}

impl SignedEntity<CardanoStakeDistribution> {
    cfg_test_tools! {
        /// Create a dummy [SignedEntity] for [CardanoStakeDistribution] entity
        pub fn dummy() -> Self {
            SignedEntity {
                signed_entity_id: "cardano-stake-distribution-id-123".to_string(),
                signed_entity_type: SignedEntityType::CardanoStakeDistribution(Epoch(1)),
                certificate_id: "certificate-hash-123".to_string(),
                artifact: fake_data::cardano_stake_distributions(1)[0].to_owned(),
                created_at: DateTime::parse_from_rfc3339("2024-07-29T16:15:05.618857482Z")
                    .unwrap()
                    .with_timezone(&Utc),
            }
        }
    }
}