From: Matt Corallo Date: Fri, 5 Mar 2021 03:10:48 +0000 (-0500) Subject: Create new `InvoiceFeatures` object for Invoice-specific features X-Git-Tag: v0.0.13~1^2~3 X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=rust-lightning;a=commitdiff_plain;h=5b230d9137ed03c0a6739378920947f5ee2f92b9 Create new `InvoiceFeatures` object for Invoice-specific features In the past we skipped doing this since invoice parsing occurs in a different crate. However, we need to accept InvoiceFeatures in routing now that we support MPP route collection, to detect if we can select multiple paths or not. Further, we should probably take rust-lightning-invoice as either a module or a subcrate in this repo. --- diff --git a/lightning/src/ln/features.rs b/lightning/src/ln/features.rs index 35c9410b..efed0b10 100644 --- a/lightning/src/ln/features.rs +++ b/lightning/src/ln/features.rs @@ -140,6 +140,17 @@ mod sealed { required_features: [], optional_features: [], }); + define_context!(InvoiceContext { + required_features: [,,,], + optional_features: [ + // Byte 0 + , + // Byte 1 + VariableLengthOnion | PaymentSecret, + // Byte 2 + BasicMPP, + ], + }); /// Defines a feature with the given bits for the specified [`Context`]s. The generated trait is /// useful for manipulating feature flags. @@ -252,13 +263,13 @@ mod sealed { "Feature flags for `option_upfront_shutdown_script`."); define_feature!(7, GossipQueries, [InitContext, NodeContext], "Feature flags for `gossip_queries`."); - define_feature!(9, VariableLengthOnion, [InitContext, NodeContext], + define_feature!(9, VariableLengthOnion, [InitContext, NodeContext, InvoiceContext], "Feature flags for `var_onion_optin`."); define_feature!(13, StaticRemoteKey, [InitContext, NodeContext], "Feature flags for `option_static_remotekey`."); - define_feature!(15, PaymentSecret, [InitContext, NodeContext], + define_feature!(15, PaymentSecret, [InitContext, NodeContext, InvoiceContext], "Feature flags for `payment_secret`."); - define_feature!(17, BasicMPP, [InitContext, NodeContext], + define_feature!(17, BasicMPP, [InitContext, NodeContext, InvoiceContext], "Feature flags for `basic_mpp`."); define_feature!(27, ShutdownAnySegwit, [InitContext, NodeContext], "Feature flags for `opt_shutdown_anysegwit`."); @@ -323,6 +334,8 @@ pub type InitFeatures = Features; pub type NodeFeatures = Features; /// Features used within a `channel_announcement` message. pub type ChannelFeatures = Features; +/// Features used within an invoice. +pub type InvoiceFeatures = Features; impl InitFeatures { /// Writes all features present up to, and including, 13. @@ -359,6 +372,14 @@ impl InitFeatures { } } +impl InvoiceFeatures { + /// Converts `InvoiceFeatures` to `Features`. Only known `InvoiceFeatures` relevant to + /// context `C` are included in the result. + pub(crate) fn to_context(&self) -> Features { + self.to_context_internal() + } +} + impl Features { /// Create a blank Features with no features set pub fn empty() -> Self {