internal/ethapi: return null for missing raw transactions - #35227
Open
manusw7 wants to merge 4 commits into
Open
internal/ethapi: return null for missing raw transactions#35227manusw7 wants to merge 4 commits into
manusw7 wants to merge 4 commits into
Conversation
Change GetRawTransactionByHash, GetRawTransactionByBlockNumberAndIndex, GetRawTransactionByBlockHashAndIndex and the helper newRPCRawTransactionFromBlockIndex to return *hexutil.Bytes instead of hexutil.Bytes so that a nil pointer serialises to JSON null rather than "0x" when the requested transaction is not found.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Change DebugAPI.GetRawTransaction return type from hexutil.Bytes to *hexutil.Bytes so that a not-found transaction serialises as JSON null instead of "0x". Add TestRPCDebugGetRawTransaction with golden files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
eth_getRawTransactionByHash,eth_getRawTransactionByBlockHashAndIndex,eth_getRawTransactionByBlockNumberAndIndex, anddebug_getRawTransactionwere returning the JSON string"0x"instead ofnullwhen the requested transaction is not found.Rationale
The structured counterparts (
eth_getTransactionByHash/ByBlockHashAndIndex/ByBlockNumberAndIndex) already returnnullfor not-found, as explicitly specified in execution-apis via thenotFoundschema (type: 'null'). The raw variants should follow the same convention. Nethermind, Reth, and Besu all returnnull.A companion PR on execution-apis formally adds the three methods to the spec with
oneOf: [notFound, bytes]: ethereum/execution-apis#836.Changes
newRPCRawTransactionFromBlockIndex:hexutil.Bytes→*hexutil.BytesGetRawTransactionByBlockNumberAndIndex:hexutil.Bytes→*hexutil.BytesGetRawTransactionByBlockHashAndIndex:hexutil.Bytes→*hexutil.BytesGetRawTransactionByHash:(hexutil.Bytes, error)→(*hexutil.Bytes, error), with explicitMarshalBinaryerror propagation on the success pathDebugAPI.GetRawTransaction(debug_getRawTransaction):(hexutil.Bytes, error)→(*hexutil.Bytes, error), with explicitMarshalBinaryerror propagation — same fix asGetRawTransactionByHash.A nil
*hexutil.Bytespointer marshals to JSONnull; a non-nil pointer marshals to the0x-prefixed hex string as before.Tests
Added
TestRPCGetRawTransactionByHash,TestRPCGetRawTransactionByBlockHashAndIndex,TestRPCGetRawTransactionByBlockNumberAndIndex, andTestRPCDebugGetRawTransactionfollowing the existing golden-file pattern. Each covers the found, out-of-range/unknown, and zero-hash cases. All not-found golden files assertnull.