-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(traverse): Add era-handling utilities (#123)
- Loading branch information
Showing
5 changed files
with
119 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use pallas_codec::minicbor; | ||
use pallas_crypto::hash::Hash; | ||
use pallas_primitives::ToHash; | ||
|
||
use crate::{Error, MultiEraHeader}; | ||
|
||
impl<'b> MultiEraHeader<'b> { | ||
pub fn decode(tag: u8, subtag: Option<u8>, cbor: &'b [u8]) -> Result<Self, Error> { | ||
match tag { | ||
0 => match subtag { | ||
Some(0) => { | ||
let header = minicbor::decode(cbor).map_err(Error::invalid_cbor)?; | ||
Ok(MultiEraHeader::EpochBoundary(header)) | ||
} | ||
_ => { | ||
let header = minicbor::decode(cbor).map_err(Error::invalid_cbor)?; | ||
Ok(MultiEraHeader::Byron(header)) | ||
} | ||
}, | ||
_ => { | ||
let header = minicbor::decode(cbor).map_err(Error::invalid_cbor)?; | ||
Ok(MultiEraHeader::AlonzoCompatible(header)) | ||
} | ||
} | ||
} | ||
|
||
pub fn slot(&self) -> u64 { | ||
match self { | ||
MultiEraHeader::EpochBoundary(x) => x.to_abs_slot(), | ||
MultiEraHeader::AlonzoCompatible(x) => x.header_body.slot, | ||
MultiEraHeader::Byron(x) => x.consensus_data.0.to_abs_slot(), | ||
} | ||
} | ||
|
||
pub fn hash(&self) -> Hash<32> { | ||
match self { | ||
MultiEraHeader::EpochBoundary(x) => x.to_hash(), | ||
MultiEraHeader::AlonzoCompatible(x) => x.to_hash(), | ||
MultiEraHeader::Byron(x) => x.to_hash(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters