Skip to content

Commit 11c780f

Browse files
committed
Block Body hook
1 parent e27ce12 commit 11c780f

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

core/types/block.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,10 @@ func (b *Block) encodeRLP(w io.Writer) error {
339339
})
340340
}
341341

342-
// Body returns the non-header content of the block.
342+
// EthBody returns the non-header content of an Ethereum block.
343343
// Note the returned data is not an independent copy.
344-
func (b *Block) Body() *Body {
344+
// Use [Block.Body] instead if your block has any registered extra.
345+
func (b *Block) EthBody() *Body {
345346
return &Body{
346347
Transactions: b.transactions,
347348
Uncles: b.uncles,

core/types/block.libevm.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ func (*NOOPBodyHooks) DecodeRLP(b *Body, s *rlp.Stream) error {
187187
type BlockHooks interface {
188188
EncodeRLP(*Block, io.Writer) error
189189
DecodeRLP(*Block, *rlp.Stream) error
190+
Body(*Block) *Body
190191
}
191192

192193
// hooks returns the Block's registered BlockHooks, if any, otherwise a
@@ -243,6 +244,10 @@ func (*NOOPBlockHooks) DecodeRLP(b *Block, s *rlp.Stream) error {
243244
return b.decodeRLP(s)
244245
}
245246

247+
func (*NOOPBlockHooks) Body(b *Block) *Body {
248+
return b.EthBody()
249+
}
250+
246251
func (b *Block) SetHeader(header *Header) {
247252
b.header = header
248253
}
@@ -254,3 +259,9 @@ func (b *Block) SetUncles(uncles []*Header) {
254259
func (b *Block) SetTransactions(transactions Transactions) {
255260
b.transactions = transactions
256261
}
262+
263+
// Body returns the non-header content of the block.
264+
// Note the returned data is not an independent copy.
265+
func (b *Block) Body() *Body {
266+
return b.hooks().Body(b)
267+
}

core/types/block.libevm_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ func (bh *stubBlockHooks) DecodeRLP(b *Block, s *rlp.Stream) error {
133133
return bh.errDecode
134134
}
135135

136+
func (bh *stubBlockHooks) Body(b *Block) *Body {
137+
return b.EthBody()
138+
}
139+
136140
func TestHeaderHooks(t *testing.T) {
137141
TestOnlyClearRegisteredExtras()
138142
defer TestOnlyClearRegisteredExtras()

0 commit comments

Comments
 (0)