Showing 1,051 of 1,052 total issues
Avoid deeply nested control flow statements. Open
Open
if vprLogger.IsDebugEnabled() {
vprLogger.Debug().
Str("total voting power", totalVp.String()).
Str("addr", base58.Encode(winner)).
Msg("pick voting reward winner")
Method Web3APIv1.GetBlockBody
has 7 return statements (exceeds 4 allowed). Open
Open
func (api *Web3APIv1) GetBlockBody() (handler http.Handler, ok bool) {
values, err := url.ParseQuery(api.request.URL.RawQuery)
if err != nil {
return commonResponseHandler(&types.Empty{}, err), true
}
Avoid deeply nested control flow statements. Open
Open
} else if conf == enterprise.AccountWhite {
values := make([]string, 1024)
if err := json.Unmarshal([]byte(e.JsonArgs), &values); err != nil {
return
}
Method Web3APIv1.ListEvents
has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring. Open
Open
func (api *Web3APIv1) ListEvents() (handler http.Handler, ok bool) {
values, err := url.ParseQuery(api.request.URL.RawQuery)
if err != nil {
return commonResponseHandler(&types.Empty{}, err), true
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method ChainService.reorg
has 7 return statements (exceeds 4 allowed). Open
Open
func (cs *ChainService) reorg(topBlock *types.Block, marker *ReorgMarker) error {
logger.Info().Uint64("blockNo", topBlock.GetHeader().GetBlockNo()).Str("hash", topBlock.ID()).
Bool("recovery", (marker != nil)).Msg("reorg started")
begT := time.Now()
Method SignVerifier.verifyTx
has 7 return statements (exceeds 4 allowed). Open
Open
func (sv *SignVerifier) verifyTx(comm component.IComponentRequester, tx *types.Tx, useMempool bool) (hit bool, err error) {
account := tx.GetBody().GetAccount()
if account == nil {
return false, ErrTxFormatInvalid
}
Method Trie.loadBatch
has 7 return statements (exceeds 4 allowed). Open
Open
func (s *Trie) loadBatch(root []byte) ([][]byte, error) {
var node Hash
copy(node[:], root)
s.db.liveMux.RLock()
Avoid deeply nested control flow statements. Open
Open
if err != nil {
fmt.Fprintf(stdOut, "\x1B[0;37mWatching File %s Error: %s\x1B[0m\n", batchFilePath, err.Error())
}
Avoid deeply nested control flow statements. Open
Open
} else if !takeNextSymbol {
current = chunkNum - 1
symbol = syntaxSplit[current]
}
Method Trie.maybeDeleteSubTree
has 7 return statements (exceeds 4 allowed). Open
Open
func (s *Trie) maybeDeleteSubTree(original, maybeDelete []byte, height, iBatch int, batch, batch2 [][]byte, ch chan<- (error)) {
if height == 0 {
if !bytes.Equal(original, maybeDelete) && len(maybeDelete) != 0 {
s.maybeDeleteRevertedNode(maybeDelete, 0)
}
Method Web3APIv1.ListBlockMetadata
has 7 return statements (exceeds 4 allowed). Open
Open
func (api *Web3APIv1) ListBlockMetadata() (handler http.Handler, ok bool) {
values, err := url.ParseQuery(api.request.URL.RawQuery)
if err != nil {
return commonResponseHandler(&types.Empty{}, err), true
}
Function importKeystore
has 7 return statements (exceeds 4 allowed). Open
Open
func importKeystore(cmd *cobra.Command) ([]byte, error) {
var err error
var address []byte
absPath, err := filepath.Abs(importFilePath)
if err != nil {
Method reorganizer.swapChain
has 7 return statements (exceeds 4 allowed). Open
Open
func (reorg *reorganizer) swapChain() error {
logger.Info().Msg("swap chain to new branch")
if err := TestDebugger.Check(DEBUG_CHAIN_STOP, 1, nil); err != nil {
return err
Avoid deeply nested control flow statements. Open
Open
if err := json.Unmarshal([]byte(e.JsonArgs), &values); err != nil {
return
}
Function sendTX
has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring. Open
Open
func sendTX(cmd *cobra.Command, tx *types.Tx, account []byte) string {
if rootConfig.KeyStorePath != "" {
var err error
if pw == "" {
pw, err = getPasswd(cmd, false)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method ChainService.Recover
has 7 return statements (exceeds 4 allowed). Open
Open
func (cs *ChainService) Recover() error {
defer RecoverExit()
logger.Debug().Msg("recover start")
Method luaTxCall.run
has 7 return statements (exceeds 4 allowed). Open
Open
func (l *luaTxCall) run(execCtx context.Context, bs *state.BlockState, bc *DummyChain, bi *types.BlockHeaderInfo, receiptTx db.Transaction) error {
err := contractFrame(l, bs, bc, receiptTx,
func(sender, contractV *state.AccountState, contractId types.AccountID, eContractState *statedb.ContractState) (string, []*types.Event, *big.Int, error) {
ctx := contract.NewVmContext(execCtx, bs, bc, sender, contractV, eContractState, sender.ID(), l.Hash(), bi, "", true, false, contractV.State().SqlRecoveryPoint, contract.BlockFactory, l.amount(), math.MaxUint64, l.feeDelegate)
Avoid deeply nested control flow statements. Open
Open
if err != ErrQuitHashFetcher {
stopSyncer(hf.compRequester, hf.GetSeq(), hf.name, err)
}
Avoid deeply nested control flow statements. Open
Open
if arg == v {
return nil, fmt.Errorf("admin is in the account whitelist: %s", ci.Args[0])
}
Method recoveryEntry.recovery
has 7 return statements (exceeds 4 allowed). Open
Open
func (re *recoveryEntry) recovery(bs *state.BlockState) error {
var zero big.Int
cs := re.callState
if re.amount.Cmp(&zero) > 0 {
if re.senderState != nil {