Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Make chainsync protocol era-agnostic #52

Merged
merged 1 commit into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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