Table of Contents

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

int

Methods

Combine(Features, Features)

Combines two feature sets.

public static Features Combine(Features first, Features second)

Parameters

first Features

The first feature set.

second Features

The second feature set.

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 Stream

The stream to read from.

includeLength bool

If the length of the byte array is included.

Returns

Task<Features>

The deserialized features.

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 BitReader

The bit reader to read from.

length int

The number of bits to read.

shouldPad bool

If 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 Feature

The 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 Features

The 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

feature Feature

Feature to check.

isCompulsory bool

If the feature is compulsory.

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 int

The bit position of the feature to check.

isCompulsory bool

If 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 Stream

The stream to write to.

asGlobal bool

If the features should be serialized as a global feature set.

includeLength bool

If the length of the byte array should be included.

Returns

Task

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 Feature

The feature to set.

isCompulsory bool

If the feature is compulsory.

isSet bool

true 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 int

The bit position of the feature to set.

isSet bool

true 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)

Parameters

bitWriter BitWriter
length int
shouldPad bool