Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix null commitments #19

Merged
merged 2 commits into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions Tzkt.Sync/Protocols/Handlers/Initiator/Commits/BootstrapCommit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public async Task Init(Block block, RawBlock rawBlock)

#region parameters
var protoParams = Bson.Parse<RawProtoParameters>(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])
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public Task Init(Block block, List<Account> accounts, IEnumerable<Commitment> 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)
};

Expand Down