Add new fn to Slot and Epoch

This commit is contained in:
Paul Hauner 2019-02-07 09:53:53 +11:00
parent bd71304d73
commit a98c221447
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6

View File

@ -241,6 +241,10 @@ impl_display!(Epoch);
impl_ssz!(Epoch); impl_ssz!(Epoch);
impl Slot { impl Slot {
pub fn new(slot: u64) -> Slot {
Slot(slot)
}
pub fn epoch(&self, epoch_length: u64) -> Epoch { pub fn epoch(&self, epoch_length: u64) -> Epoch {
Epoch::from(self.0 / epoch_length) Epoch::from(self.0 / epoch_length)
} }
@ -251,6 +255,10 @@ impl Slot {
} }
impl Epoch { impl Epoch {
pub fn new(slot: u64) -> Epoch {
Epoch(slot)
}
pub fn start_slot(&self, epoch_length: u64) -> Slot { pub fn start_slot(&self, epoch_length: u64) -> Slot {
Slot::from(self.0.saturating_mul(epoch_length)) Slot::from(self.0.saturating_mul(epoch_length))
} }