eth: conver if-else-if chain to tagged switch (#27816)

This commit is contained in:
Shude Li 2023-07-31 15:22:36 +08:00 committed by GitHub
parent 95cc7bf4f8
commit 5a4eba6886
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -62,13 +62,14 @@ func (api *DebugAPI) DumpBlock(blockNr rpc.BlockNumber) (state.Dump, error) {
return stateDb.RawDump(opts), nil return stateDb.RawDump(opts), nil
} }
var header *types.Header var header *types.Header
if blockNr == rpc.LatestBlockNumber { switch blockNr {
case rpc.LatestBlockNumber:
header = api.eth.blockchain.CurrentBlock() header = api.eth.blockchain.CurrentBlock()
} else if blockNr == rpc.FinalizedBlockNumber { case rpc.FinalizedBlockNumber:
header = api.eth.blockchain.CurrentFinalBlock() header = api.eth.blockchain.CurrentFinalBlock()
} else if blockNr == rpc.SafeBlockNumber { case rpc.SafeBlockNumber:
header = api.eth.blockchain.CurrentSafeBlock() header = api.eth.blockchain.CurrentSafeBlock()
} else { default:
block := api.eth.blockchain.GetBlockByNumber(uint64(blockNr)) block := api.eth.blockchain.GetBlockByNumber(uint64(blockNr))
if block == nil { if block == nil {
return state.Dump{}, fmt.Errorf("block #%d not found", blockNr) return state.Dump{}, fmt.Errorf("block #%d not found", blockNr)
@ -146,13 +147,14 @@ func (api *DebugAPI) AccountRange(blockNrOrHash rpc.BlockNumberOrHash, start hex
} }
} else { } else {
var header *types.Header var header *types.Header
if number == rpc.LatestBlockNumber { switch number {
case rpc.LatestBlockNumber:
header = api.eth.blockchain.CurrentBlock() header = api.eth.blockchain.CurrentBlock()
} else if number == rpc.FinalizedBlockNumber { case rpc.FinalizedBlockNumber:
header = api.eth.blockchain.CurrentFinalBlock() header = api.eth.blockchain.CurrentFinalBlock()
} else if number == rpc.SafeBlockNumber { case rpc.SafeBlockNumber:
header = api.eth.blockchain.CurrentSafeBlock() header = api.eth.blockchain.CurrentSafeBlock()
} else { default:
block := api.eth.blockchain.GetBlockByNumber(uint64(number)) block := api.eth.blockchain.GetBlockByNumber(uint64(number))
if block == nil { if block == nil {
return state.IteratorDump{}, fmt.Errorf("block #%d not found", number) return state.IteratorDump{}, fmt.Errorf("block #%d not found", number)