| | 1 | | using Microsoft.EntityFrameworkCore; |
| | 2 | | using Microsoft.EntityFrameworkCore.Metadata.Builders; |
| | 3 | |
|
| | 4 | | namespace NLightning.Infrastructure.Persistence.EntityConfiguration.Channel; |
| | 5 | |
|
| | 6 | | using Domain.Channels.Constants; |
| | 7 | | using Entities.Channel; |
| | 8 | | using Enums; |
| | 9 | | using ValueConverters; |
| | 10 | |
|
| | 11 | | public static class ChannelConfigEntityConfiguration |
| | 12 | | { |
| | 13 | | public static void ConfigureChannelConfigEntity(this ModelBuilder modelBuilder, DatabaseType databaseType) |
| | 14 | | { |
| 0 | 15 | | modelBuilder.Entity<ChannelConfigEntity>(entity => |
| 0 | 16 | | { |
| 0 | 17 | | // Set PrimaryKey |
| 0 | 18 | | entity.HasKey(e => e.ChannelId); |
| 0 | 19 | |
|
| 0 | 20 | | // Set required props |
| 0 | 21 | | entity.Property(e => e.ChannelId) |
| 0 | 22 | | .HasConversion<ChannelIdConverter>() |
| 0 | 23 | | .IsRequired(); |
| 0 | 24 | | entity.Property(e => e.MinimumDepth).IsRequired(); |
| 0 | 25 | | entity.Property(e => e.ToSelfDelay).IsRequired(); |
| 0 | 26 | | entity.Property(e => e.MaxAcceptedHtlcs).IsRequired(); |
| 0 | 27 | | entity.Property(e => e.LocalDustLimitAmountSats).IsRequired(); |
| 0 | 28 | | entity.Property(e => e.RemoteDustLimitAmountSats).IsRequired(); |
| 0 | 29 | | entity.Property(e => e.HtlcMinimumMsat).IsRequired(); |
| 0 | 30 | | entity.Property(e => e.MaxHtlcAmountInFlight).IsRequired(); |
| 0 | 31 | | entity.Property(e => e.FeeRatePerKwSatoshis).IsRequired(); |
| 0 | 32 | | entity.Property(e => e.OptionAnchorOutputs).IsRequired(); |
| 0 | 33 | |
|
| 0 | 34 | | // Nullable byte[] properties |
| 0 | 35 | | entity.Property(e => e.LocalUpfrontShutdownScript).IsRequired(false); |
| 0 | 36 | | entity.Property(e => e.RemoteUpfrontShutdownScript).IsRequired(false); |
| 0 | 37 | |
|
| 0 | 38 | | if (databaseType == DatabaseType.MicrosoftSql) |
| 0 | 39 | | { |
| 0 | 40 | | OptimizeConfigurationForSqlServer(entity); |
| 0 | 41 | | } |
| 0 | 42 | | }); |
| 0 | 43 | | } |
| | 44 | |
|
| | 45 | | private static void OptimizeConfigurationForSqlServer(EntityTypeBuilder<ChannelConfigEntity> entity) |
| | 46 | | { |
| 0 | 47 | | entity.Property(e => e.ChannelId).HasColumnType($"varbinary({ChannelConstants.ChannelIdLength})"); |
| 0 | 48 | | entity.Property(e => e.LocalUpfrontShutdownScript).HasColumnType("varbinary(max)"); |
| 0 | 49 | | entity.Property(e => e.RemoteUpfrontShutdownScript).HasColumnType("varbinary(max)"); |
| 0 | 50 | | } |
| | 51 | | } |