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
loggerILogger<ChannelMemoryRepository>
Methods
AddChannel(ChannelModel)
Adds the specified channel to the in-memory channel repository.
public void AddChannel(ChannelModel channel)
Parameters
channelChannelModelThe 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
compactPubKeyCompactPubKeyThe public key associated with the channel to add, in compact format.
channelChannelModelThe 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
predicateFunc<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
channelIdChannelIdThe unique identifier of the channel to retrieve.
channelChannelModelWhen this method returns, contains the channel associated with the specified ID, if found; otherwise,
null.
Returns
- bool
trueif 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
channelIdChannelIdThe unique identifier of the channel whose state is to be retrieved.
channelStateChannelStateWhen this method returns, contains the state of the channel associated with the specified ID, if found; otherwise,
ChannelState.None.
Returns
- bool
trueif 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
compactPubKeyCompactPubKeyThe compact public key associated with the target channel.
channelIdChannelIdThe unique identifier of the channel to locate.
channelChannelModelWhen this method returns, contains the temporary channel associated with the specified public key and channel ID, if found; otherwise,
null.
Returns
- bool
trueif 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
compactPubKeyCompactPubKeyThe compact public key associated with the channel.
channelIdChannelIdThe unique identifier of the channel to retrieve.
channelStateChannelStateWhen this method returns, contains the state of the channel if found; otherwise,
ChannelState.None.
Returns
- bool
trueif 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
channelIdChannelIdThe unique identifier of the channel to be removed.
Returns
- bool
trueif 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
compactPubKeyCompactPubKeyThe public key of the channel's peer used to identify the temporary channel.
channelIdChannelIdThe unique identifier of the channel to be removed.
Returns
- bool
trueif the temporary channel was successfully removed; otherwise,false.
UpdateChannel(ChannelModel)
Updates the specified channel in the memory repository.
public void UpdateChannel(ChannelModel channel)
Parameters
channelChannelModelThe 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
compactPubKeyCompactPubKeyThe compact public key identifying the temporary channel to update.
channelChannelModelThe 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
oldChannelIdChannelIdThe unique identifier of the existing channel to be upgraded.
tempChannelChannelModelThe 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
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
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.