diff --git a/pallas-multiplexer/src/std.rs b/pallas-multiplexer/src/std.rs index 5330f30e..11586055 100644 --- a/pallas-multiplexer/src/std.rs +++ b/pallas-multiplexer/src/std.rs @@ -10,7 +10,6 @@ use std::{ Arc, }, thread::{spawn, JoinHandle}, - time::Duration, }; pub type StdIngress = Receiver; diff --git a/pallas-traverse/src/era.rs b/pallas-traverse/src/era.rs index b83af9cb..0de8ee08 100644 --- a/pallas-traverse/src/era.rs +++ b/pallas-traverse/src/era.rs @@ -29,7 +29,7 @@ impl TryFrom for Era { 4 => Ok(Era::Mary), 5 => Ok(Era::Alonzo), 6 => Ok(Era::Babbage), - x => Err(crate::Error::UnkownEra(x)), + x => Err(crate::Error::UnknownEra(x)), } } } diff --git a/pallas-traverse/src/header.rs b/pallas-traverse/src/header.rs index e94329eb..7a6f6767 100644 --- a/pallas-traverse/src/header.rs +++ b/pallas-traverse/src/header.rs @@ -1,5 +1,5 @@ use pallas_codec::minicbor; -use pallas_crypto::hash::Hash; +use pallas_crypto::hash::{Hash, Hasher}; use pallas_primitives::ToHash; use crate::{Error, MultiEraHeader}; @@ -45,4 +45,34 @@ impl<'b> MultiEraHeader<'b> { MultiEraHeader::Byron(x) => x.to_hash(), } } -} + + pub fn leader_vrf_output(&self) -> Result, Error> { + match self { + MultiEraHeader::EpochBoundary(_) => Err(Error::InvalidEra(0)), + MultiEraHeader::AlonzoCompatible(x) => { + Ok(x.header_body.leader_vrf.0.to_vec()) + } + MultiEraHeader::Babbage(x) => { + let mut leader_tagged_vrf: Vec = vec![0x4C_u8]; /* "L" */ + leader_tagged_vrf.extend(&*x.header_body.vrf_result.0); + Ok(Hasher::<256>::hash(&leader_tagged_vrf).to_vec()) + } + MultiEraHeader::Byron(_) => Err(Error::InvalidEra(1)), + } + } + + pub fn nonce_vrf_output(&self) -> Result, Error> { + match self { + MultiEraHeader::EpochBoundary(_) => Err(Error::InvalidEra(0)), + MultiEraHeader::AlonzoCompatible(x) => { + Ok(x.header_body.nonce_vrf.0.to_vec()) + } + MultiEraHeader::Babbage(x) => { + let mut nonce_tagged_vrf: Vec = vec![0x4E_u8]; /* "N" */ + nonce_tagged_vrf.extend(&*x.header_body.vrf_result.0); + Ok(Hasher::<256>::hash(&nonce_tagged_vrf).to_vec()) + } + MultiEraHeader::Byron(_) => Err(Error::InvalidEra(1)), + } + } +} \ No newline at end of file diff --git a/pallas-traverse/src/lib.rs b/pallas-traverse/src/lib.rs index d6947da9..81b61796 100644 --- a/pallas-traverse/src/lib.rs +++ b/pallas-traverse/src/lib.rs @@ -97,7 +97,10 @@ pub enum Error { UnknownCbor(String), #[error("Unknown era tag: {0}")] - UnkownEra(u16), + UnknownEra(u16), + + #[error("Invalid era for request: {0}")] + InvalidEra(u16), } impl Error {