mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
ethapi: address review concerns
This commit is contained in:
parent
904e903392
commit
df7022b179
2 changed files with 18 additions and 23 deletions
35
eth/api.go
35
eth/api.go
|
|
@ -361,30 +361,25 @@ type BadBlockArgs struct {
|
||||||
|
|
||||||
// GetBadBLocks returns a list of the last 'bad blocks' that the client has seen on the network
|
// GetBadBLocks returns a list of the last 'bad blocks' that the client has seen on the network
|
||||||
// and returns them as a JSON list of block-hashes
|
// and returns them as a JSON list of block-hashes
|
||||||
func (api *PrivateDebugAPI) GetBadBlocks(ctx context.Context) ([]BadBlockArgs, error) {
|
func (api *PrivateDebugAPI) GetBadBlocks(ctx context.Context) ([]*BadBlockArgs, error) {
|
||||||
blocks := api.eth.BlockChain().BadBlocks()
|
blocks := api.eth.BlockChain().BadBlocks()
|
||||||
responseBlocks := make([]BadBlockArgs, 0, len(blocks))
|
results := make([]*BadBlockArgs, len(blocks))
|
||||||
for _, block := range blocks {
|
|
||||||
rlpData, err := rlp.EncodeToBytes(block)
|
var err error
|
||||||
if err != nil {
|
for i, block := range blocks {
|
||||||
return responseBlocks, err
|
results[i] = &BadBlockArgs{
|
||||||
|
Hash: block.Hash(),
|
||||||
}
|
}
|
||||||
var (
|
if rlpBytes, err := rlp.EncodeToBytes(block); err != nil {
|
||||||
blockdata map[string]interface{}
|
results[i].RLP = err.Error() // Hacky, but hey, it works
|
||||||
berr error
|
} else {
|
||||||
)
|
results[i].RLP = fmt.Sprintf("0x%x", rlpBytes)
|
||||||
// A bad block may be so malformed that it the expanded format fails to generate
|
}
|
||||||
// correctly. If so, provide the caller with error message and RLP anyway
|
if results[i].Block, err = ethapi.RPCMarshalBlock(block, true, true); err != nil {
|
||||||
if blockdata, berr = ethapi.RpcMarshalBlock(block, true, true); berr != nil {
|
results[i].Block = map[string]interface{}{"error": err.Error()}
|
||||||
blockdata["error"] = berr.Error()
|
|
||||||
}
|
}
|
||||||
responseBlocks = append(responseBlocks, BadBlockArgs{
|
|
||||||
Hash: block.Hash(),
|
|
||||||
Block: blockdata,
|
|
||||||
RLP: fmt.Sprintf("%x", rlpData),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
return responseBlocks, nil
|
return results, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// StorageRangeResult is the result of a debug_storageRangeAt API call.
|
// StorageRangeResult is the result of a debug_storageRangeAt API call.
|
||||||
|
|
|
||||||
|
|
@ -792,10 +792,10 @@ func FormatLogs(logs []vm.StructLog) []StructLogRes {
|
||||||
return formatted
|
return formatted
|
||||||
}
|
}
|
||||||
|
|
||||||
// RpcMarshalBlock converts the given block to the RPC output which depends on fullTx. If inclTx is true transactions are
|
// RPCMarshalBlock converts the given block to the RPC output which depends on fullTx. If inclTx is true transactions are
|
||||||
// returned. When fullTx is true the returned block contains full transaction details, otherwise it will only contain
|
// returned. When fullTx is true the returned block contains full transaction details, otherwise it will only contain
|
||||||
// transaction hashes.
|
// transaction hashes.
|
||||||
func RpcMarshalBlock(b *types.Block, inclTx bool, fullTx bool) (map[string]interface{}, error) {
|
func RPCMarshalBlock(b *types.Block, inclTx bool, fullTx bool) (map[string]interface{}, error) {
|
||||||
head := b.Header() // copies the header once
|
head := b.Header() // copies the header once
|
||||||
fields := map[string]interface{}{
|
fields := map[string]interface{}{
|
||||||
"number": (*hexutil.Big)(head.Number),
|
"number": (*hexutil.Big)(head.Number),
|
||||||
|
|
@ -850,7 +850,7 @@ func RpcMarshalBlock(b *types.Block, inclTx bool, fullTx bool) (map[string]inter
|
||||||
// rpcOutputBlock uses the generalized output filler, then adds the total difficulty field, which requires
|
// rpcOutputBlock uses the generalized output filler, then adds the total difficulty field, which requires
|
||||||
// a `PublicBlockchainAPI`.
|
// a `PublicBlockchainAPI`.
|
||||||
func (s *PublicBlockChainAPI) rpcOutputBlock(b *types.Block, inclTx bool, fullTx bool) (map[string]interface{}, error) {
|
func (s *PublicBlockChainAPI) rpcOutputBlock(b *types.Block, inclTx bool, fullTx bool) (map[string]interface{}, error) {
|
||||||
fields, err := RpcMarshalBlock(b, inclTx, fullTx)
|
fields, err := RPCMarshalBlock(b, inclTx, fullTx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue