Skip to content

Commit c396e14

Browse files
committed
Implement Readable for Offer
When storing `Offer`s, it's useful for them to implement LDK's deserialization trait.
1 parent 6d11111 commit c396e14

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lightning/src/offers/offer.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ use crate::blinded_path::BlindedPath;
9191
use crate::ln::channelmanager::PaymentId;
9292
use crate::ln::features::OfferFeatures;
9393
use crate::ln::inbound_payment::{ExpandedKey, IV_LEN, Nonce};
94-
use crate::ln::msgs::MAX_VALUE_MSAT;
94+
use crate::ln::msgs::{DecodeError, MAX_VALUE_MSAT};
9595
use crate::offers::merkle::TlvStream;
9696
use crate::offers::parse::{Bech32Encode, Bolt12ParseError, Bolt12SemanticError, ParsedMessage};
9797
use crate::offers::signer::{Metadata, MetadataMaterial, self};
98-
use crate::util::ser::{HighZeroBytesDroppedBigSize, WithoutLength, Writeable, Writer};
98+
use crate::util::ser::{HighZeroBytesDroppedBigSize, Readable, WithoutLength, Writeable, Writer};
9999
use crate::util::string::PrintableString;
100100

101101
#[cfg(not(c_bindings))]
@@ -892,6 +892,13 @@ impl OfferContents {
892892
}
893893
}
894894

895+
impl Readable for Offer {
896+
fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
897+
let bytes: WithoutLength<Vec<u8>> = Readable::read(reader)?;
898+
Self::try_from(bytes.0).map_err(|_| DecodeError::InvalidValue)
899+
}
900+
}
901+
895902
impl Writeable for Offer {
896903
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
897904
WithoutLength(&self.bytes).write(writer)

0 commit comments

Comments
 (0)