Table of Contents

Class ChannelMemoryRepository

Namespace
NLightning.Infrastructure.Repositories.Memory
Assembly
NLightning.Infrastructure.Repositories.dll
public class ChannelMemoryRepository : IChannelMemoryRepository
Inheritance
ChannelMemoryRepository
Implements
Inherited Members

Constructors

ChannelMemoryRepository(ILogger<ChannelMemoryRepository>)

public ChannelMemoryRepository(ILogger<ChannelMemoryRepository> logger)

Parameters

logger ILogger<ChannelMemoryRepository>

Methods

AddChannel(ChannelModel)

Adds the specified channel to the in-memory channel repository.

public void AddChannel(ChannelModel channel)

Parameters

channel ChannelModel

The channel to be added to the repository.

AddTemporaryChannel(CompactPubKey, ChannelModel)

Adds a temporary channel associated with the specified public key.

public void AddTemporaryChannel(CompactPubKey compactPubKey, ChannelModel channel)

Parameters

compactPubKey CompactPubKey

The public key associated with the channel to add, in compact format.

channel ChannelModel

The channel information to store temporarily.

FindChannels(Func<ChannelModel, bool>)

Retrieves a list of channels that match the specified predicate.

public List<ChannelModel> FindChannels(Func<ChannelModel, bool> predicate)

Parameters

predicate Func<ChannelModel, bool>

A function that defines the criteria to filter channels.

Returns

List<ChannelModel>

A list of channels that match the provided predicate.

TryGetChannel(ChannelId, out ChannelModel)

Attempts to retrieve a channel that matches the specified channel ID.

public bool TryGetChannel(ChannelId channelId, out ChannelModel channel)

Parameters

channelId ChannelId

The unique identifier of the channel to retrieve.

channel ChannelModel

When this method returns, contains the channel associated with the specified ID, if found; otherwise, null.

Returns

bool

true if a channel with the specified ID was found; otherwise, false.

TryGetChannelState(ChannelId, out ChannelState)

Attempts to retrieve the state of a channel that matches the specified channel ID.

public bool TryGetChannelState(ChannelId channelId, out ChannelState channelState)

Parameters

channelId ChannelId

The unique identifier of the channel whose state is to be retrieved.

channelState ChannelState

When this method returns, contains the state of the channel associated with the specified ID, if found; otherwise, ChannelState.None.

Returns

bool

true if a channel with the specified ID was found, allowing its state to be retrieved; otherwise, false.

TryGetTemporaryChannel(CompactPubKey, ChannelId, out ChannelModel)

Attempts to retrieve a temporary channel that matches the specified public key and channel ID.

public bool TryGetTemporaryChannel(CompactPubKey compactPubKey, ChannelId channelId, out ChannelModel channel)

Parameters

compactPubKey CompactPubKey

The compact public key associated with the target channel.

channelId ChannelId

The unique identifier of the channel to locate.

channel ChannelModel

When this method returns, contains the temporary channel associated with the specified public key and channel ID, if found; otherwise, null.

Returns

bool

true if a temporary channel matching the specified public key and channel ID was found; otherwise, false.

TryGetTemporaryChannelState(CompactPubKey, ChannelId, out ChannelState)

Attempts to retrieve the temporary state of a channel that matches the specified public key and channel ID.

public bool TryGetTemporaryChannelState(CompactPubKey compactPubKey, ChannelId channelId, out ChannelState channelState)

Parameters

compactPubKey CompactPubKey

The compact public key associated with the channel.

channelId ChannelId

The unique identifier of the channel to retrieve.

channelState ChannelState

When this method returns, contains the state of the channel if found; otherwise, ChannelState.None.

Returns

bool

true if a temporary channel state matching the specified public key and channel ID was found; otherwise, false.

TryRemoveChannel(ChannelId)

Attempts to remove a channel that matches the specified channel ID.

public bool TryRemoveChannel(ChannelId channelId)

Parameters

channelId ChannelId

The unique identifier of the channel to be removed.

Returns

bool

true if a channel with the specified ID was successfully removed; otherwise, false.

TryRemoveTemporaryChannel(CompactPubKey, ChannelId)

Attempts to remove a temporary channel associated with the specified public key and channel ID.

public bool TryRemoveTemporaryChannel(CompactPubKey compactPubKey, ChannelId channelId)

Parameters

compactPubKey CompactPubKey

The public key of the channel's peer used to identify the temporary channel.

channelId ChannelId

The unique identifier of the channel to be removed.

Returns

bool

true if the temporary channel was successfully removed; otherwise, false.

UpdateChannel(ChannelModel)

Updates the specified channel in the memory repository.

public void UpdateChannel(ChannelModel channel)

Parameters

channel ChannelModel

The channel model to update. The channel must already exist in the repository.

UpdateTemporaryChannel(CompactPubKey, ChannelModel)

Updates the temporary channel associated with the specified compact public key.

public void UpdateTemporaryChannel(CompactPubKey compactPubKey, ChannelModel channel)

Parameters

compactPubKey CompactPubKey

The compact public key identifying the temporary channel to update.

channel ChannelModel

The updated temporary channel model containing new state or configuration.

UpgradeChannel(ChannelId, ChannelModel)

Upgrades an existing channel by removing it from the temporary channel list and adding it to the channel list.

public void UpgradeChannel(ChannelId oldChannelId, ChannelModel tempChannel)

Parameters

oldChannelId ChannelId

The unique identifier of the existing channel to be upgraded.

tempChannel ChannelModel

The temporary channel model that will replace the existing channel.

Remarks

This method is typically used when a channel transitions from a temporary state (e.g., during the opening process) to a fully established state. It ensures that the channel is properly moved from the temporary storage to the main channel repository, allowing it to be managed as a regular channel going forward.

Events

OnChannelUpdated

Event triggered when a channel's data or state has been updated.

public event EventHandler<ChannelUpdatedEventArgs>? OnChannelUpdated

Event Type

EventHandler<ChannelUpdatedEventArgs>

Remarks

This event is raised whenever changes are made to a channel's information or status within the system, providing subscribers the opportunity to take actions or synchronize with the updated channel data.

OnChannelUpgraded

Event triggered when a channel has been successfully upgraded.

public event EventHandler<ChannelUpgradedEventArgs>? OnChannelUpgraded

Event Type

EventHandler<ChannelUpgradedEventArgs>

Remarks

This event is raised after the process of upgrading a channel, transitioning from a temporary or transitional state to its final state within the system. Subscribing to this event enables handlers to respond to the completion of the channel upgrade process.