Skip to content

Commit

Permalink
fix: Fix n2n babbage header parsing (#355)
Browse files Browse the repository at this point in the history
  • Loading branch information
scarmuega authored Jul 4, 2022
1 parent add845f commit 4888700
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions src/sources/n2n/headers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use pallas::{
codec::minicbor::decode,
ledger::primitives::{alonzo, byron, ToHash},
ledger::primitives::{alonzo, babbage, byron, ToHash},
network::miniprotocols::{chainsync::HeaderContent, Point},
};

Expand All @@ -11,6 +11,7 @@ pub enum MultiEraHeader {
ByronBoundary(byron::EbbHead),
Byron(byron::BlockHead),
AlonzoCompatible(alonzo::Header),
Babbage(babbage::Header),
}

impl TryFrom<HeaderContent> for MultiEraHeader {
Expand All @@ -28,10 +29,17 @@ impl TryFrom<HeaderContent> for MultiEraHeader {
Ok(MultiEraHeader::Byron(header))
}
},
_ => {
1 | 2 | 3 | 4 => {
let header = decode(&value.cbor)?;
Ok(MultiEraHeader::AlonzoCompatible(header))
}
5 => {
let header = decode(&value.cbor)?;
Ok(MultiEraHeader::Babbage(header))
}
x => {
return Err(format!("This version of Oura can't handle era: {}", x).into());
}
}
}
}
Expand All @@ -53,6 +61,10 @@ impl MultiEraHeader {
let hash = x.to_hash();
Ok(Point::Specific(x.header_body.slot, hash.to_vec()))
}
MultiEraHeader::Babbage(x) => {
let hash = x.to_hash();
Ok(Point::Specific(x.header_body.slot, hash.to_vec()))
}
}
}
}

0 comments on commit 4888700

Please sign in to comment.