MCPcopy Create free account
hub / github.com/CPChain/chain / GetBadBlocks

Method GetBadBlocks

protocols/cpc/api.go:347–366  ·  view source on GitHub ↗

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

(ctx context.Context)

Source from the content-addressed store, hash-verified

345// GetBadBlocks returns a list of the last 'bad blocks' that the client has seen on the network
346// and returns them as a JSON list of block-hashes
347func (api *PrivateDebugAPI) GetBadBlocks(ctx context.Context) ([]*BadBlockArgs, error) {
348 blocks := api.cpc.BlockChain().BadBlocks()
349 results := make([]*BadBlockArgs, len(blocks))
350
351 var err error
352 for i, block := range blocks {
353 results[i] = &BadBlockArgs{
354 Hash: block.Hash(),
355 }
356 if rlpBytes, err := rlp.EncodeToBytes(block); err != nil {
357 results[i].RLP = err.Error() // Hacky, but hey, it works
358 } else {
359 results[i].RLP = fmt.Sprintf("0x%x", rlpBytes)
360 }
361 if results[i].Block, err = cpcapi.RPCMarshalBlock(block, true, true); err != nil {
362 results[i].Block = map[string]interface{}{"error": err.Error()}
363 }
364 }
365 return results, nil
366}
367
368// StorageRangeResult is the result of a debug_storageRangeAt API call.
369type StorageRangeResult struct {

Callers

nothing calls this directly

Calls 4

BadBlocksMethod · 0.80
BlockChainMethod · 0.65
HashMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected