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
// Copyright (c) Mysten Labs, Inc.
// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use crate::{
    base_types::EpochId,
    message_envelope::Message,
    messages_checkpoint::{CheckpointDigest, CheckpointSummary, CheckpointTimestamp},
};

/// The static epoch information that is accessible to move smart contracts
#[derive(Default)]
pub struct EpochData {
    epoch_id: EpochId,
    epoch_start_timestamp: CheckpointTimestamp,
    epoch_digest: CheckpointDigest,
}

impl EpochData {
    pub fn new(
        epoch_id: EpochId,
        epoch_start_timestamp: CheckpointTimestamp,
        epoch_digest: CheckpointDigest,
    ) -> Self {
        Self {
            epoch_id,
            epoch_start_timestamp,
            epoch_digest,
        }
    }

    pub fn new_genesis(epoch_start_timestamp: CheckpointTimestamp) -> Self {
        Self {
            epoch_id: 0,
            epoch_start_timestamp,
            epoch_digest: Default::default(),
        }
    }

    pub fn new_from_epoch_checkpoint(
        epoch_id: EpochId,
        epoch_checkpoint: &CheckpointSummary,
    ) -> Self {
        Self {
            epoch_id,
            epoch_start_timestamp: epoch_checkpoint.timestamp_ms,
            epoch_digest: epoch_checkpoint.digest(),
        }
    }

    pub fn new_test() -> Self {
        Default::default()
    }

    pub fn epoch_id(&self) -> EpochId {
        self.epoch_id
    }

    pub fn epoch_start_timestamp(&self) -> CheckpointTimestamp {
        self.epoch_start_timestamp
    }

    pub fn epoch_digest(&self) -> CheckpointDigest {
        self.epoch_digest
    }
}