]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Implement Readable for Bolt12Invoice
authorJeffrey Czyz <jkczyz@gmail.com>
Tue, 21 May 2024 19:28:56 +0000 (14:28 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Tue, 11 Jun 2024 16:05:32 +0000 (11:05 -0500)
A future InvoiceReceived event will include a Bolt12Invoice. Since Event
implements Readable, so must Bolt12Invoice.

lightning/src/offers/invoice.rs

index 5482e6f83ea48e4139beb6b1d367aba55e5851eb..0d5d2caaa7e0d7c3cb9a217f0be0f6ddb919afe9 100644 (file)
@@ -124,7 +124,7 @@ use crate::offers::parse::{Bolt12ParseError, Bolt12SemanticError, ParsedMessage}
 use crate::offers::payer::{PAYER_METADATA_TYPE, PayerTlvStream, PayerTlvStreamRef};
 use crate::offers::refund::{IV_BYTES as REFUND_IV_BYTES, Refund, RefundContents};
 use crate::offers::signer;
-use crate::util::ser::{HighZeroBytesDroppedBigSize, Iterable, SeekReadable, WithoutLength, Writeable, Writer};
+use crate::util::ser::{HighZeroBytesDroppedBigSize, Iterable, Readable, SeekReadable, WithoutLength, Writeable, Writer};
 use crate::util::string::PrintableString;
 
 #[allow(unused_imports)]
@@ -1205,6 +1205,13 @@ impl Writeable for Bolt12Invoice {
        }
 }
 
+impl Readable for Bolt12Invoice {
+       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 InvoiceContents {
        fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
                self.as_tlv_stream().write(writer)