fix json encoding of BAL for debug API: make it human-readable again

This commit is contained in:
Jared Wasinger 2025-10-21 19:36:50 +08:00
parent 2994e096c6
commit e481a1a7d1
3 changed files with 13 additions and 19 deletions

View file

@ -137,7 +137,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
p.chain.Engine().Finalize(p.chain, header, tracingStateDB, block.Body())
if hooks := cfg.Tracer; hooks != nil {
if hooks := cfg.Tracer; hooks != nil && hooks.OnBlockFinalization != nil {
hooks.OnBlockFinalization()
}

View file

@ -67,6 +67,16 @@ func (e *BlockAccessList) DecodeRLP(dec *rlp.Stream) error {
return nil
}
// StringableRepresentation returns an instance of the block access list
// which can be converted to a human-readable JSON representation.
func (e *BlockAccessList) StringableRepresentation() interface{} {
res := []AccountAccess{}
for _, aa := range *e {
res = append(res, aa)
}
return &res
}
func (e *BlockAccessList) String() string {
var res bytes.Buffer
enc := json.NewEncoder(&res)

View file

@ -17,11 +17,9 @@
package eth
import (
"bytes"
"context"
"errors"
"fmt"
"github.com/ethereum/go-ethereum/core/types/bal"
"time"
"github.com/ethereum/go-ethereum/common"
@ -537,7 +535,7 @@ func (api *DebugAPI) ExecutionWitnessByHash(hash common.Hash) (*stateless.ExtWit
// GetBlockAccessList returns a block access list for the given number/hash
// or nil if one does not exist.
func (api *DebugAPI) GetBlockAccessList(number rpc.BlockNumberOrHash) (*bal.BlockAccessList, error) {
func (api *DebugAPI) GetBlockAccessList(number rpc.BlockNumberOrHash) (interface{}, error) {
var block *types.Block
if num := number.BlockNumber; num != nil {
block = api.eth.blockchain.GetBlockByNumber(uint64(num.Int64()))
@ -548,19 +546,5 @@ func (api *DebugAPI) GetBlockAccessList(number rpc.BlockNumberOrHash) (*bal.Bloc
if block == nil {
return nil, fmt.Errorf("block not found")
}
return block.Body().AccessList, nil
}
// GetEncodedBlockAccessList returns a block access list corresponding to a
// block number/hash in RLP-encoded form. It returns nil if one does not exist.
func (api *DebugAPI) GetEncodedBlockAccessList(number rpc.BlockNumberOrHash) ([]byte, error) {
bal, err := api.GetBlockAccessList(number)
if err != nil {
return nil, err
}
var enc bytes.Buffer
if err = bal.EncodeRLP(&enc); err != nil {
return nil, err
}
return enc.Bytes(), nil
return block.Body().AccessList.StringableRepresentation(), nil
}