| | 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 Domain.Crypto.Constants; |
| | 8 | | using Entities.Channel; |
| | 9 | | using Enums; |
| | 10 | | using ValueConverters; |
| | 11 | |
|
| | 12 | | public static class ChannelKeySetEntityConfiguration |
| | 13 | | { |
| | 14 | | public static void ConfigureChannelKeySetEntity(this ModelBuilder modelBuilder, DatabaseType databaseType) |
| | 15 | | { |
| 0 | 16 | | modelBuilder.Entity<ChannelKeySetEntity>(entity => |
| 0 | 17 | | { |
| 0 | 18 | | // Composite key |
| 0 | 19 | | entity.HasKey(e => new { e.ChannelId, e.IsLocal }); |
| 0 | 20 | |
|
| 0 | 21 | | // Set required props |
| 0 | 22 | | entity.Property(e => e.IsLocal).IsRequired(); |
| 0 | 23 | | entity.Property(e => e.CurrentPerCommitmentIndex).IsRequired(); |
| 0 | 24 | | entity.Property(e => e.KeyIndex).IsRequired(); |
| 0 | 25 | |
|
| 0 | 26 | | // Required byte[] properties |
| 0 | 27 | | entity.Property(e => e.ChannelId) |
| 0 | 28 | | .HasConversion<ChannelIdConverter>() |
| 0 | 29 | | .IsRequired(); |
| 0 | 30 | | entity.Property(e => e.FundingPubKey).IsRequired(); |
| 0 | 31 | | entity.Property(e => e.RevocationBasepoint).IsRequired(); |
| 0 | 32 | | entity.Property(e => e.PaymentBasepoint).IsRequired(); |
| 0 | 33 | | entity.Property(e => e.DelayedPaymentBasepoint).IsRequired(); |
| 0 | 34 | | entity.Property(e => e.HtlcBasepoint).IsRequired(); |
| 0 | 35 | | entity.Property(e => e.CurrentPerCommitmentPoint).IsRequired(); |
| 0 | 36 | |
|
| 0 | 37 | | // Nullable byte[] properties |
| 0 | 38 | | entity.Property(e => e.LastRevealedPerCommitmentSecret).IsRequired(false); |
| 0 | 39 | |
|
| 0 | 40 | | if (databaseType == DatabaseType.MicrosoftSql) |
| 0 | 41 | | OptimizeConfigurationForSqlServer(entity); |
| 0 | 42 | | }); |
| 0 | 43 | | } |
| | 44 | |
|
| | 45 | | private static void OptimizeConfigurationForSqlServer(EntityTypeBuilder<ChannelKeySetEntity> entity) |
| | 46 | | { |
| 0 | 47 | | entity.Property(e => e.ChannelId).HasColumnType($"varbinary({ChannelConstants.ChannelIdLength})"); |
| 0 | 48 | | entity.Property(e => e.FundingPubKey).HasColumnType($"varbinary({CryptoConstants.CompactPubkeyLen})"); |
| 0 | 49 | | entity.Property(e => e.RevocationBasepoint).HasColumnType($"varbinary({CryptoConstants.CompactPubkeyLen})"); |
| 0 | 50 | | entity.Property(e => e.PaymentBasepoint).HasColumnType($"varbinary({CryptoConstants.CompactPubkeyLen})"); |
| 0 | 51 | | entity.Property(e => e.DelayedPaymentBasepoint).HasColumnType($"varbinary({CryptoConstants.CompactPubkeyLen})"); |
| 0 | 52 | | entity.Property(e => e.HtlcBasepoint).HasColumnType($"varbinary({CryptoConstants.CompactPubkeyLen})"); |
| 0 | 53 | | entity.Property(e => e.CurrentPerCommitmentPoint) |
| 0 | 54 | | .HasColumnType($"varbinary({CryptoConstants.CompactPubkeyLen})"); |
| 0 | 55 | | } |
| | 56 | | } |