From 36ec1d681fc2917ca4857d14ce262ed7c2b60a7a Mon Sep 17 00:00:00 2001 From: Charpa <102919164+jbcaron@users.noreply.github.com> Date: Tue, 18 Jun 2024 18:14:25 +0400 Subject: [PATCH] fix: serialization ReceiptBlock (#604) --- starknet-core/src/types/receipt_block.rs | 37 +++++++++--------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/starknet-core/src/types/receipt_block.rs b/starknet-core/src/types/receipt_block.rs index 4287e2e6..5c73d03d 100644 --- a/starknet-core/src/types/receipt_block.rs +++ b/starknet-core/src/types/receipt_block.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; use serde_with::serde_as; +use crate::serde::unsigned_field_element::UfeHex; use starknet_types_core::felt::Felt; /// A more idiomatic way to access `execution_status` and `revert_reason`. @@ -48,21 +49,22 @@ impl ReceiptBlock { } } +#[serde_as] +#[derive(Serialize, Deserialize)] +#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] +struct Raw { + #[serde(skip_serializing_if = "Option::is_none")] + #[serde_as(as = "Option")] + block_hash: Option, + #[serde(skip_serializing_if = "Option::is_none")] + block_number: Option, +} + impl Serialize for ReceiptBlock { fn serialize(&self, serializer: S) -> Result where S: serde::Serializer, { - #[derive(Serialize)] - #[serde_as] - struct Raw<'a> { - #[serde_as(as = "Option")] - #[serde(skip_serializing_if = "Option::is_none")] - block_hash: Option<&'a Felt>, - #[serde(skip_serializing_if = "Option::is_none")] - block_number: Option<&'a u64>, - } - let raw = match self { Self::Pending => Raw { block_hash: None, @@ -72,8 +74,8 @@ impl Serialize for ReceiptBlock { block_hash, block_number, } => Raw { - block_hash: Some(block_hash), - block_number: Some(block_number), + block_hash: Some(*block_hash), + block_number: Some(*block_number), }, }; @@ -86,17 +88,6 @@ impl<'de> Deserialize<'de> for ReceiptBlock { where D: serde::Deserializer<'de>, { - #[derive(Deserialize)] - #[serde_as] - #[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] - struct Raw { - #[serde_as(as = "Option")] - #[serde(skip_serializing_if = "Option::is_none")] - block_hash: Option, - #[serde(skip_serializing_if = "Option::is_none")] - block_number: Option, - } - let raw = Raw::deserialize(deserializer)?; match (raw.block_hash, raw.block_number) {