feat(traverse): Introduce more new accessor methods (#153)

This commit is contained in:
Santiago Carmuega 2022-07-17 16:40:49 -03:00 committed by GitHub
parent 33c6152f19
commit c377a6aaec
11 changed files with 182 additions and 51 deletions

View file

@ -1,8 +1,9 @@
use std::borrow::Cow;
use std::ops::Deref;
use pallas_codec::minicbor;
use pallas_crypto::hash::{Hash, Hasher};
use pallas_primitives::ToHash;
use pallas_primitives::{alonzo, babbage, byron, ToHash};
use crate::Era::Byron;
use crate::{Error, MultiEraHeader};
@ -97,4 +98,32 @@ impl<'b> MultiEraHeader<'b> {
MultiEraHeader::Byron(_) => Err(Error::InvalidEra(Byron)),
}
}
pub fn as_eb(&self) -> Option<&byron::EbbHead> {
match self {
MultiEraHeader::EpochBoundary(x) => Some(x.deref().deref()),
_ => None,
}
}
pub fn as_byron(&self) -> Option<&byron::BlockHead> {
match self {
MultiEraHeader::Byron(x) => Some(x.deref().deref()),
_ => None,
}
}
pub fn as_alonzo(&self) -> Option<&alonzo::Header> {
match self {
MultiEraHeader::AlonzoCompatible(x) => Some(x.deref().deref()),
_ => None,
}
}
pub fn as_babbage(&self) -> Option<&babbage::Header> {
match self {
MultiEraHeader::Babbage(x) => Some(x.deref().deref()),
_ => None,
}
}
}