Skip to content

Commit

Permalink
feat: Make chainsync protocol era-agnostic (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
scarmuega authored Feb 17, 2022
1 parent e26acf2 commit 723aac9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
17 changes: 13 additions & 4 deletions pallas-miniprotocols/src/chainsync/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ where
impl DecodePayload for HeaderContent {
fn decode_payload(d: &mut crate::PayloadDecoder) -> Result<Self, Box<dyn std::error::Error>> {
d.array()?;
let variant = d.u32()?; // WTF is this value?
let variant = d.u8()?; // era variant

match variant {
// byron
Expand All @@ -133,13 +133,22 @@ impl DecodePayload for HeaderContent {
d.tag()?;
let bytes = d.bytes()?;

Ok(HeaderContent::Byron(a, b, Vec::from(bytes)))
Ok(HeaderContent {
variant,
byron_prefix: Some((a, b)),
cbor: Vec::from(bytes),
})
}
// shelley
// shelley and beyond
_ => {
d.tag()?;
let bytes = d.bytes()?;
Ok(HeaderContent::Shelley(Vec::from(bytes)))

Ok(HeaderContent {
variant,
byron_prefix: None,
cbor: Vec::from(bytes),
})
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions pallas-miniprotocols/src/chainsync/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ pub enum Message<C> {
}

#[derive(Debug)]
pub enum HeaderContent {
Byron(u8, u64, Vec<u8>),
Shelley(Vec<u8>),
pub struct HeaderContent {
pub variant: u8,
pub byron_prefix: Option<(u8, u64)>,
pub cbor: Vec<u8>,
}

#[derive(Debug)]
Expand Down

0 comments on commit 723aac9

Please sign in to comment.