feat(network): add cbor decoder for HardForkQuery (#335)

This commit is contained in:
Alexsander Falcucci 2023-11-20 12:02:02 +01:00 committed by GitHub
parent 155139e166
commit 9b57b0f53d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -172,8 +172,14 @@ impl Encode<()> for HardForkQuery {
} }
impl<'b> Decode<'b, ()> for HardForkQuery { impl<'b> Decode<'b, ()> for HardForkQuery {
fn decode(_d: &mut Decoder<'b>, _: &mut ()) -> Result<Self, decode::Error> { fn decode(d: &mut Decoder<'b>, _: &mut ()) -> Result<Self, decode::Error> {
todo!() d.array()?;
let tag = d.u16()?;
match tag {
0 => Ok(Self::GetInterpreter),
1 => Ok(Self::GetCurrentEra),
_ => Err(decode::Error::message("invalid tag")),
}
} }
} }
@ -197,8 +203,20 @@ impl Encode<()> for LedgerQuery {
} }
impl<'b> Decode<'b, ()> for LedgerQuery { impl<'b> Decode<'b, ()> for LedgerQuery {
fn decode(_d: &mut Decoder<'b>, _: &mut ()) -> Result<Self, decode::Error> { fn decode(d: &mut Decoder<'b>, _: &mut ()) -> Result<Self, decode::Error> {
todo!() 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")),
}
} }
} }