From fc14495ac6a9dbe7dc9a6bd43c4395b599592db1 Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Mon, 25 Mar 2024 14:07:21 +0100 Subject: [PATCH] Implement `Readable` for `Refund` When storing `Refund`s, it's useful for them to implement LDK's deserialization trait. --- lightning/src/offers/refund.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lightning/src/offers/refund.rs b/lightning/src/offers/refund.rs index d796971f8..624036d19 100644 --- a/lightning/src/offers/refund.rs +++ b/lightning/src/offers/refund.rs @@ -103,7 +103,7 @@ use crate::offers::offer::{OfferTlvStream, OfferTlvStreamRef}; use crate::offers::parse::{Bech32Encode, Bolt12ParseError, Bolt12SemanticError, ParsedMessage}; use crate::offers::payer::{PayerContents, PayerTlvStream, PayerTlvStreamRef}; use crate::offers::signer::{Metadata, MetadataMaterial, self}; -use crate::util::ser::{SeekReadable, WithoutLength, Writeable, Writer}; +use crate::util::ser::{SeekReadable, Readable, WithoutLength, Writeable, Writer}; use crate::util::string::PrintableString; #[cfg(not(c_bindings))] @@ -769,6 +769,13 @@ impl RefundContents { } } +impl Readable for Refund { + fn read(reader: &mut R) -> Result { + let bytes: WithoutLength> = Readable::read(reader)?; + Self::try_from(bytes.0).map_err(|_| DecodeError::InvalidValue) + } +} + impl Writeable for Refund { fn write(&self, writer: &mut W) -> Result<(), io::Error> { WithoutLength(&self.bytes).write(writer) -- 2.39.5