Skip to content

Commit

Permalink
fix: execution status revert reason field is optional
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fracek committed Nov 1, 2023
1 parent 1497446 commit c945676
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions starknet-core/src/types/execution_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
#[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,
}),
}
}
}

0 comments on commit c945676

Please sign in to comment.