Skip to content

Commit

Permalink
feat(network): add cbor decoder for HardForkQuery (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
falcucci authored Nov 20, 2023
1 parent 155139e commit 9b57b0f
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions pallas-network/src/miniprotocols/localstate/queries_v16/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,14 @@ impl Encode<()> for HardForkQuery {
}

impl<'b> Decode<'b, ()> for HardForkQuery {
fn decode(_d: &mut Decoder<'b>, _: &mut ()) -> Result<Self, decode::Error> {
todo!()
fn decode(d: &mut Decoder<'b>, _: &mut ()) -> Result<Self, decode::Error> {
d.array()?;
let tag = d.u16()?;
match tag {
0 => Ok(Self::GetInterpreter),
1 => Ok(Self::GetCurrentEra),
_ => Err(decode::Error::message("invalid tag")),
}
}
}

Expand All @@ -197,8 +203,20 @@ impl Encode<()> for LedgerQuery {
}

impl<'b> Decode<'b, ()> for LedgerQuery {
fn decode(_d: &mut Decoder<'b>, _: &mut ()) -> Result<Self, decode::Error> {
todo!()
fn decode(d: &mut Decoder<'b>, _: &mut ()) -> Result<Self, decode::Error> {
d.array()?;
let tag = d.u16()?;
match tag {
0 => {
let (era, q) = d.decode()?;
Ok(Self::BlockQuery(era, q))
}
2 => {
let q = d.decode()?;
Ok(Self::HardForkQuery(q))
}
_ => Err(decode::Error::message("invalid tag")),
}
}
}

Expand Down

0 comments on commit 9b57b0f

Please sign in to comment.