Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Readable for Offer and Refund #2965

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions lightning/src/offers/offer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,13 @@ impl OfferContents {
}
}

impl Readable for Offer {
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 Offer {
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
WithoutLength(&self.bytes).write(writer)
Expand Down
9 changes: 8 additions & 1 deletion lightning/src/offers/refund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down Expand Up @@ -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)
Expand Down