Skip to content

Commit

Permalink
Fix failed txs validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Groxan committed Mar 28, 2022
1 parent aa25aa5 commit a284db8
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions Tzkt.Sync/Protocols/Handlers/Proto12/Validation/Validator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,12 @@ protected virtual async Task ValidateOrigination(JsonElement content)
var delegat = content.OptionalString("delegate");
var metadata = content.Required("metadata");
var result = metadata.Required("operation_result");
var applied = result.RequiredString("status") == "applied";

if (!await Cache.Accounts.ExistsAsync(source))
throw new ValidationException("unknown source account");

if (result.RequiredString("status") == "applied" && delegat != null)
if (applied && delegat != null)
if (!Cache.Accounts.DelegateExists(delegat))
throw new ValidationException("unknown delegate account");

Expand All @@ -330,7 +331,7 @@ protected virtual async Task ValidateOrigination(JsonElement content)
source,
content.RequiredInt64("fee"));

if (result.TryGetProperty("balance_updates", out var resultUpdates))
if (applied && result.TryGetProperty("balance_updates", out var resultUpdates))
ValidateTransferBalanceUpdates(
resultUpdates.EnumerateArray(),
source,
Expand All @@ -344,12 +345,13 @@ protected virtual void ValidateInternalOrigination(JsonElement content, string i
{
var delegat = content.OptionalString("delegate");
var result = content.Required("result");
var applied = result.RequiredString("status") == "applied";

if (result.RequiredString("status") == "applied" && delegat != null)
if (applied && delegat != null)
if (!Cache.Accounts.DelegateExists(delegat))
throw new ValidationException("unknown delegate account");

if (result.TryGetProperty("balance_updates", out var resultUpdates))
if (applied && result.TryGetProperty("balance_updates", out var resultUpdates))
ValidateTransferBalanceUpdates(
resultUpdates.RequiredArray().EnumerateArray(),
content.RequiredString("source"),
Expand All @@ -375,8 +377,9 @@ protected virtual async Task ValidateTransaction(JsonElement content)
content.RequiredInt64("fee"));

var result = metadata.Required("operation_result");
var applied = result.RequiredString("status") == "applied";

if (result.TryGetProperty("balance_updates", out var resultUpdates))
if (applied && result.TryGetProperty("balance_updates", out var resultUpdates))
ValidateTransferBalanceUpdates(
resultUpdates.RequiredArray().EnumerateArray(),
source,
Expand Down Expand Up @@ -404,8 +407,9 @@ protected virtual async Task ValidateTransaction(JsonElement content)
protected virtual void ValidateInternalTransaction(JsonElement content, string initiator)
{
var result = content.Required("result");
var applied = result.RequiredString("status") == "applied";

if (result.TryGetProperty("balance_updates", out var resultUpdates))
if (applied && result.TryGetProperty("balance_updates", out var resultUpdates))
ValidateTransferBalanceUpdates(
resultUpdates.RequiredArray().EnumerateArray(),
content.RequiredString("source"),
Expand Down

0 comments on commit a284db8

Please sign in to comment.