add method list_enabled_ln_feature_bits
This commit is contained in:
@@ -1468,28 +1468,28 @@ class LnFeatures(IntFlag):
|
||||
|
||||
def for_init_message(self) -> 'LnFeatures':
|
||||
features = LnFeatures(0)
|
||||
for flag in list_enabled_bits(self):
|
||||
for flag in list_enabled_ln_feature_bits(self):
|
||||
if LnFeatureContexts.INIT & _ln_feature_contexts[1 << flag]:
|
||||
features |= (1 << flag)
|
||||
return features
|
||||
|
||||
def for_node_announcement(self) -> 'LnFeatures':
|
||||
features = LnFeatures(0)
|
||||
for flag in list_enabled_bits(self):
|
||||
for flag in list_enabled_ln_feature_bits(self):
|
||||
if LnFeatureContexts.NODE_ANN & _ln_feature_contexts[1 << flag]:
|
||||
features |= (1 << flag)
|
||||
return features
|
||||
|
||||
def for_invoice(self) -> 'LnFeatures':
|
||||
features = LnFeatures(0)
|
||||
for flag in list_enabled_bits(self):
|
||||
for flag in list_enabled_ln_feature_bits(self):
|
||||
if LnFeatureContexts.INVOICE & _ln_feature_contexts[1 << flag]:
|
||||
features |= (1 << flag)
|
||||
return features
|
||||
|
||||
def for_channel_announcement(self) -> 'LnFeatures':
|
||||
features = LnFeatures(0)
|
||||
for flag in list_enabled_bits(self):
|
||||
for flag in list_enabled_ln_feature_bits(self):
|
||||
ctxs = _ln_feature_contexts[1 << flag]
|
||||
if LnFeatureContexts.CHAN_ANN_AS_IS & ctxs:
|
||||
features |= (1 << flag)
|
||||
@@ -1627,6 +1627,19 @@ def get_ln_flag_pair_of_bit(flag_bit: int) -> int:
|
||||
return flag_bit - 1
|
||||
|
||||
|
||||
def list_enabled_ln_feature_bits(features: int) -> tuple[int, ...]:
|
||||
"""Returns a list of enabled feature bits. If both opt and req are set, only
|
||||
req will be included in the result."""
|
||||
all_enabled_bits = list_enabled_bits(features)
|
||||
single_feature_bits: set[int] = set()
|
||||
for bit in all_enabled_bits:
|
||||
if bit % 2 == 0: # even bit, always added
|
||||
single_feature_bits.add(bit)
|
||||
elif bit - 1 not in single_feature_bits:
|
||||
# add if we haven't already added the corresponding req (even) bit
|
||||
single_feature_bits.add(bit)
|
||||
return tuple(sorted(single_feature_bits))
|
||||
|
||||
|
||||
class IncompatibleOrInsaneFeatures(Exception): pass
|
||||
class UnknownEvenFeatureBits(IncompatibleOrInsaneFeatures): pass
|
||||
|
||||
Reference in New Issue
Block a user