Skip to content

Commit

Permalink
Handle missed balance_updates in failed increase_paid_storage op
Browse files Browse the repository at this point in the history
  • Loading branch information
Groxan committed Sep 19, 2022
1 parent 7cf428d commit 783ecd5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public virtual async Task Apply(Block block, JsonElement content)
if (parentTx.Status != OperationStatus.Applied || result.RequiredString("status") != "applied")
return;

var consumedGas = (int)((result.RequiredInt64("consumed_milligas") + 999) / 1000);
var consumedGas = (int)(((result.OptionalInt64("consumed_milligas") ?? 0) + 999) / 1000);

var contractEvent = new ContractEvent
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public virtual async Task Apply(Block block, JsonElement op, JsonElement content
var contract = await Cache.Accounts.GetAsync(content.RequiredString("destination")) as Contract;

var result = content.Required("metadata").Required("operation_result");
var balanceUpdate = result.RequiredArray("balance_updates").EnumerateArray()
var balanceUpdate = result.OptionalArray("balance_updates")?.EnumerateArray()
.FirstOrDefault(x => x.RequiredString("kind") == "burned" && x.RequiredString("category") == "storage fees");
var storageFee = balanceUpdate.ValueKind != JsonValueKind.Undefined
? balanceUpdate.RequiredInt64("change")
var storageFee = balanceUpdate is JsonElement el && el.ValueKind != JsonValueKind.Undefined
? el.RequiredInt64("change")
: 0;

var operation = new IncreasePaidStorageOperation
Expand Down Expand Up @@ -53,7 +53,7 @@ public virtual async Task Apply(Block block, JsonElement op, JsonElement content
Errors = result.TryGetProperty("errors", out var errors)
? OperationErrors.Parse(content, errors)
: null,
GasUsed = (int)((result.RequiredInt64("consumed_milligas") + 999) / 1000),
GasUsed = (int)(((result.OptionalInt64("consumed_milligas") ?? 0) + 999) / 1000),
StorageUsed = (int)(storageFee / block.Protocol.ByteCost),
StorageFee = storageFee
};
Expand Down

0 comments on commit 783ecd5

Please sign in to comment.