Skip to content

Commit

Permalink
fix: remove unnecessary serde method
Browse files Browse the repository at this point in the history
  • Loading branch information
GMKrieger committed Dec 4, 2024
1 parent 389518a commit 3c20d4e
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 51 deletions.
2 changes: 0 additions & 2 deletions crates/starknet-os/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use starknet_api::core::{ChainId, ContractAddress, PatriciaKey};
use starknet_api::{contract_address, felt, patricia_key};

use crate::error::SnOsError;
use crate::utils::ChainIdNum;

pub const fn default_layout() -> LayoutName {
LayoutName::all_cairo
Expand Down Expand Up @@ -45,7 +44,6 @@ pub const GLOBAL_STATE_VERSION: &[u8] = "STARKNET_STATE_V0".as_bytes();
#[serde_as]
#[derive(Debug, Serialize, Clone, Deserialize, PartialEq)]
pub struct StarknetOsConfig {
#[serde_as(as = "ChainIdNum")]
pub chain_id: ChainId,
pub fee_token_address: ContractAddress,
pub deprecated_fee_token_address: ContractAddress,
Expand Down
49 changes: 0 additions & 49 deletions crates/starknet-os/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use cairo_vm::{any_box, Felt252};
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
use serde_json::Number;
use serde_with::{DeserializeAs, SerializeAs};
use starknet_api::core::ChainId;
use starknet_os_types::chain_id::chain_id_to_felt;
use tokio::task;

pub(crate) struct Felt252Str;
Expand Down Expand Up @@ -80,30 +78,6 @@ impl SerializeAs<Felt252> for Felt252HexNoPrefix {
}
}

pub(crate) struct ChainIdNum;

impl<'de> DeserializeAs<'de, ChainId> for ChainIdNum {
fn deserialize_as<D>(deserializer: D) -> Result<ChainId, D::Error>
where
D: Deserializer<'de>,
{
let bytes = u128::deserialize(deserializer)?.to_be_bytes();
let chain_id_str = String::from_utf8_lossy(&bytes);

Ok(ChainId::from(chain_id_str.into_owned()))
}
}

impl SerializeAs<ChainId> for ChainIdNum {
fn serialize_as<S>(value: &ChainId, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let chain_id_felt = chain_id_to_felt(value);
chain_id_felt.serialize(serializer)
}
}

/// Retrieves a constant from the `constants` hashmap or returns an error.
///
/// We should not use `get_constant_from_var_name` if possible as it performs an O(N)
Expand Down Expand Up @@ -169,13 +143,6 @@ mod tests {

use super::*;

#[serde_as]
#[derive(Serialize, Deserialize, Debug, PartialEq)]
struct ChainIdOnly {
#[serde_as(as = "ChainIdNum")]
chain_id: ChainId,
}

#[serde_as]
#[derive(Serialize, Deserialize, Debug, PartialEq)]
struct FeltStrOnly {
Expand All @@ -197,22 +164,6 @@ mod tests {
felt: Felt252,
}

#[test]
fn test_utils_chain_id_num_ok() {
let expected = "{\"chain_id\":\"0x534e5f5345504f4c4941\"}".to_owned();
let c = ChainIdOnly { chain_id: ChainId::Sepolia };
let result = serde_json::to_string(&c).unwrap();
assert_eq!(expected, result);
}

#[test]
fn test_utils_chain_id_num_deser_ok() {
let expected = ChainIdOnly { chain_id: ChainId::Other("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\u{1}".to_string()) };
let json = r#"{ "chain_id": 1 }"#;
let result: ChainIdOnly = serde_json::from_str(json).unwrap();
assert_eq!(expected, result);
}

#[test]
fn test_utils_felt_252_str_ok() {
let expected = "{\"felt\":\"0x0\"}".to_owned();
Expand Down

0 comments on commit 3c20d4e

Please sign in to comment.