Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly process chainId field #370

Merged
merged 3 commits into from
Mar 22, 2024

Conversation

klkvr
Copy link
Member

@klkvr klkvr commented Mar 22, 2024

Motivation

WIthout serde(default) legacy transactions without chainId field can't be deserialized right now

Solution

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

let serialized = serde_json::to_string(&transaction).unwrap();
assert_eq!(
serialized,
r#"{"hash":"0x0000000000000000000000000000000000000000000000000000000000000001","nonce":"0x2","blockHash":null,"blockNumber":null,"transactionIndex":null,"from":"0x0000000000000000000000000000000000000006","to":null,"value":"0x8","gas":"0xa","input":"0x0b0c0d"}"#
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this fixture from

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's just a fixture from the test above with all options set to None, the idea was to test that we can handle any of the optional fields missing

I can change it to a valid legacy tx payload so we avoid unexpected test failures when modifying Transaction in the future

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pedantic style nit, otherwise lgtm

Comment on lines 72 to 74
#[serde(default)]
#[serde(with = "alloy_serde::u64_hex_opt")]
#[serde(skip_serializing_if = "Option::is_none")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we collapse them into a single serde attribute?
the skip is also fine because this field should be ignored

@mattsse mattsse merged commit 825ec7f into alloy-rs:main Mar 22, 2024
16 checks passed
@klkvr klkvr mentioned this pull request Apr 8, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants