diff --git a/starknet-core/src/types/contract/legacy.rs b/starknet-core/src/types/contract/legacy.rs index a6edda7f..7c824092 100644 --- a/starknet-core/src/types/contract/legacy.rs +++ b/starknet-core/src/types/contract/legacy.rs @@ -14,7 +14,9 @@ use crate::{ }; use serde::{ - de::Error as DeError, ser::SerializeSeq, Deserialize, Deserializer, Serialize, Serializer, + de::{DeserializeOwned, Error as DeError}, + ser::SerializeSeq, + Deserialize, Deserializer, Serialize, Serializer, }; use serde_json_pythonic::to_string_pythonic; use serde_with::{serde_as, SerializeAs}; @@ -31,6 +33,7 @@ const API_VERSION: Felt = Felt::ZERO; #[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))] pub struct LegacyContractClass { /// Contract ABI. + #[serde(default, deserialize_with = "deserialize_optional_field")] pub abi: Vec, /// Contract entrypoints. pub entry_points_by_type: RawLegacyEntryPoints, @@ -38,6 +41,17 @@ pub struct LegacyContractClass { pub program: LegacyProgram, } +fn deserialize_optional_field<'de, D, T>(deserializer: D) -> Result +where + D: Deserializer<'de>, + T: DeserializeOwned + Default, +{ + match Option::::deserialize(deserializer)? { + Some(value) => Ok(value), + None => Ok(T::default()), + } +} + /// Legacy (Cairo 0) contract entrypoints by types. #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")]