Skip to content

Commit

Permalink
fix optinal albi
Browse files Browse the repository at this point in the history
  • Loading branch information
jbcaron committed Nov 22, 2024
1 parent 6853ac6 commit 70e1ee4
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion starknet-core/src/types/contract/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -31,13 +33,25 @@ 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<RawLegacyAbiEntry>,
/// Contract entrypoints.
pub entry_points_by_type: RawLegacyEntryPoints,
/// The Cairo program of the contract containing the actual bytecode.
pub program: LegacyProgram,
}

fn deserialize_optional_field<'de, D, T>(deserializer: D) -> Result<T, D::Error>
where
D: Deserializer<'de>,
T: DeserializeOwned + Default,
{
match Option::<T>::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")]
Expand Down

0 comments on commit 70e1ee4

Please sign in to comment.