From 0f33f4edff6fd0a553df9bfe654becfffd4c52f5 Mon Sep 17 00:00:00 2001 From: Joseph Zhao Date: Mon, 23 Dec 2024 22:24:30 +0800 Subject: [PATCH 1/2] init --- crates/eip7702/src/auth_list.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/eip7702/src/auth_list.rs b/crates/eip7702/src/auth_list.rs index 433769b..d1ee657 100644 --- a/crates/eip7702/src/auth_list.rs +++ b/crates/eip7702/src/auth_list.rs @@ -48,7 +48,7 @@ impl RecoveredAuthority { pub struct Authorization { /// The chain ID of the authorization. #[cfg_attr(feature = "serde", serde(with = "quantity"))] - pub chain_id: u64, + pub chain_id: U256, /// The address of the authorization. pub address: Address, /// The nonce for the authorization. @@ -62,7 +62,7 @@ impl Authorization { /// # Note /// /// Implementers should check that this matches the current `chain_id` *or* is 0. - pub const fn chain_id(&self) -> u64 { + pub const fn chain_id(&self) -> U256 { self.chain_id } @@ -496,7 +496,7 @@ mod tests { fn test_encode_decode_auth() { // fully filled test_encode_decode_roundtrip(Authorization { - chain_id: 1u64, + chain_id: U256::from(1), address: Address::left_padding_from(&[6]), nonce: 1, }); @@ -504,8 +504,11 @@ mod tests { #[test] fn test_encode_decode_signed_auth() { - let auth = - Authorization { chain_id: 1u64, address: Address::left_padding_from(&[6]), nonce: 1 }; + let auth = Authorization { + chain_id: U256::from(1), + address: Address::left_padding_from(&[6]), + nonce: 1, + }; let auth = auth.into_signed(PrimitiveSignature::from_str("48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c8041b").unwrap()); let mut buf = Vec::new(); From 75fcdd903b6251c58f47bfbdd7e0b82d7a96c93f Mon Sep 17 00:00:00 2001 From: Joseph Zhao Date: Mon, 23 Dec 2024 23:42:09 +0800 Subject: [PATCH 2/2] fix --- crates/eip7702/src/auth_list.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/eip7702/src/auth_list.rs b/crates/eip7702/src/auth_list.rs index d1ee657..25e49df 100644 --- a/crates/eip7702/src/auth_list.rs +++ b/crates/eip7702/src/auth_list.rs @@ -47,7 +47,6 @@ impl RecoveredAuthority { #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] pub struct Authorization { /// The chain ID of the authorization. - #[cfg_attr(feature = "serde", serde(with = "quantity"))] pub chain_id: U256, /// The address of the authorization. pub address: Address, @@ -62,8 +61,8 @@ impl Authorization { /// # Note /// /// Implementers should check that this matches the current `chain_id` *or* is 0. - pub const fn chain_id(&self) -> U256 { - self.chain_id + pub const fn chain_id(&self) -> &U256 { + &self.chain_id } /// Get the `address` for the authorization. @@ -526,9 +525,12 @@ mod tests { #[test] fn test_auth_json() { let sig = r#"{"r":"0xc569c92f176a3be1a6352dd5005bfc751dcb32f57623dd2a23693e64bf4447b0","s":"0x1a891b566d369e79b7a66eecab1e008831e22daa15f91a0a0cf4f9f28f47ee05","yParity":"0x1"}"#; - let auth = - Authorization { chain_id: 1u64, address: Address::left_padding_from(&[6]), nonce: 1 } - .into_signed(serde_json::from_str(sig).unwrap()); + let auth = Authorization { + chain_id: U256::from(1), + address: Address::left_padding_from(&[6]), + nonce: 1, + } + .into_signed(serde_json::from_str(sig).unwrap()); let val = serde_json::to_string(&auth).unwrap(); let s = r#"{"chainId":"0x1","address":"0x0000000000000000000000000000000000000006","nonce":"0x1","yParity":"0x1","r":"0xc569c92f176a3be1a6352dd5005bfc751dcb32f57623dd2a23693e64bf4447b0","s":"0x1a891b566d369e79b7a66eecab1e008831e22daa15f91a0a0cf4f9f28f47ee05"}"#; assert_eq!(val, s);