mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-24 00:39:26 +00:00
fix json encoding of BAL for debug API: make it human-readable again
This commit is contained in:
parent
2994e096c6
commit
e481a1a7d1
3 changed files with 13 additions and 19 deletions
|
|
@ -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)
|
// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
|
||||||
p.chain.Engine().Finalize(p.chain, header, tracingStateDB, block.Body())
|
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()
|
hooks.OnBlockFinalization()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,16 @@ func (e *BlockAccessList) DecodeRLP(dec *rlp.Stream) error {
|
||||||
return nil
|
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 {
|
func (e *BlockAccessList) String() string {
|
||||||
var res bytes.Buffer
|
var res bytes.Buffer
|
||||||
enc := json.NewEncoder(&res)
|
enc := json.NewEncoder(&res)
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,9 @@
|
||||||
package eth
|
package eth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/ethereum/go-ethereum/core/types/bal"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"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
|
// GetBlockAccessList returns a block access list for the given number/hash
|
||||||
// or nil if one does not exist.
|
// 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
|
var block *types.Block
|
||||||
if num := number.BlockNumber; num != nil {
|
if num := number.BlockNumber; num != nil {
|
||||||
block = api.eth.blockchain.GetBlockByNumber(uint64(num.Int64()))
|
block = api.eth.blockchain.GetBlockByNumber(uint64(num.Int64()))
|
||||||
|
|
@ -548,19 +546,5 @@ func (api *DebugAPI) GetBlockAccessList(number rpc.BlockNumberOrHash) (*bal.Bloc
|
||||||
if block == nil {
|
if block == nil {
|
||||||
return nil, fmt.Errorf("block not found")
|
return nil, fmt.Errorf("block not found")
|
||||||
}
|
}
|
||||||
return block.Body().AccessList, nil
|
return block.Body().AccessList.StringableRepresentation(), 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
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue