From 7241b3e256b74e1163d0ce20ee10c45023230612 Mon Sep 17 00:00:00 2001 From: Groxan <257Byte@gmail.com> Date: Wed, 9 Sep 2020 19:23:06 +0300 Subject: [PATCH 1/2] Fix empty commitments --- .../Initiator/Commits/BootstrapCommit.cs | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/Tzkt.Sync/Protocols/Handlers/Initiator/Commits/BootstrapCommit.cs b/Tzkt.Sync/Protocols/Handlers/Initiator/Commits/BootstrapCommit.cs index 21167a914..c0eb3dfb2 100644 --- a/Tzkt.Sync/Protocols/Handlers/Initiator/Commits/BootstrapCommit.cs +++ b/Tzkt.Sync/Protocols/Handlers/Initiator/Commits/BootstrapCommit.cs @@ -114,7 +114,7 @@ public async Task Init(Block block, RawBlock rawBlock) #region parameters var protoParams = Bson.Parse(rawBlock.Header.Content.Parameters.Substring(8)); - Commitments = protoParams.Commitments.Select(x => new Commitment + Commitments = protoParams.Commitments?.Select(x => new Commitment { Address = x[0], Balance = long.Parse(x[1]) @@ -159,19 +159,22 @@ public override Task Apply() state.MigrationOpsCount += BootstrapedAccounts.Count; } - var conn = Db.Database.GetDbConnection() as NpgsqlConnection; - using var writer = conn.BeginBinaryImport(@"COPY ""Commitments"" (""Balance"", ""Address"") FROM STDIN (FORMAT BINARY)"); - - foreach (var commitment in Commitments) + if (Commitments != null) { - writer.StartRow(); - writer.Write(commitment.Balance); - writer.Write(commitment.Address); + var conn = Db.Database.GetDbConnection() as NpgsqlConnection; + using var writer = conn.BeginBinaryImport(@"COPY ""Commitments"" (""Balance"", ""Address"") FROM STDIN (FORMAT BINARY)"); - state.CommitmentsCount++; - } + foreach (var commitment in Commitments) + { + writer.StartRow(); + writer.Write(commitment.Balance); + writer.Write(commitment.Address); - writer.Complete(); + state.CommitmentsCount++; + } + + writer.Complete(); + } return Task.CompletedTask; } From d17c44c63f67e77a293aee3be2e7494b7b8a5b91 Mon Sep 17 00:00:00 2001 From: Groxan <257Byte@gmail.com> Date: Thu, 10 Sep 2020 01:21:01 +0300 Subject: [PATCH 2/2] fix null commitments --- .../Protocols/Handlers/Initiator/Commits/StatisticsCommit.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tzkt.Sync/Protocols/Handlers/Initiator/Commits/StatisticsCommit.cs b/Tzkt.Sync/Protocols/Handlers/Initiator/Commits/StatisticsCommit.cs index a4321ad27..7b27884fe 100644 --- a/Tzkt.Sync/Protocols/Handlers/Initiator/Commits/StatisticsCommit.cs +++ b/Tzkt.Sync/Protocols/Handlers/Initiator/Commits/StatisticsCommit.cs @@ -20,7 +20,7 @@ public Task Init(Block block, List accounts, IEnumerable co { Level = block.Level, TotalBootstrapped = accounts.Sum(x => x.Balance), - TotalCommitments = commitments.Sum(x => x.Balance), + TotalCommitments = commitments?.Sum(x => x.Balance) ?? 0, TotalVested = accounts.Where(x => x.Type == AccountType.Contract).Sum(x => x.Balance) };