Fixes a parsing issue of EIP712 chain_id (chain_id = 80001 parsed as chain_id = 0x80001) (#892)

* Parsing U256 from base10_parse::<u64>() instead of directly to U256

This fixes a bug for chain_ids that are > 10, base10_parse::<U256>() was
somehow parsing into hex.

When using the derive macro, chain_id = 10 was parsed as chain_id = 0x10 = 16,
causing an issue for some chains like Polygon.

* chore: fmt

Co-authored-by: Georgios Konstantopoulos <me@gakonst.com>
This commit is contained in:
Alexis Robert 2022-02-10 19:03:46 +01:00 committed by GitHub
parent 331caf9418
commit b07b302410
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 10 deletions

View File

@ -267,16 +267,17 @@ impl TryFrom<&syn::DeriveInput> for EIP712Domain {
.to_compile_error()) .to_compile_error())
} }
domain.chain_id = lit_int domain.chain_id = U256::from(
.base10_digits() lit_int.base10_parse::<u64>().map_err(
.parse() |_| {
.map_err(|_| {
Error::new( Error::new(
meta.path.span(), meta.path.span(),
"failed to parse chain id", "failed to parse chain id",
) )
.to_compile_error() .to_compile_error()
})?; },
)?,
);
} }
_ => { _ => {
return Err(Error::new( return Err(Error::new(