From 9b57b0f53d8369b43c4e7f35df65648373b53172 Mon Sep 17 00:00:00 2001 From: Alexsander Falcucci Date: Mon, 20 Nov 2023 12:02:02 +0100 Subject: [PATCH] feat(network): add cbor decoder for HardForkQuery (#335) --- .../localstate/queries_v16/codec.rs | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/pallas-network/src/miniprotocols/localstate/queries_v16/codec.rs b/pallas-network/src/miniprotocols/localstate/queries_v16/codec.rs index f5be36b..2e518b6 100644 --- a/pallas-network/src/miniprotocols/localstate/queries_v16/codec.rs +++ b/pallas-network/src/miniprotocols/localstate/queries_v16/codec.rs @@ -172,8 +172,14 @@ impl Encode<()> for HardForkQuery { } impl<'b> Decode<'b, ()> for HardForkQuery { - fn decode(_d: &mut Decoder<'b>, _: &mut ()) -> Result { - todo!() + fn decode(d: &mut Decoder<'b>, _: &mut ()) -> Result { + 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 { - fn decode(_d: &mut Decoder<'b>, _: &mut ()) -> Result { - todo!() + fn decode(d: &mut Decoder<'b>, _: &mut ()) -> Result { + 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")), + } } }