From c945676e206d686083edbaae2db3f26ce73a53f8 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 | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/starknet-core/src/types/execution_result.rs b/starknet-core/src/types/execution_result.rs index 3479d554..fa5992ea 100644 --- a/starknet-core/src/types/execution_result.rs +++ b/starknet-core/src/types/execution_result.rs @@ -58,23 +58,19 @@ impl<'de> Deserialize<'de> for ExecutionResult { D: serde::Deserializer<'de>, { #[derive(Deserialize)] - #[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, + }), } } }