-
Notifications
You must be signed in to change notification settings - Fork 97
feat: add debug_getRawHeader method
#4926
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
base: main
Are you sure you want to change the base?
Changes from all commits
61a501b
cc42633
a36d6a3
8107201
39b9123
24bb813
18bbd8f
51ae109
6dc494a
08aadf3
1737bce
cbff76b
c25abea
a2aee36
08db390
e38b425
744d5ab
db324a3
c711078
349eaee
80d0d2a
06130eb
6008b51
1e98c46
a05d094
f7d8a66
84b9531
17afe77
25cdb86
9656054
ac9fc4e
2185dfa
2a8f1f3
78279e8
0ab100f
233a311
55a4723
cd9baf8
6903a5f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,10 +138,12 @@ export class BlockFactory { | |
| * RLP encode a block based on Ethereum Yellow Paper. | ||
| * | ||
| * @param { Block } block - The block object from eth_getBlockByNumber/Hash | ||
| * @param {boolean} headerOnly - A flag that determines whether to encode the entire block or only the block header | ||
| * | ||
| * @returns {Uint8Array} - RLP encoded block as Uint8 array | ||
| */ | ||
| static rlpEncode(block: Block): Uint8Array { | ||
| if (typeof block.transactions[0] === 'string') { | ||
| static rlpEncode(block: Block, headerOnly: boolean = false): Uint8Array { | ||
| if (!headerOnly && typeof block.transactions[0] === 'string') { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not a blocker for me, but I think it would look a little bit cleaner with separate methods, and we wouldn’t need conditional validation logic here. encodeHeader(block): RLP => rlp(header(block));
encode(block): RLP => validate(block) && rlp(...header(block), ...payload(block));also because of this the jsdocs are not quite valid any longer (especiall ydescription of the returned value) it should be more like |
||
| throw new Error('Block transactions must include full transaction objects for RLP encoding'); | ||
| } | ||
|
|
||
|
|
@@ -150,7 +152,8 @@ export class BlockFactory { | |
| // -- BT - block transactions (RLP encoded transactions array) | ||
| // -- BU - ommers (empty array) | ||
| // -- BW - withdrawals (empty array) | ||
| return RLP.encode([ | ||
|
|
||
| const header = [ | ||
| // Hp - parentHash | ||
| block.parentHash, | ||
| // Ho - ommersHash | ||
|
|
@@ -185,6 +188,14 @@ export class BlockFactory { | |
| block.baseFeePerGas, | ||
| // Hw - withdrawalsRoot | ||
| block.withdrawalsRoot, | ||
| ]; | ||
|
|
||
| if (headerOnly) { | ||
| return RLP.encode(header); | ||
| } | ||
|
|
||
| return RLP.encode([ | ||
| ...header, | ||
| // BT - block transactions (RLP encoded transactions array) | ||
| [...block.transactions.map((tx) => BlockFactory.rlpEncodeTx(tx as Transaction))], | ||
| // BU - ommers (empty array) | ||
|
|
||
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.
maybe we should split preparing canonical representation and encoding into two separate steps? I think it would allow us to get rid of
headerOnlyflag, swapping it forrlpEncodeBlock(block: Block)andrlpEncodeBlockHeader(header: BlockHeader)