mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-24 07:34:31 +00:00
This commit is contained in:
parent
df9623dbe9
commit
689ac1b12a
3 changed files with 6 additions and 16 deletions
|
|
@ -90,7 +90,6 @@ type BadBlockArgs struct {
|
|||
// and returns them as a JSON list of block-hashes
|
||||
func (api *DebugAPI) GetBadBlocks(ctx context.Context) ([]*BadBlockArgs, error) {
|
||||
var (
|
||||
err error
|
||||
blocks = rawdb.ReadAllBadBlocks(api.eth.chainDb)
|
||||
results = make([]*BadBlockArgs, 0, len(blocks))
|
||||
)
|
||||
|
|
@ -104,9 +103,7 @@ func (api *DebugAPI) GetBadBlocks(ctx context.Context) ([]*BadBlockArgs, error)
|
|||
} else {
|
||||
blockRlp = fmt.Sprintf("%#x", rlpBytes)
|
||||
}
|
||||
if blockJSON, err = ethapi.RPCMarshalBlock(block, true, true, api.eth.ApiBackend.ChainConfig()); err != nil {
|
||||
blockJSON = map[string]interface{}{"error": err.Error()}
|
||||
}
|
||||
blockJSON = ethapi.RPCMarshalBlock(block, true, true, api.eth.ApiBackend.ChainConfig())
|
||||
results = append(results, &BadBlockArgs{
|
||||
Hash: block.Hash(),
|
||||
RLP: blockRlp,
|
||||
|
|
|
|||
|
|
@ -1340,7 +1340,7 @@ func RPCMarshalHeader(head *types.Header) map[string]interface{} {
|
|||
// 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(block *types.Block, inclTx bool, fullTx bool, config *params.ChainConfig) (map[string]interface{}, error) {
|
||||
func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *params.ChainConfig) map[string]interface{} {
|
||||
fields := RPCMarshalHeader(block.Header())
|
||||
fields["size"] = hexutil.Uint64(block.Size())
|
||||
|
||||
|
|
@ -1366,20 +1366,17 @@ func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *param
|
|||
uncleHashes[i] = uncle.Hash()
|
||||
}
|
||||
fields["uncles"] = uncleHashes
|
||||
return fields, nil
|
||||
return fields
|
||||
}
|
||||
|
||||
// rpcMarshalBlock uses the generalized output filler, then adds the total difficulty field, which requires
|
||||
// a `BlockChainAPI`.
|
||||
func (api *BlockChainAPI) rpcMarshalBlock(ctx context.Context, b *types.Block, inclTx bool, fullTx bool) (map[string]interface{}, error) {
|
||||
fields, err := RPCMarshalBlock(b, inclTx, fullTx, api.b.ChainConfig())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fields := RPCMarshalBlock(b, inclTx, fullTx, api.b.ChainConfig())
|
||||
if inclTx {
|
||||
fields["totalDifficulty"] = (*hexutil.Big)(api.b.GetTd(ctx, b.Hash()))
|
||||
}
|
||||
return fields, err
|
||||
return fields, nil
|
||||
}
|
||||
|
||||
// findNearestSignedBlock finds the nearest checkpoint from input block
|
||||
|
|
|
|||
|
|
@ -110,11 +110,7 @@ func TestRPCMarshalBlock(t *testing.T) {
|
|||
}
|
||||
|
||||
for i, tc := range testSuite {
|
||||
resp, err := RPCMarshalBlock(block, tc.inclTx, tc.fullTx, params.MainnetChainConfig)
|
||||
if err != nil {
|
||||
t.Errorf("test %d: got error %v", i, err)
|
||||
continue
|
||||
}
|
||||
resp := RPCMarshalBlock(block, tc.inclTx, tc.fullTx, params.MainnetChainConfig)
|
||||
out, err := json.Marshal(resp)
|
||||
if err != nil {
|
||||
t.Errorf("test %d: json marshal error: %v", i, err)
|
||||
|
|
|
|||
Loading…
Reference in a new issue