X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Ffeatures.rs;h=77d0fa4529fb2ea526682079229b81fa9165ddf6;hb=384c4dc7753e4b7ac53ea380e52809babd8f0f9b;hp=b372e6af6bf3df3fcf50a8c2ea3177c7f9989e07;hpb=9170804ca467cf624b87737752aedb0866d7fc49;p=rust-lightning diff --git a/lightning/src/ln/features.rs b/lightning/src/ln/features.rs index b372e6af..77d0fa45 100644 --- a/lightning/src/ln/features.rs +++ b/lightning/src/ln/features.rs @@ -56,20 +56,20 @@ //! [BOLT #9]: https://github.com/lightning/bolts/blob/master/09-features.md //! [messages]: crate::ln::msgs -use {io, io_extras}; -use prelude::*; +use crate::{io, io_extras}; +use crate::prelude::*; use core::{cmp, fmt}; use core::hash::{Hash, Hasher}; use core::marker::PhantomData; use bitcoin::bech32; use bitcoin::bech32::{Base32Len, FromBase32, ToBase32, u5, WriteBase32}; -use ln::msgs::DecodeError; -use util::ser::{Readable, Writeable, Writer}; +use crate::ln::msgs::DecodeError; +use crate::util::ser::{Readable, Writeable, Writer}; mod sealed { - use prelude::*; - use ln::features::Features; + use crate::prelude::*; + use crate::ln::features::Features; /// The context in which [`Features`] are applicable. Defines which features are known to the /// implementation, though specification of them as required or optional is up to the code @@ -157,6 +157,7 @@ mod sealed { // Byte 2 BasicMPP, ]); + define_context!(OfferContext, []); // This isn't a "real" feature context, and is only used in the channel_type field in an // `OpenChannel` message. define_context!(ChannelTypeContext, [ @@ -366,7 +367,7 @@ mod sealed { supports_keysend, requires_keysend); #[cfg(test)] - define_feature!(123456789, UnknownFeature, [NodeContext, ChannelContext, InvoiceContext], + define_feature!(123456789, UnknownFeature, [NodeContext, ChannelContext, InvoiceContext, OfferContext], "Feature flags for an unknown feature used in testing.", set_unknown_feature_optional, set_unknown_feature_required, supports_unknown_test_feature, requires_unknown_test_feature); } @@ -425,6 +426,8 @@ pub type NodeFeatures = Features; pub type ChannelFeatures = Features; /// Features used within an invoice. pub type InvoiceFeatures = Features; +/// Features used within an offer. +pub type OfferFeatures = Features; /// Features used within the channel_type field in an OpenChannel message. /// @@ -684,6 +687,15 @@ impl Features { } } +#[cfg(test)] +impl Features { + pub(crate) fn unknown() -> Self { + let mut features = Self::empty(); + features.set_unknown_feature_required(); + features + } +} + macro_rules! impl_feature_len_prefixed_write { ($features: ident) => { impl Writeable for $features { @@ -704,21 +716,26 @@ impl_feature_len_prefixed_write!(ChannelFeatures); impl_feature_len_prefixed_write!(NodeFeatures); impl_feature_len_prefixed_write!(InvoiceFeatures); -// Because ChannelTypeFeatures only appears inside of TLVs, it doesn't have a length prefix when -// serialized. Thus, we can't use `impl_feature_len_prefixed_write`, above, and have to write our -// own serialization. -impl Writeable for ChannelTypeFeatures { - fn write(&self, w: &mut W) -> Result<(), io::Error> { - self.write_be(w) - } -} -impl Readable for ChannelTypeFeatures { - fn read(r: &mut R) -> Result { - let v = io_extras::read_to_end(r)?; - Ok(Self::from_be_bytes(v)) +// Some features only appear inside of TLVs, so they don't have a length prefix when serialized. +macro_rules! impl_feature_tlv_write { + ($features: ident) => { + impl Writeable for $features { + fn write(&self, w: &mut W) -> Result<(), io::Error> { + self.write_be(w) + } + } + impl Readable for $features { + fn read(r: &mut R) -> Result { + let v = io_extras::read_to_end(r)?; + Ok(Self::from_be_bytes(v)) + } + } } } +impl_feature_tlv_write!(ChannelTypeFeatures); +impl_feature_tlv_write!(OfferFeatures); + #[cfg(test)] mod tests { use super::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, InvoiceFeatures, NodeFeatures, sealed};