penumbra_sdk_sct/
epoch.rs1use penumbra_sdk_proto::penumbra::core::component::sct::v1 as pb;
2use penumbra_sdk_proto::DomainType;
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Copy, Clone, Serialize, Deserialize)]
6#[serde(try_from = "pb::Epoch", into = "pb::Epoch")]
7pub struct Epoch {
8 pub index: u64,
9 pub start_height: u64,
10}
11
12impl DomainType for Epoch {
13 type Proto = pb::Epoch;
14}
15
16impl From<pb::Epoch> for Epoch {
17 fn from(msg: pb::Epoch) -> Self {
18 Epoch {
19 index: msg.index,
20 start_height: msg.start_height,
21 }
22 }
23}
24
25impl From<Epoch> for pb::Epoch {
26 fn from(epoch: Epoch) -> Self {
27 pb::Epoch {
28 index: epoch.index,
29 start_height: epoch.start_height,
30 }
31 }
32}
33
34impl Epoch {
35 pub fn is_scheduled_epoch_end(&self, current_height: u64, epoch_duration: u64) -> bool {
37 current_height - self.start_height >= epoch_duration - 1
38 }
39}