@@ -32,6 +32,7 @@ use ln::msgs::DecodeError;
32
32
use util:: ser:: { Readable , Writeable , Writer } ;
33
33
34
34
mod sealed {
35
+ use ln:: features:: Features ;
35
36
/// The context in which [`Features`] are applicable. Defines which features are required and
36
37
/// which are optional for the context.
37
38
///
@@ -146,7 +147,8 @@ mod sealed {
146
147
///
147
148
/// [`Context`]: trait.Context.html
148
149
macro_rules! define_feature {
149
- ( $odd_bit: expr, $feature: ident, [ $( $context: ty) ,+] , $doc: expr) => {
150
+ ( $odd_bit: expr, $feature: ident, [ $( $context: ty) ,+] , $doc: expr, $supports_setter: ident,
151
+ $requires_setter: ident) => {
150
152
#[ doc = $doc]
151
153
///
152
154
/// See [BOLT #9] for details.
@@ -231,6 +233,16 @@ mod sealed {
231
233
}
232
234
}
233
235
236
+ impl <T : $feature> Features <T > {
237
+ pub fn $supports_setter( & mut self ) {
238
+ <T as $feature>:: set_optional_bit( & mut self . flags) ;
239
+ }
240
+
241
+ pub fn $requires_setter( & mut self ) {
242
+ <T as $feature>:: set_required_bit( & mut self . flags) ;
243
+ }
244
+ }
245
+
234
246
$(
235
247
impl $feature for $context {
236
248
// EVEN_BIT % 2 == 0
@@ -240,28 +252,34 @@ mod sealed {
240
252
const ASSERT_ODD_BIT_PARITY : usize = ( <Self as $feature>:: ODD_BIT % 2 ) - 1 ;
241
253
}
242
254
) *
255
+
243
256
}
244
257
}
245
258
246
259
define_feature ! ( 1 , DataLossProtect , [ InitContext , NodeContext ] ,
247
- "Feature flags for `option_data_loss_protect`." ) ;
260
+ "Feature flags for `option_data_loss_protect`." , set_supports_data_loss_protect,
261
+ set_requires_data_loss_protect) ;
248
262
// NOTE: Per Bolt #9, initial_routing_sync has no even bit.
249
- define_feature ! ( 3 , InitialRoutingSync , [ InitContext ] ,
250
- "Feature flags for `initial_routing_sync`." ) ;
263
+ define_feature ! ( 3 , InitialRoutingSync , [ InitContext ] , "Feature flags for `initial_routing_sync`." ,
264
+ set_supports_initial_routing_sync , set_requires_initial_routing_sync ) ;
251
265
define_feature ! ( 5 , UpfrontShutdownScript , [ InitContext , NodeContext ] ,
252
- "Feature flags for `option_upfront_shutdown_script`." ) ;
266
+ "Feature flags for `option_upfront_shutdown_script`." , set_supports_upfront_shutdown_script,
267
+ set_requires_upfront_shutdown_script) ;
253
268
define_feature ! ( 7 , GossipQueries , [ InitContext , NodeContext ] ,
254
- "Feature flags for `gossip_queries`." ) ;
269
+ "Feature flags for `gossip_queries`." , set_supports_gossip_queries , set_requires_gossip_queries ) ;
255
270
define_feature ! ( 9 , VariableLengthOnion , [ InitContext , NodeContext ] ,
256
- "Feature flags for `var_onion_optin`." ) ;
271
+ "Feature flags for `var_onion_optin`." , set_supports_variable_length_onion,
272
+ set_requires_variable_length_onion) ;
257
273
define_feature ! ( 13 , StaticRemoteKey , [ InitContext , NodeContext ] ,
258
- "Feature flags for `option_static_remotekey`." ) ;
274
+ "Feature flags for `option_static_remotekey`." , set_supports_static_remote_key,
275
+ set_requires_static_remote_key) ;
259
276
define_feature ! ( 15 , PaymentSecret , [ InitContext , NodeContext ] ,
260
- "Feature flags for `payment_secret`." ) ;
277
+ "Feature flags for `payment_secret`." , set_supports_payment_secret , set_requires_payment_secret ) ;
261
278
define_feature ! ( 17 , BasicMPP , [ InitContext , NodeContext ] ,
262
- "Feature flags for `basic_mpp`." ) ;
279
+ "Feature flags for `basic_mpp`." , set_supports_basic_mpp , set_requires_basic_mpp ) ;
263
280
define_feature ! ( 27 , ShutdownAnySegwit , [ InitContext , NodeContext ] ,
264
- "Feature flags for `opt_shutdown_anysegwit`." ) ;
281
+ "Feature flags for `opt_shutdown_anysegwit`." , set_supports_shutdown_any_segwit,
282
+ set_requires_shutdown_any_segwit) ;
265
283
266
284
#[ cfg( test) ]
267
285
define_context ! ( TestingContext {
@@ -285,7 +303,8 @@ mod sealed {
285
303
286
304
#[ cfg( test) ]
287
305
define_feature ! ( 23 , UnknownFeature , [ TestingContext ] ,
288
- "Feature flags for an unknown feature used in testing." ) ;
306
+ "Feature flags for an unknown feature used in testing." , set_supports_unknown_feature,
307
+ set_requires_unknown_feature) ;
289
308
}
290
309
291
310
/// Tracks the set of features which a node implements, templated by the context in which it
0 commit comments