Skip to content

Commit 6e350cf

Browse files
committed
doc: demonstrate use of all non-optional upstream RLP fields
1 parent c6f199d commit 6e350cf

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

core/types/rlp_backwards_compat.libevm_test.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,20 @@ type cChainBodyExtras struct {
198198
var _ BodyHooks = (*cChainBodyExtras)(nil)
199199

200200
func (e *cChainBodyExtras) RLPFieldsForEncoding(b *Body) ([]any, []any) {
201-
return []any{
202-
b.Transactions,
203-
b.Uncles,
204-
e.Version,
205-
e.ExtData,
206-
}, nil
201+
// The Avalanche C-Chain uses all of the geth required fields (but none of
202+
// the optional ones) so there's no need to explicitly list them. This
203+
// pattern might not be ideal for readability but is used here for
204+
// demonstrative purposes.
205+
//
206+
// All new fields will always be tagged as optional for backwards
207+
// compatibility so this is safe to do, but only for the required fields.
208+
req, _ /*drop all optional*/ := NOOPBodyHooks{}.RLPFieldsForEncoding(b)
209+
return append(req, e.Version, e.ExtData), nil
207210
}
208211

209212
func (e *cChainBodyExtras) RLPFieldPointersForDecoding(b *Body) ([]any, []any) {
213+
// An alternative to the pattern used above is to explicitly list all
214+
// fields for better introspection.
210215
return []any{
211216
&b.Transactions,
212217
&b.Uncles,

0 commit comments

Comments
 (0)