Skip to content

Commit 5e700e6

Browse files
committed
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.
1 parent 4894d52 commit 5e700e6

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

lightning/src/ln/features.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,17 @@ mod sealed {
140140
required_features: [],
141141
optional_features: [],
142142
});
143+
define_context!(InvoiceContext {
144+
required_features: [,,,],
145+
optional_features: [
146+
// Byte 0
147+
,
148+
// Byte 1
149+
VariableLengthOnion | PaymentSecret,
150+
// Byte 2
151+
BasicMPP,
152+
],
153+
});
143154

144155
/// Defines a feature with the given bits for the specified [`Context`]s. The generated trait is
145156
/// useful for manipulating feature flags.
@@ -256,9 +267,9 @@ mod sealed {
256267
"Feature flags for `var_onion_optin`.");
257268
define_feature!(13, StaticRemoteKey, [InitContext, NodeContext],
258269
"Feature flags for `option_static_remotekey`.");
259-
define_feature!(15, PaymentSecret, [InitContext, NodeContext],
270+
define_feature!(15, PaymentSecret, [InitContext, NodeContext, InvoiceContext],
260271
"Feature flags for `payment_secret`.");
261-
define_feature!(17, BasicMPP, [InitContext, NodeContext],
272+
define_feature!(17, BasicMPP, [InitContext, NodeContext, InvoiceContext],
262273
"Feature flags for `basic_mpp`.");
263274
define_feature!(27, ShutdownAnySegwit, [InitContext, NodeContext],
264275
"Feature flags for `opt_shutdown_anysegwit`.");
@@ -323,6 +334,8 @@ pub type InitFeatures = Features<sealed::InitContext>;
323334
pub type NodeFeatures = Features<sealed::NodeContext>;
324335
/// Features used within a `channel_announcement` message.
325336
pub type ChannelFeatures = Features<sealed::ChannelContext>;
337+
/// Features used within an invoice.
338+
pub type InvoiceFeatures = Features<sealed::InvoiceContext>;
326339

327340
impl InitFeatures {
328341
/// Writes all features present up to, and including, 13.
@@ -359,6 +372,14 @@ impl InitFeatures {
359372
}
360373
}
361374

375+
impl InvoiceFeatures {
376+
/// Converts `InvoiceFeatures` to `Features<C>`. Only known `InvoiceFeatures` relevant to
377+
/// context `C` are included in the result.
378+
pub(crate) fn to_context<C: sealed::Context>(&self) -> Features<C> {
379+
self.to_context_internal()
380+
}
381+
}
382+
362383
impl<T: sealed::Context> Features<T> {
363384
/// Create a blank Features with no features set
364385
pub fn empty() -> Self {

0 commit comments

Comments
 (0)