Skip to content

Commit d8b509a

Browse files
committed
Offer features for BOLT 12
The offer message in BOLT 12 contains a features TLV record. Add a corresponding OfferFeatures type where the length is not included in the serialization as it would be redundant with the record length.
1 parent 0472c2f commit d8b509a

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

lightning/src/ln/features.rs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ mod sealed {
235235
BasicMPP,
236236
],
237237
});
238+
define_context!(OfferContext {
239+
required_features: [],
240+
optional_features: [],
241+
});
238242
// This isn't a "real" feature context, and is only used in the channel_type field in an
239243
// `OpenChannel` message.
240244
define_context!(ChannelTypeContext {
@@ -495,6 +499,8 @@ pub type NodeFeatures = Features<sealed::NodeContext>;
495499
pub type ChannelFeatures = Features<sealed::ChannelContext>;
496500
/// Features used within an invoice.
497501
pub type InvoiceFeatures = Features<sealed::InvoiceContext>;
502+
/// Features used within an offer.
503+
pub type OfferFeatures = Features<sealed::OfferContext>;
498504

499505
/// Features used within the channel_type field in an OpenChannel message.
500506
///
@@ -811,21 +817,26 @@ impl_feature_len_prefixed_write!(ChannelFeatures);
811817
impl_feature_len_prefixed_write!(NodeFeatures);
812818
impl_feature_len_prefixed_write!(InvoiceFeatures);
813819

814-
// Because ChannelTypeFeatures only appears inside of TLVs, it doesn't have a length prefix when
815-
// serialized. Thus, we can't use `impl_feature_len_prefixed_write`, above, and have to write our
816-
// own serialization.
817-
impl Writeable for ChannelTypeFeatures {
818-
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
819-
self.write_be(w)
820-
}
821-
}
822-
impl Readable for ChannelTypeFeatures {
823-
fn read<R: io::Read>(r: &mut R) -> Result<Self, DecodeError> {
824-
let v = io_extras::read_to_end(r)?;
825-
Ok(Self::from_be_bytes(v))
820+
// Some features only appears inside of TLVs, so they don't have a length prefix when serialized.
821+
macro_rules! impl_feature_tlv_value_write {
822+
($features: ident) => {
823+
impl Writeable for $features {
824+
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
825+
self.write_be(w)
826+
}
827+
}
828+
impl Readable for $features {
829+
fn read<R: io::Read>(r: &mut R) -> Result<Self, DecodeError> {
830+
let v = io_extras::read_to_end(r)?;
831+
Ok(Self::from_be_bytes(v))
832+
}
833+
}
826834
}
827835
}
828836

837+
impl_feature_tlv_value_write!(ChannelTypeFeatures);
838+
impl_feature_tlv_value_write!(OfferFeatures);
839+
829840
#[cfg(test)]
830841
mod tests {
831842
use super::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, InvoiceFeatures, NodeFeatures};

0 commit comments

Comments
 (0)