From: Elias Rohrer Date: Mon, 25 Mar 2024 13:07:21 +0000 (+0100) Subject: Implement `Readable` for `Refund` X-Git-Tag: v0.0.124-beta~103^2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=fc14495ac6a9dbe7dc9a6bd43c4395b599592db1;p=rust-lightning Implement `Readable` for `Refund` When storing `Refund`s, it's useful for them to implement LDK's deserialization trait. --- 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)