Class Features
- Namespace
- NLightning.Bolts.BOLT9
- Assembly
- NLightning.Bolts.dll
Represents the features supported by a node. BOLT-9
public class Features
- Inheritance
-
Features
- Inherited Members
Constructors
Features()
Initializes a new instance of the Features class.
public Features()
Remarks
Always set the bit of VAR_ONION_OPTIN as Optional.
Properties
SizeInBits
Gets the position of the last index of one in the BitArray and add 1 because arrays starts at 0.
public int SizeInBits { get; }
Property Value
Methods
Combine(Features, Features)
Combines two feature sets.
public static Features Combine(Features first, Features second)
Parameters
Returns
- Features
The combined feature set.
Remarks
The combined feature set is the logical OR of the two feature sets.
DeserializeAsync(Stream, bool)
Deserializes the features from a binary reader.
public static Task<Features> DeserializeAsync(Stream stream, bool includeLength = true)
Parameters
stream
StreamThe stream to read from.
includeLength
boolIf the length of the byte array is included.
Returns
Remarks
If the length of the byte array is included, the first 2 bytes are read as the length of the byte array.
Exceptions
- SerializationException
Error deserializing Features
DeserializeFromBitReader(BitReader, int, bool)
Deserializes the features from a BitReader.
public static Features DeserializeFromBitReader(BitReader bitReader, int length, bool shouldPad)
Parameters
bitReader
BitReaderThe bit reader to read from.
length
intThe number of bits to read.
shouldPad
boolIf the bit array should be padded.
Returns
- Features
The deserialized features.
Exceptions
- SerializationException
Error deserializing Features
DeserializeFromBytes(byte[])
Deserializes the features from a byte array.
public static Features DeserializeFromBytes(byte[] data)
Parameters
data
byte[]The byte array to deserialize from.
Returns
- Features
The deserialized features.
Remarks
The byte array can have a length less than or equal to 8 bytes.
Exceptions
- SerializationException
Error deserializing Features
HasFeature(Feature)
Checks if a feature is set.
public bool HasFeature(Feature feature)
Parameters
feature
FeatureThe feature to check.
Returns
- bool
true if the feature is set, false otherwise.
Remarks
We don't care if the feature is compulsory or optional.
IsCompatible(Features)
Check if this feature set is compatible with the other provided feature set.
public bool IsCompatible(Features other)
Parameters
other
FeaturesThe other feature set to check compatibility with.
Returns
- bool
true if the feature sets are compatible, false otherwise.
Remarks
The other feature set must support the var_onion_optin feature. The other feature set must have all dependencies set.
IsFeatureSet(Feature, bool)
Checks if a feature is set.
public bool IsFeatureSet(Feature feature, bool isCompulsory)
Parameters
Returns
- bool
true if the feature is set, false otherwise.
IsFeatureSet(int, bool)
Checks if a feature is set.
public bool IsFeatureSet(int bitPosition, bool isCompulsory)
Parameters
bitPosition
intThe bit position of the feature to check.
isCompulsory
boolIf the feature is compulsory.
Returns
- bool
true if the feature is set, false otherwise.
IsOptionAnchorsSet()
Checks if the option_anchor_outputs or option_anchors_zero_fee_htlc_tx feature is set.
public bool IsOptionAnchorsSet()
Returns
- bool
true if one of the features are set, false otherwise.
SerializeAsync(Stream, bool, bool)
Serializes the features to a binary writer.
public Task SerializeAsync(Stream stream, bool asGlobal = false, bool includeLength = true)
Parameters
stream
StreamThe stream to write to.
asGlobal
boolIf the features should be serialized as a global feature set.
includeLength
boolIf the length of the byte array should be included.
Returns
Remarks
If the features are serialized as a global feature set, only the first 13 bits are serialized.
SetFeature(Feature, bool, bool)
Sets a feature.
public void SetFeature(Feature feature, bool isCompulsory, bool isSet = true)
Parameters
feature
FeatureThe feature to set.
isCompulsory
boolIf the feature is compulsory.
isSet
booltrue to set the feature, false to unset it
Remarks
If the feature has dependencies, they will be set first. The dependencies keep the same isCompulsory value as the feature being set.
SetFeature(int, bool)
Sets a feature.
public void SetFeature(int bitPosition, bool isSet)
Parameters
bitPosition
intThe bit position of the feature to set.
isSet
booltrue to set the feature, false to unset it
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.
WriteToBitWriter(BitWriter, int, bool)
Serializes the features to a byte array.
public void WriteToBitWriter(BitWriter bitWriter, int length, bool shouldPad)