Skip to content

Add ability for input and value of transaction to be null for Tempo Blockchain#107

Open
JasoonS wants to merge 3 commits into
mainfrom
js/tempo-0x76-nulls
Open

Add ability for input and value of transaction to be null for Tempo Blockchain#107
JasoonS wants to merge 3 commits into
mainfrom
js/tempo-0x76-nulls

Conversation

@JasoonS
Copy link
Copy Markdown
Collaborator

@JasoonS JasoonS commented Mar 19, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Transaction fields that were previously failing on null or missing values now default safely, preventing errors during data import.
  • Tests
    • Added unit tests covering null, missing and normal cases for transaction parsing to prevent regressions.
  • Chores
    • Package version updated to 0.7.1.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 19, 2026

📝 Walkthrough

Walkthrough

Updated hypersync-format crate from version 0.7.0 to 0.7.1 and added custom serde deserializers for Transaction fields. Modified deserialization logic for input and value fields to handle null or missing values by returning defaults instead of failing.

Changes

Cohort / File(s) Summary
Version Management
hypersync-format/Cargo.toml
Patch version bump from 0.7.0 to 0.7.1.
Deserialization Logic
hypersync-format/src/types/mod.rs
Added two new serde helper functions: deserialize_quantity_or_null (treats null/missing as 0) and deserialize_data_or_null (treats null/missing as empty). Updated Transaction input field to use data deserializer and value field to use quantity deserializer with defaults.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 A tiny hop through null-safe lands,
Where missing fields find gentle hands,
From point-zero-seven we now depart,
To point-one with deserializer's heart! 🎉

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding null-handling capability for transaction input and value fields specific to Tempo Blockchain, which is reflected in the code changes adding serde deserializers.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • ✅ Generated successfully - (🔄 Check to regenerate)
  • Commit on current branch
🧪 Generate unit tests (beta)

✅ Unit Tests committed locally.

  • Create PR with unit tests
  • Commit unit tests in branch js/tempo-0x76-nulls
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
hypersync-format/src/types/mod.rs (2)

104-106: Consider adding tests for null input and value handling.

The existing test at line 362 covers effective_gas_price null handling. Similar test coverage for Transaction.input and Transaction.value would help document and validate the Tempo blockchain behavior.

Would you like me to generate a test case for Transaction deserialization with null/missing input and value fields?

🤖 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 existing nullable_default function.

These two new deserializers duplicate the existing generic nullable_default function (lines 205-211) which already handles the same pattern for any Default + Deserialize type.

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 Transaction fields to use nullable_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

📥 Commits

Reviewing files that changed from the base of the PR and between 0372bc6 and 4057d91.

📒 Files selected for processing (2)
  • hypersync-format/Cargo.toml
  • hypersync-format/src/types/mod.rs

Comment on lines +110 to 112
// 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,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

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.

Suggested change
// 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.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 19, 2026

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.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 19, 2026

Warning

Docstrings generation - IN PROGRESS

Generating docstrings for this pull request

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 19, 2026

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
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 19, 2026

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.

coderabbitai Bot added a commit that referenced this pull request Mar 19, 2026
Docstrings generation was requested by @JasoonS.

* #107 (comment)

The following files were modified:

* `hypersync-format/src/types/mod.rs`
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 19, 2026

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"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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())
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is default 0x, or 0x0? Just thinking its probably better to have empty bytes than 0 if possible. But might break other assumptions

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, we could leave empty, and handle in HyperSync, maybe better

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 19, 2026

✅ Created PR with unit tests: #109

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 19, 2026

✅ Unit tests committed locally. Commit: f261414f5064af1f5ef0c75f9957875bdab01bbc

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 19, 2026

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.

coderabbitai Bot added a commit that referenced this pull request Mar 19, 2026
Docstrings generation was requested by @coderabbitai[bot].

* #107 (comment)

The following files were modified:

* `hypersync-format/src/types/mod.rs`
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 19, 2026

✅ Created PR with unit tests: #111

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 19, 2026

✅ Created PR with unit tests: #112

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 19, 2026

✅ Created PR with unit tests: #113

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.

2 participants