feat: Make chainsync protocol era-agnostic (#52)
This commit is contained in:
parent
b2688fcd9e
commit
f877a776ae
2 changed files with 17 additions and 7 deletions
|
|
@ -119,7 +119,7 @@ where
|
||||||
impl DecodePayload for HeaderContent {
|
impl DecodePayload for HeaderContent {
|
||||||
fn decode_payload(d: &mut crate::PayloadDecoder) -> Result<Self, Box<dyn std::error::Error>> {
|
fn decode_payload(d: &mut crate::PayloadDecoder) -> Result<Self, Box<dyn std::error::Error>> {
|
||||||
d.array()?;
|
d.array()?;
|
||||||
let variant = d.u32()?; // WTF is this value?
|
let variant = d.u8()?; // era variant
|
||||||
|
|
||||||
match variant {
|
match variant {
|
||||||
// byron
|
// byron
|
||||||
|
|
@ -133,13 +133,22 @@ impl DecodePayload for HeaderContent {
|
||||||
d.tag()?;
|
d.tag()?;
|
||||||
let bytes = d.bytes()?;
|
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()?;
|
d.tag()?;
|
||||||
let bytes = d.bytes()?;
|
let bytes = d.bytes()?;
|
||||||
Ok(HeaderContent::Shelley(Vec::from(bytes)))
|
|
||||||
|
Ok(HeaderContent {
|
||||||
|
variant,
|
||||||
|
byron_prefix: None,
|
||||||
|
cbor: Vec::from(bytes),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,10 @@ pub enum Message<C> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum HeaderContent {
|
pub struct HeaderContent {
|
||||||
Byron(u8, u64, Vec<u8>),
|
pub variant: u8,
|
||||||
Shelley(Vec<u8>),
|
pub byron_prefix: Option<(u8, u64)>,
|
||||||
|
pub cbor: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue