mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +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
|
||||
// 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()
|
||||
responseBlocks := make([]BadBlockArgs, 0, len(blocks))
|
||||
for _, block := range blocks {
|
||||
rlpData, err := rlp.EncodeToBytes(block)
|
||||
if err != nil {
|
||||
return responseBlocks, err
|
||||
results := make([]*BadBlockArgs, len(blocks))
|
||||
|
||||
var err error
|
||||
for i, block := range blocks {
|
||||
results[i] = &BadBlockArgs{
|
||||
Hash: block.Hash(),
|
||||
}
|
||||
var (
|
||||
blockdata map[string]interface{}
|
||||
berr error
|
||||
)
|
||||
// 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 blockdata, berr = ethapi.RpcMarshalBlock(block, true, true); berr != nil {
|
||||
blockdata["error"] = berr.Error()
|
||||
if rlpBytes, err := rlp.EncodeToBytes(block); err != nil {
|
||||
results[i].RLP = err.Error() // Hacky, but hey, it works
|
||||
} else {
|
||||
results[i].RLP = fmt.Sprintf("0x%x", rlpBytes)
|
||||
}
|
||||
if results[i].Block, err = ethapi.RPCMarshalBlock(block, true, true); err != nil {
|
||||
results[i].Block = map[string]interface{}{"error": err.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.
|
||||
|
|
|
|||
|
|
@ -792,10 +792,10 @@ func FormatLogs(logs []vm.StructLog) []StructLogRes {
|
|||
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
|
||||
// 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
|
||||
fields := map[string]interface{}{
|
||||
"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
|
||||
// a `PublicBlockchainAPI`.
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue