]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Implement `Readable` for `Refund`
authorElias Rohrer <dev@tnull.de>
Mon, 25 Mar 2024 13:07:21 +0000 (14:07 +0100)
committerElias Rohrer <dev@tnull.de>
Tue, 4 Jun 2024 07:44:19 +0000 (09:44 +0200)
When storing `Refund`s, it's useful for them to implement LDK's
deserialization trait.

lightning/src/offers/refund.rs

index d796971f8b366f721174895a643b6f6d2cb67ecc..624036d195742879930cd25041d416561d3eee34 100644 (file)
@@ -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<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
+               let bytes: WithoutLength<Vec<u8>> = Readable::read(reader)?;
+               Self::try_from(bytes.0).map_err(|_| DecodeError::InvalidValue)
+       }
+}
+
 impl Writeable for Refund {
        fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
                WithoutLength(&self.bytes).write(writer)