aergoio/aergo

View on GitHub

Showing 1,051 of 1,052 total issues

Avoid deeply nested control flow statements.
Open

                    if vprLogger.IsDebugEnabled() {
                        vprLogger.Debug().
                            Str("total voting power", totalVp.String()).
                            Str("addr", base58.Encode(winner)).
                            Msg("pick voting reward winner")
Severity: Major
Found in contract/system/vprt.go - About 45 mins to fix

    Method Web3APIv1.GetBlockBody has 7 return statements (exceeds 4 allowed).
    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
        }
    Severity: Major
    Found in rpc/web3/v1.go - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                          } else if conf == enterprise.AccountWhite {
                              values := make([]string, 1024)
                              if err := json.Unmarshal([]byte(e.JsonArgs), &values); err != nil {
                                  return
                              }
      Severity: Major
      Found in rpc/rpc.go - About 45 mins to fix

        Method Web3APIv1.ListEvents has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
        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
            }
        Severity: Minor
        Found in rpc/web3/v1.go - About 45 mins to fix

        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

        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()
        Severity: Major
        Found in chain/reorg.go - About 45 mins to fix

          Method SignVerifier.verifyTx has 7 return statements (exceeds 4 allowed).
          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
              }
          Severity: Major
          Found in chain/signVerifier.go - About 45 mins to fix

            Method Trie.loadBatch has 7 return statements (exceeds 4 allowed).
            Open

            func (s *Trie) loadBatch(root []byte) ([][]byte, error) {
                var node Hash
                copy(node[:], root)
            
                s.db.liveMux.RLock()
            Severity: Major
            Found in pkg/trie/trie.go - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                  if err != nil {
                                      fmt.Fprintf(stdOut, "\x1B[0;37mWatching File %s Error: %s\x1B[0m\n", batchFilePath, err.Error())
                                  }
              Severity: Major
              Found in cmd/brick/exec/batch.go - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                } else if !takeNextSymbol {
                                    current = chunkNum - 1
                                    symbol = syntaxSplit[current]
                                }
                Severity: Major
                Found in cmd/brick/brick.go - About 45 mins to fix

                  Method Trie.maybeDeleteSubTree has 7 return statements (exceeds 4 allowed).
                  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)
                          }
                  Severity: Major
                  Found in pkg/trie/trie_revert.go - About 45 mins to fix

                    Method Web3APIv1.ListBlockMetadata has 7 return statements (exceeds 4 allowed).
                    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
                        }
                    Severity: Major
                    Found in rpc/web3/v1.go - About 45 mins to fix

                      Function importKeystore has 7 return statements (exceeds 4 allowed).
                      Open

                      func importKeystore(cmd *cobra.Command) ([]byte, error) {
                          var err error
                          var address []byte
                          absPath, err := filepath.Abs(importFilePath)
                          if err != nil {
                      Severity: Major
                      Found in cmd/aergocli/cmd/accounts.go - About 45 mins to fix

                        Method reorganizer.swapChain has 7 return statements (exceeds 4 allowed).
                        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
                        Severity: Major
                        Found in chain/reorg.go - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                                  if err := json.Unmarshal([]byte(e.JsonArgs), &values); err != nil {
                                                      return
                                                  }
                          Severity: Major
                          Found in rpc/rpc.go - About 45 mins to fix

                            Function sendTX has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
                            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)
                            Severity: Minor
                            Found in cmd/aergocli/cmd/sendtx.go - About 45 mins to fix

                            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

                            func (cs *ChainService) Recover() error {
                                defer RecoverExit()
                            
                                logger.Debug().Msg("recover start")
                            
                            
                            Severity: Major
                            Found in chain/recover.go - About 45 mins to fix

                              Method luaTxCall.run has 7 return statements (exceeds 4 allowed).
                              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)
                              
                              
                              Severity: Major
                              Found in contract/vm_dummy/vm_dummy.go - About 45 mins to fix

                                Avoid deeply nested control flow statements.
                                Open

                                                        if err != ErrQuitHashFetcher {
                                                            stopSyncer(hf.compRequester, hf.GetSeq(), hf.name, err)
                                                        }
                                Severity: Major
                                Found in syncer/hashfetcher.go - About 45 mins to fix

                                  Avoid deeply nested control flow statements.
                                  Open

                                                      if arg == v {
                                                          return nil, fmt.Errorf("admin is in the account whitelist: %s", ci.Args[0])
                                                      }
                                  Severity: Major
                                  Found in contract/enterprise/validate.go - About 45 mins to fix

                                    Method recoveryEntry.recovery has 7 return statements (exceeds 4 allowed).
                                    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 {
                                    Severity: Major
                                    Found in contract/vm_state.go - About 45 mins to fix
                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language