From afe20502da58bf323c0a13fafd0be2cd3fdd0b52 Mon Sep 17 00:00:00 2001 From: Francesco Ceccon Date: Wed, 1 Nov 2023 12:18:37 +0100 Subject: [PATCH] fix: execution status revert reason field is optional The Starknet JSON-RPC spec defines this field as optional. This commit fixes compatibility with nodes like Juno that don't include this field if the revert reason is empty. --- starknet-core/src/types/execution_result.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/starknet-core/src/types/execution_result.rs b/starknet-core/src/types/execution_result.rs index 3479d554..81c6b91b 100644 --- a/starknet-core/src/types/execution_result.rs +++ b/starknet-core/src/types/execution_result.rs @@ -61,20 +61,17 @@ impl<'de> Deserialize<'de> for ExecutionResult { #[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] struct Raw { execution_status: TransactionExecutionStatus, - revert_reason: Option, + #[serde(default)] + revert_reason: String, } let raw = Raw::deserialize(deserializer)?; - match (raw.execution_status, raw.revert_reason) { - (TransactionExecutionStatus::Succeeded, None) => Ok(Self::Succeeded), - (TransactionExecutionStatus::Reverted, Some(reason)) => Ok(Self::Reverted { reason }), - (TransactionExecutionStatus::Succeeded, Some(_)) => Err(serde::de::Error::custom( - "field `revert_reason` must not exist when `execution_status` is `SUCCEEDED`", - )), - (TransactionExecutionStatus::Reverted, None) => Err(serde::de::Error::custom( - "field `revert_reason` missing when `execution_status` is `REVERTED`", - )), + match raw.execution_status { + TransactionExecutionStatus::Succeeded => Ok(Self::Succeeded), + TransactionExecutionStatus::Reverted => Ok(Self::Reverted { + reason: raw.revert_reason, + }), } } }