-
Notifications
You must be signed in to change notification settings - Fork 97
feat: add debug_getRawReceipts method
#4919
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
Open
BartoszSolkaBD
wants to merge
18
commits into
hiero-ledger:main
Choose a base branch
from
BartoszSolkaBD:4892-Add-debug_getRawReceipts-method
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
9d6d9e1
feat: added support for debug_getBadBlocks (#4889)
BartoszSolkaBD 21ad2a4
test: refactor tests to not repeat test body (#4889)
BartoszSolkaBD cba3cee
docs: aligned summary field of debug_getBadBlocks in openrpc.json (#4…
BartoszSolkaBD 145910e
test: added description to get-bad-blocks.io (#4889)
BartoszSolkaBD 7896368
docs: added clarification for debug_getBadBlocks summary (#4889)
BartoszSolkaBD 874238e
refactor: removed try-catch block in debug_getBadBlock (#4889)
BartoszSolkaBD 26581f6
feat: added support for debug_getRawReceipt (#4892)
BartoszSolkaBD 8d5d63d
Merge branch 'main' into 4892-Add-debug_getRawReceipts-method
BartoszSolkaBD 06121e5
feat: added unit test that checks consistency between debug_getRawRec…
BartoszSolkaBD c9a54b2
chore: update comments in debug tests to specify Hedera Mainnet for c…
BartoszSolkaBD d115ca0
chore: added unit tests for receiptSerialization (#4892)
BartoszSolkaBD 6fdd45c
chore: added unit test for canonical scalar encoding and aligned impl…
BartoszSolkaBD 3b5780c
chore: removed debug_getRawReceipts from NOT_IMPLEMENTED_METHODS in o…
BartoszSolkaBD 26d47da
Merge remote-tracking branch 'origin/main' into 4892-Add-debug_getRaw…
BartoszSolkaBD c91ef46
refactor: refactored debug_getRawReceipts to not reuse eth_getBlockRe…
BartoszSolkaBD 8a876cc
fix: aligned ts-doc return type of getRawReceipts function (#4892)
BartoszSolkaBD fb1e877
Merge remote-tracking branch 'origin/main' into 4892-Add-debug_getRaw…
BartoszSolkaBD eed78ea
fix: added missing ts-docs; removed rlp related mappers from Transact…
BartoszSolkaBD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| /** | ||
| * Receipt serialization per Ethereum Yellow Paper and EIP-2718. | ||
| * | ||
| * Yellow Paper: receipt is RLP of the 4-tuple | ||
| * (receipt_root_or_status, cumulative_gas_used, logs_bloom, logs). | ||
| * Post-Byzantium: first field is status (empty for 0, 0x01 for 1) or 32-byte state root. | ||
| * Each log: RLP([address, topics[], data]). | ||
| * | ||
| * EIP-2718: for typed txs (type !== 0), wire format is type_byte || RLP(above 4-tuple). | ||
| */ | ||
|
|
||
| import { RLP } from '@ethereumjs/rlp'; | ||
| import { bytesToInt, concatBytes, hexToBytes, intToBytes } from '@ethereumjs/util'; | ||
|
|
||
| import { prepend0x, toHexString } from '../formatters'; | ||
| import constants from './constants'; | ||
| import type { Log } from './model'; | ||
| import { IReceiptRlpInput } from './types/IReceiptRlpInput'; | ||
|
|
||
| /** | ||
| * Converts receipt logs into the RLP encoded log structure. | ||
| * | ||
| * Each log becomes a 3-tuple [address, topics[], data] per the Yellow Paper | ||
| * (address and data as bytes; topics as array of 32-byte topic hashes). | ||
| * | ||
| * @param logs - The logs array from the transaction receipt (see {@link Log}). | ||
| * @returns Array of [address, topics, data] as Uint8Arrays for RLP encoding. | ||
| */ | ||
| function encodeLogsForReceipt(logs: Log[]): [Uint8Array, Uint8Array[], Uint8Array][] { | ||
| return logs.map((log) => [hexToBytes(log.address), log.topics.map((t) => hexToBytes(t)), hexToBytes(log.data)]); | ||
| } | ||
|
|
||
| /** | ||
| * Encodes a single transaction receipt to EIP-2718 binary form. | ||
| * | ||
| * Produces the RLP-encoded 4-tuple (receipt_root_or_status, cumulative_gas_used, | ||
| * logs_bloom, logs) per the Ethereum Yellow Paper. For typed transactions (type !== 0), | ||
| * the output is the single-byte type prefix followed by that RLP payload (EIP-2718). | ||
| * | ||
quiet-node marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * Based on section 4.4.1 (Transaction Receipt) from the Ethereum Yellow Paper: https://ethereum.github.io/yellowpaper/paper.pdf | ||
| * | ||
| * @param receipt - The transaction receipt to encode (see {@link ITransactionReceipt}). | ||
| * @returns Hex string (0x-prefixed) of the encoded receipt, suitable for receipts root hashing. | ||
| */ | ||
| export function encodeReceiptToHex(receipt: IReceiptRlpInput): string { | ||
| const txType = receipt.type !== null ? bytesToInt(hexToBytes(receipt.type)) : 0; | ||
|
|
||
| // First field: receipt root or status (post-Byzantium) | ||
| let receiptRootOrStatus: Uint8Array; | ||
| if (receipt.root && receipt.root.length > 2) { | ||
| receiptRootOrStatus = hexToBytes(receipt.root); | ||
| } else if (receipt.status && bytesToInt(hexToBytes(receipt.status)) === 0) { | ||
| receiptRootOrStatus = new Uint8Array(0); | ||
| } else { | ||
| receiptRootOrStatus = hexToBytes(constants.ONE_HEX); | ||
| } | ||
|
|
||
| const cumulativeGasUsed = receipt.cumulativeGasUsed; | ||
| const cumulativeGasUsedBytes = | ||
| BigInt(cumulativeGasUsed) === BigInt(0) | ||
| ? new Uint8Array(0) | ||
| : hexToBytes(prepend0x(BigInt(cumulativeGasUsed).toString(16))); // canonical RLP encoding (no leading zeros) | ||
|
|
||
| const encodedList = RLP.encode([ | ||
| receiptRootOrStatus, | ||
| cumulativeGasUsedBytes, | ||
| hexToBytes(receipt.logsBloom), | ||
| encodeLogsForReceipt(receipt.logs), | ||
| ]); | ||
|
|
||
| if (txType === 0) { | ||
| return prepend0x(toHexString(encodedList)); | ||
| } | ||
| const withPrefix = concatBytes(intToBytes(txType), encodedList); | ||
| return prepend0x(toHexString(withPrefix)); | ||
| } | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strange I really thought I left a comment on this file in the previous round of review. Anyhoo should we consider moving this module out of the root of src/lib where the other generic namespace modules live? It feels like the receipt-related logic here would be better encapsulated in a dedicated class rather than sitting alongside the other top-level modules. Since these methods are all doing transaction receipt related work, would it make sense to move them into the TransactionReceiptFactory class? That seems like a natural home for them and would keep things cleaner overall.