aboutsummaryrefslogtreecommitdiffstats
path: root/eth
diff options
context:
space:
mode:
Diffstat (limited to 'eth')
-rw-r--r--eth/api.go29
1 files changed, 27 insertions, 2 deletions
diff --git a/eth/api.go b/eth/api.go
index 247ca7485..446161cc4 100644
--- a/eth/api.go
+++ b/eth/api.go
@@ -32,6 +32,7 @@ import (
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
+ "github.com/ethereum/go-ethereum/internal/ethapi"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/miner"
"github.com/ethereum/go-ethereum/params"
@@ -351,10 +352,34 @@ func (api *PrivateDebugAPI) Preimage(ctx context.Context, hash common.Hash) (hex
return nil, errors.New("unknown preimage")
}
+// BadBlockArgs represents the entries in the list returned when bad blocks are queried.
+type BadBlockArgs struct {
+ Hash common.Hash `json:"hash"`
+ Block map[string]interface{} `json:"block"`
+ RLP string `json:"rlp"`
+}
+
// 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) ([]core.BadBlockArgs, error) {
- return api.eth.BlockChain().BadBlocks()
+func (api *PrivateDebugAPI) GetBadBlocks(ctx context.Context) ([]*BadBlockArgs, error) {
+ blocks := api.eth.BlockChain().BadBlocks()
+ results := make([]*BadBlockArgs, len(blocks))
+
+ var err error
+ for i, block := range blocks {
+ results[i] = &BadBlockArgs{
+ Hash: block.Hash(),
+ }
+ 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()}
+ }
+ }
+ return results, nil
}
// StorageRangeResult is the result of a debug_storageRangeAt API call.