< Summary - Combined Code Coverage

Information
Class: NLightning.Infrastructure.Repositories.Database.Channel.ChannelConfigDbRepository
Assembly: NLightning.Infrastructure.Repositories
File(s): /home/runner/work/nlightning/nlightning/src/NLightning.Infrastructure.Repositories/Database/Channel/ChannelConfigDbRepository.cs
Tag: 36_15743069263
Line coverage
0%
Covered lines: 0
Uncovered lines: 54
Coverable lines: 54
Total lines: 82
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 14
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
Add(...)100%210%
Add(...)100%210%
Update(...)100%210%
Update(...)100%210%
DeleteAsync(...)100%210%
DeleteAsync(...)100%210%
GetByChannelIdAsync()0%620%
GetByChannelIdAsync()0%620%
MapDomainToEntity(...)0%4260%
MapDomainToEntity(...)0%4260%
MapEntityToDomain(...)0%4260%
MapEntityToDomain(...)0%4260%

File(s)

/home/runner/work/nlightning/nlightning/src/NLightning.Infrastructure.Repositories/Database/Channel/ChannelConfigDbRepository.cs

#LineLine coverage
 1using NLightning.Domain.Bitcoin.ValueObjects;
 2using NLightning.Domain.Channels.Interfaces;
 3using NLightning.Domain.Channels.ValueObjects;
 4using NLightning.Domain.Enums;
 5using NLightning.Domain.Money;
 6using NLightning.Infrastructure.Persistence.Contexts;
 7using NLightning.Infrastructure.Persistence.Entities.Channel;
 8
 9namespace NLightning.Infrastructure.Repositories.Database.Channel;
 10
 11public class ChannelConfigDbRepository(NLightningDbContext context)
 012    : BaseDbRepository<ChannelConfigEntity>(context), IChannelConfigDbRepository
 13{
 14    public void Add(ChannelId channelId, ChannelConfig config)
 015    {
 016        var configEntity = MapDomainToEntity(channelId, config);
 017        Insert(configEntity);
 018    }
 19
 20    public void Update(ChannelId channelId, ChannelConfig config)
 021    {
 022        var configEntity = MapDomainToEntity(channelId, config);
 023        base.Update(configEntity);
 024    }
 25
 26    public Task DeleteAsync(ChannelId channelId)
 027    {
 028        return DeleteByIdAsync(channelId);
 029    }
 30
 31    public async Task<ChannelConfig?> GetByChannelIdAsync(ChannelId channelId)
 032    {
 033        var configEntity = await GetByIdAsync(channelId);
 34
 035        return configEntity == null ? null : MapEntityToDomain(configEntity);
 036    }
 37
 38    internal static ChannelConfigEntity MapDomainToEntity(ChannelId channelId, ChannelConfig config)
 039    {
 040        return new ChannelConfigEntity
 041        {
 042            ChannelId = channelId,
 043            ChannelReserveAmountSats = config.ChannelReserveAmount?.Satoshi,
 044            FeeRatePerKwSatoshis = config.FeeRateAmountPerKw.Satoshi,
 045            HtlcMinimumMsat = config.HtlcMinimumAmount.MilliSatoshi,
 046            LocalDustLimitAmountSats = config.LocalDustLimitAmount.Satoshi,
 047            LocalUpfrontShutdownScript = config.LocalUpfrontShutdownScript,
 048            MaxAcceptedHtlcs = config.MaxAcceptedHtlcs,
 049            MaxHtlcAmountInFlight = config.MaxHtlcAmountInFlight.MilliSatoshi,
 050            MinimumDepth = config.MinimumDepth,
 051            OptionAnchorOutputs = config.OptionAnchorOutputs,
 052            RemoteDustLimitAmountSats = config.RemoteDustLimitAmount.Satoshi,
 053            RemoteUpfrontShutdownScript = config.RemoteShutdownScriptPubKey,
 054            ToSelfDelay = config.ToSelfDelay,
 055            UseScidAlias = (byte)config.UseScidAlias
 056        };
 057    }
 58
 59    internal static ChannelConfig MapEntityToDomain(ChannelConfigEntity entity)
 060    {
 061        LightningMoney? channelReserveAmount = null;
 062        if (entity.ChannelReserveAmountSats.HasValue)
 063            channelReserveAmount = LightningMoney.Satoshis(entity.ChannelReserveAmountSats.Value);
 64
 065        BitcoinScript? localUpfrontShutdownScript = null;
 066        if (entity.LocalUpfrontShutdownScript is not null)
 067            localUpfrontShutdownScript = entity.LocalUpfrontShutdownScript;
 68
 069        BitcoinScript? remoteUpfrontShutdownScript = null;
 070        if (entity.RemoteUpfrontShutdownScript is not null)
 071            remoteUpfrontShutdownScript = entity.RemoteUpfrontShutdownScript;
 72
 073        return new ChannelConfig(channelReserveAmount, LightningMoney.Satoshis(entity.FeeRatePerKwSatoshis),
 074                                 LightningMoney.MilliSatoshis(entity.HtlcMinimumMsat),
 075                                 LightningMoney.Satoshis(entity.LocalDustLimitAmountSats), entity.MaxAcceptedHtlcs,
 076                                 LightningMoney.MilliSatoshis(entity.MaxHtlcAmountInFlight), entity.MinimumDepth,
 077                                 entity.OptionAnchorOutputs, LightningMoney.Satoshis(entity.RemoteDustLimitAmountSats),
 078                                 entity.ToSelfDelay, (FeatureSupport)entity.UseScidAlias, localUpfrontShutdownScript,
 079                                 remoteUpfrontShutdownScript
 080        );
 081    }
 82}