From 2ec97c870c63b6042e4bd988fa66e9812bb0e783 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Tue, 8 Oct 2024 18:58:44 +0200 Subject: [PATCH] Revert "Add custom serialization for Address" (#765) Revert "Add custom serialization for Address (#742)" This reverts commit 4b823f7977fcdc181a0bd04ba1b2c51f7a29b4e2. --- crates/dyn-abi/src/eip712/typed_data.rs | 49 ------------------------- crates/primitives/src/bits/macros.rs | 3 -- crates/primitives/src/bits/serde.rs | 35 +----------------- 3 files changed, 1 insertion(+), 86 deletions(-) diff --git a/crates/dyn-abi/src/eip712/typed_data.rs b/crates/dyn-abi/src/eip712/typed_data.rs index b0a3f7ed96..12c53dc3cd 100644 --- a/crates/dyn-abi/src/eip712/typed_data.rs +++ b/crates/dyn-abi/src/eip712/typed_data.rs @@ -291,55 +291,6 @@ mod tests { ); } - #[test] - fn test_full_domain_contract_format() { - let json = json!({ - "types": { - "EIP712Domain": [ - { - "name": "name", - "type": "string" - }, - { - "name": "version", - "type": "string" - }, - { - "name": "chainId", - "type": "uint256" - }, - { - "name": "verifyingContract", - "type": "address" - }, - { - "name": "salt", - "type": "bytes32" - } - ] - }, - "primaryType": "EIP712Domain", - "domain": { - "name": "example.metamask.io", - "version": "1", - "chainId": 1, - "verifyingContract": "0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359" - }, - "message": {} - }); - - let typed_data: TypedData = serde_json::from_value(json).unwrap(); - - let serialized_contract = typed_data.domain.verifying_contract.unwrap(); - assert_eq!(serialized_contract.to_string(), "0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359"); - - let hash = typed_data.eip712_signing_hash().unwrap(); - assert_eq!( - hex::encode(&hash[..]), - "4863a6e9735dee205f3010f78d613c425a26ae2db6e4cf207f88b5d26735d378", - ); - } - #[test] fn test_minimal_message() { let json = json!({ diff --git a/crates/primitives/src/bits/macros.rs b/crates/primitives/src/bits/macros.rs index 5377450041..c07d8dccd1 100644 --- a/crates/primitives/src/bits/macros.rs +++ b/crates/primitives/src/bits/macros.rs @@ -595,9 +595,6 @@ macro_rules! impl_allocative { #[macro_export] #[cfg(feature = "serde")] macro_rules! impl_serde { - (Address) => { - // Use custom implementation for Address - }; ($t:ty) => { #[cfg_attr(docsrs, doc(cfg(feature = "serde")))] impl $crate::private::serde::Serialize for $t { diff --git a/crates/primitives/src/bits/serde.rs b/crates/primitives/src/bits/serde.rs index 97e98ec37d..2e77dcd67a 100644 --- a/crates/primitives/src/bits/serde.rs +++ b/crates/primitives/src/bits/serde.rs @@ -1,33 +1,10 @@ -use super::{Address, FixedBytes}; +use super::FixedBytes; use core::fmt; use serde::{ de::{self, Visitor}, Deserialize, Deserializer, Serialize, Serializer, }; -impl Serialize for Address { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - if serializer.is_human_readable() { - let checksum_address = self.to_checksum_buffer(None); - serializer.serialize_str(checksum_address.as_str()) - } else { - serializer.serialize_bytes(self.as_slice()) - } - } -} - -impl<'de> Deserialize<'de> for Address { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - Deserialize::deserialize(deserializer).map(Self) - } -} - impl Serialize for FixedBytes { fn serialize(&self, serializer: S) -> Result { if serializer.is_human_readable() { @@ -90,8 +67,6 @@ impl<'de, const N: usize> Deserialize<'de> for FixedBytes { #[cfg(test)] mod tests { - use core::str::FromStr; - use super::*; use alloc::string::ToString; use serde::Deserialize; @@ -113,14 +88,6 @@ mod tests { assert_eq!(serde_json::from_value::>(val).unwrap(), bytes); } - #[test] - fn serde_address() { - let address = Address::from_str("0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359").unwrap(); - let ser = serde_json::to_string(&address).unwrap(); - // serialize in checksum format - assert_eq!(ser, "\"0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359\""); - } - #[test] fn serde_num_array() { let json = serde_json::json! {{"fixed": [0,1,2,3,4]}};