fix: support eip712 domain chain ids as string (#1756)

* fix: support eip712 domain chain ids as string

* chore: add rustfmt.toml
This commit is contained in:
Matthias Seitz 2022-09-29 17:05:36 +02:00 committed by GitHub
parent 5c762c44d7
commit fac31f631c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -254,3 +254,25 @@ where
let num = <[LenientBlockNumber; 1]>::deserialize(deserializer)?[0].into(); let num = <[LenientBlockNumber; 1]>::deserialize(deserializer)?[0].into();
Ok(num) Ok(num)
} }
#[cfg(test)]
mod tests {
#[test]
#[cfg(feature = "eip712")]
fn test_deserialize_string_chain_id() {
use crate::types::transaction::eip712::EIP712Domain;
let val = serde_json::json!(
{
"name": "Seaport",
"version": "1.1",
"chainId": "137",
"verifyingContract": "0x00000000006c3852cbEf3e08E8dF289169EdE581"
}
);
let domain: EIP712Domain = serde_json::from_value(val).unwrap();
assert_eq!(domain.chain_id, Some(137u64.into()));
}
}

View File

@ -131,7 +131,7 @@ pub struct EIP712Domain {
#[serde( #[serde(
default, default,
skip_serializing_if = "Option::is_none", skip_serializing_if = "Option::is_none",
deserialize_with = "crate::types::serde_helpers::deserialize_number_opt" deserialize_with = "crate::types::serde_helpers::deserialize_stringified_numeric_opt"
)] )]
pub chain_id: Option<U256>, pub chain_id: Option<U256>,