Add ability for input and value of transaction to be null for Tempo Blockchain#107
Add ability for input and value of transaction to be null for Tempo Blockchain#107JasoonS wants to merge 3 commits into
Conversation
📝 WalkthroughWalkthroughUpdated hypersync-format crate from version 0.7.0 to 0.7.1 and added custom serde deserializers for Transaction fields. Modified deserialization logic for Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)✅ Unit Tests committed locally.
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
hypersync-format/src/types/mod.rs (2)
104-106: Consider adding tests for nullinputandvaluehandling.The existing test at line 362 covers
effective_gas_pricenull handling. Similar test coverage forTransaction.inputandTransaction.valuewould help document and validate the Tempo blockchain behavior.Would you like me to generate a test case for Transaction deserialization with null/missing
inputandvaluefields?🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@hypersync-format/src/types/mod.rs` around lines 104 - 106, Add unit tests to cover deserialization of Transaction when input and value are null or missing: create tests that deserialize JSON fixtures with "input": null and with the "input" field omitted to verify deserialize_data_or_null produces the expected Data value, and similarly for "value" to ensure Transaction.value handles null/missing correctly; reference the Transaction struct fields input and value and the deserialize_data_or_null deserializer so the tests assert deserialized fields match the Tempo semantics (e.g., empty/default Data or zero value) and mirror the existing effective_gas_price null test pattern.
75-89: Consider reusing the existingnullable_defaultfunction.These two new deserializers duplicate the existing generic
nullable_defaultfunction (lines 205-211) which already handles the same pattern for anyDefault + Deserializetype.You can simplify by reusing it directly:
♻️ Proposed refactor
-/// Deserialize a Quantity that may be null or missing, defaulting to zero. -fn deserialize_quantity_or_null<'de, D>(deserializer: D) -> Result<Quantity, D::Error> -where - D: Deserializer<'de>, -{ - Ok(Option::<Quantity>::deserialize(deserializer)?.unwrap_or_default()) -} - -/// Deserialize Data that may be null or missing, defaulting to empty. -fn deserialize_data_or_null<'de, D>(deserializer: D) -> Result<Data, D::Error> -where - D: Deserializer<'de>, -{ - Ok(Option::<Data>::deserialize(deserializer)?.unwrap_or_default()) -}Then update the
Transactionfields to usenullable_default:- #[serde(default, deserialize_with = "deserialize_data_or_null")] + #[serde(default, deserialize_with = "nullable_default")] pub input: Data, ... - #[serde(default, deserialize_with = "deserialize_quantity_or_null")] + #[serde(default, deserialize_with = "nullable_default")] pub value: Quantity,🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@hypersync-format/src/types/mod.rs` around lines 75 - 89, The two functions deserialize_quantity_or_null and deserialize_data_or_null duplicate the generic nullable_default helper; remove those two functions and update the Transaction struct fields that reference them to use serde's deserialize_with = "nullable_default" (or the correct path to nullable_default) so types implementing Default + Deserialize (like Quantity and Data) reuse the existing generic deserializer.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@hypersync-format/src/types/mod.rs`:
- Around line 110-112: The comment above the `value` field is a copy-paste error
referencing "input"; update that comment to correctly describe the `value` field
(e.g., that in the Tempo blockchain transactions may omit a value for type 0x76)
so it matches the `pub value: Quantity` declaration and its serde attribute
`deserialize_quantity_or_null`; locate the comment near `pub value: Quantity`
and replace "input" with "value" (or rewrite the sentence to accurately describe
`value`) and keep the existing serde annotation `deserialize_quantity_or_null`
unchanged.
---
Nitpick comments:
In `@hypersync-format/src/types/mod.rs`:
- Around line 104-106: Add unit tests to cover deserialization of Transaction
when input and value are null or missing: create tests that deserialize JSON
fixtures with "input": null and with the "input" field omitted to verify
deserialize_data_or_null produces the expected Data value, and similarly for
"value" to ensure Transaction.value handles null/missing correctly; reference
the Transaction struct fields input and value and the deserialize_data_or_null
deserializer so the tests assert deserialized fields match the Tempo semantics
(e.g., empty/default Data or zero value) and mirror the existing
effective_gas_price null test pattern.
- Around line 75-89: The two functions deserialize_quantity_or_null and
deserialize_data_or_null duplicate the generic nullable_default helper; remove
those two functions and update the Transaction struct fields that reference them
to use serde's deserialize_with = "nullable_default" (or the correct path to
nullable_default) so types implementing Default + Deserialize (like Quantity and
Data) reuse the existing generic deserializer.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 2a7d0bc6-16b3-45e9-9d48-ce288a43b7cb
📒 Files selected for processing (2)
hypersync-format/Cargo.tomlhypersync-format/src/types/mod.rs
| // In the Tempo blockchain, transactions don't need to have an input, and don't if they are of type 0x76 | ||
| #[serde(default, deserialize_with = "deserialize_quantity_or_null")] | ||
| pub value: Quantity, |
There was a problem hiding this comment.
Fix copy-paste error in comment.
The comment on line 110 mentions "transactions don't need to have an input" but this is for the value field, not input.
📝 Proposed fix
- // In the Tempo blockchain, transactions don't need to have an input, and don't if they are of type 0x76
+ // In the Tempo blockchain, transactions don't need to have a value, and don't if they are of type 0x76
#[serde(default, deserialize_with = "deserialize_quantity_or_null")]
pub value: Quantity,📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // In the Tempo blockchain, transactions don't need to have an input, and don't if they are of type 0x76 | |
| #[serde(default, deserialize_with = "deserialize_quantity_or_null")] | |
| pub value: Quantity, | |
| // In the Tempo blockchain, transactions don't need to have a value, and don't if they are of type 0x76 | |
| #[serde(default, deserialize_with = "deserialize_quantity_or_null")] | |
| pub value: Quantity, |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@hypersync-format/src/types/mod.rs` around lines 110 - 112, The comment above
the `value` field is a copy-paste error referencing "input"; update that comment
to correctly describe the `value` field (e.g., that in the Tempo blockchain
transactions may omit a value for type 0x76) so it matches the `pub value:
Quantity` declaration and its serde attribute `deserialize_quantity_or_null`;
locate the comment near `pub value: Quantity` and replace "input" with "value"
(or rewrite the sentence to accurately describe `value`) and keep the existing
serde annotation `deserialize_quantity_or_null` unchanged.
|
Note Unit test generation is a public access feature. Expect some limitations and changes as we gather feedback and continue to improve it. Generating unit tests... This may take up to 20 minutes. |
|
Warning Docstrings generation - IN PROGRESS Generating docstrings for this pull request |
|
Note Unit test generation is a public access feature. Expect some limitations and changes as we gather feedback and continue to improve it. Generating unit tests... This may take up to 20 minutes. |
1 similar comment
|
Note Unit test generation is a public access feature. Expect some limitations and changes as we gather feedback and continue to improve it. Generating unit tests... This may take up to 20 minutes. |
Docstrings generation was requested by @JasoonS. * #107 (comment) The following files were modified: * `hypersync-format/src/types/mod.rs`
|
Note Unit test generation is a public access feature. Expect some limitations and changes as we gather feedback and continue to improve it. Generating unit tests... This may take up to 20 minutes. |
| [package] | ||
| name = "hypersync-format" | ||
| version = "0.7.0" | ||
| version = "0.7.1" |
There was a problem hiding this comment.
Client depends on this, I think we should bump the version there as well as part of this PR. Even if you don't release it.
| where | ||
| D: Deserializer<'de>, | ||
| { | ||
| Ok(Option::<Quantity>::deserialize(deserializer)?.unwrap_or_default()) |
There was a problem hiding this comment.
Is default 0x, or 0x0? Just thinking its probably better to have empty bytes than 0 if possible. But might break other assumptions
There was a problem hiding this comment.
Yeah, we could leave empty, and handle in HyperSync, maybe better
|
✅ Created PR with unit tests: #109 |
|
✅ Unit tests committed locally. Commit: |
|
Note Unit test generation is a public access feature. Expect some limitations and changes as we gather feedback and continue to improve it. Generating unit tests... This may take up to 20 minutes. |
Docstrings generation was requested by @coderabbitai[bot]. * #107 (comment) The following files were modified: * `hypersync-format/src/types/mod.rs`
|
✅ Created PR with unit tests: #111 |
|
✅ Created PR with unit tests: #112 |
|
✅ Created PR with unit tests: #113 |
Summary by CodeRabbit