Skip to content

Commit 70e1ee4

Browse files
committed
fix optinal albi
1 parent 6853ac6 commit 70e1ee4

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

starknet-core/src/types/contract/legacy.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ use crate::{
1414
};
1515

1616
use serde::{
17-
de::Error as DeError, ser::SerializeSeq, Deserialize, Deserializer, Serialize, Serializer,
17+
de::{DeserializeOwned, Error as DeError},
18+
ser::SerializeSeq,
19+
Deserialize, Deserializer, Serialize, Serializer,
1820
};
1921
use serde_json_pythonic::to_string_pythonic;
2022
use serde_with::{serde_as, SerializeAs};
@@ -31,13 +33,25 @@ const API_VERSION: Felt = Felt::ZERO;
3133
#[cfg_attr(feature = "no_unknown_fields", serde(deny_unknown_fields))]
3234
pub struct LegacyContractClass {
3335
/// Contract ABI.
36+
#[serde(default, deserialize_with = "deserialize_optional_field")]
3437
pub abi: Vec<RawLegacyAbiEntry>,
3538
/// Contract entrypoints.
3639
pub entry_points_by_type: RawLegacyEntryPoints,
3740
/// The Cairo program of the contract containing the actual bytecode.
3841
pub program: LegacyProgram,
3942
}
4043

44+
fn deserialize_optional_field<'de, D, T>(deserializer: D) -> Result<T, D::Error>
45+
where
46+
D: Deserializer<'de>,
47+
T: DeserializeOwned + Default,
48+
{
49+
match Option::<T>::deserialize(deserializer)? {
50+
Some(value) => Ok(value),
51+
None => Ok(T::default()),
52+
}
53+
}
54+
4155
/// Legacy (Cairo 0) contract entrypoints by types.
4256
#[derive(Debug, Clone, Serialize, Deserialize)]
4357
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]

0 commit comments

Comments
 (0)