aergoio/aergo

View on GitHub

Showing 1,051 of 1,052 total issues

Method Web3APIv1.GetReceipts has 61 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (api *Web3APIv1) GetReceipts() (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 1 hr to fix

    Method AccountService.Receive has a Cognitive Complexity of 27 (exceeds 20 allowed). Consider refactoring.
    Open

    func (as *AccountService) Receive(context actor.Context) {
    
        switch msg := context.Message().(type) {
        case *message.GetAccounts:
            accountList := as.getAccounts()
    Severity: Minor
    Found in account/accountservice.go - About 1 hr 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 BlockGenerator.GatherTXs has a Cognitive Complexity of 27 (exceeds 20 allowed). Consider refactoring.
    Open

    func (g *BlockGenerator) GatherTXs() ([]types.Transaction, error) {
        var (
            bState = g.bState
    
            nCollected int
    Severity: Minor
    Found in consensus/chain/tx.go - About 1 hr 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

    Function runCallCmd has 15 return statements (exceeds 4 allowed).
    Open

    func runCallCmd(cmd *cobra.Command, args []string) error {
        cmd.SilenceUsage = true
    
        caller, err := types.DecodeAddress(args[0])
        if err != nil {
    Severity: Major
    Found in cmd/aergocli/cmd/contract.go - About 1 hr to fix

      Method SignVerifier.RequestVerifyTxs has a Cognitive Complexity of 27 (exceeds 20 allowed). Consider refactoring.
      Open

      func (sv *SignVerifier) RequestVerifyTxs(txlist *types.TxList) {
          txs := txlist.GetTxs()
          txLen := len(txs)
      
          if txLen == 0 {
      Severity: Minor
      Found in chain/signVerifier.go - About 1 hr 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

      Function ParseTxBody has a Cognitive Complexity of 27 (exceeds 20 allowed). Consider refactoring.
      Open

      func ParseTxBody(tb *InOutTxBody) (msg *types.TxBody, err error) {
          if tb == nil {
              return nil, errors.New("tx body is empty")
          }
          msg = &types.TxBody{}
      Severity: Minor
      Found in types/jsonrpc/tx.go - About 1 hr 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

      Function ParseTxBody has 60 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func ParseTxBody(tb *InOutTxBody) (msg *types.TxBody, err error) {
          if tb == nil {
              return nil, errors.New("tx body is empty")
          }
          msg = &types.TxBody{}
      Severity: Minor
      Found in types/jsonrpc/tx.go - About 1 hr to fix

        Method BlockFetcher.searchCandidateTask has 60 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (bf *BlockFetcher) searchCandidateTask() (*FetchTask, error) {
            getNewHashSet := func() (*HashSet, error) {
                if bf.curHashSet == nil { //blocking
                    logger.Info().Msg("BlockFetcher waiting first hashset")
        
        
        Severity: Minor
        Found in syncer/blockfetcher.go - About 1 hr to fix

          Function init has 59 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func init() {
              contractCmd := &cobra.Command{
                  Use:   "contract [flags] subcommand",
                  Short: "Contract command",
              }
          Severity: Minor
          Found in cmd/aergocli/cmd/contract.go - About 1 hr to fix

            Function execGetState has 59 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func execGetState(cmd *cobra.Command, args []string) {
                var root []byte
                var err error
                if len(stateroot) != 0 {
                    root, err = base58.Decode(stateroot)
            Severity: Minor
            Found in cmd/aergocli/cmd/getstate.go - About 1 hr to fix

              Method Syncer.handleMessage has 59 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func (syncer *Syncer) handleMessage(inmsg interface{}) {
                  defer syncer.RecoverSyncerSelf()
              
                  if !syncer.verifySeq(inmsg) {
                      return
              Severity: Minor
              Found in syncer/syncerservice.go - About 1 hr to fix

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                func serveSwaggerYAML(path string) func(w http.ResponseWriter, r *http.Request) {
                    return func(w http.ResponseWriter, r *http.Request) {
                        yamlContent, err := os.ReadFile(path + "swagger.yaml")
                        if err != nil {
                            http.Error(w, "Failed to read YAML file", http.StatusInternalServerError)
                Severity: Major
                Found in rpc/web3/web3.go and 1 other location - About 1 hr to fix
                rpc/web3/web3.go on lines 157..168

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 151.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                func serveSwaggerUI(path string) func(w http.ResponseWriter, r *http.Request) {
                    return func(w http.ResponseWriter, r *http.Request) {
                        htmlContent, err := os.ReadFile(path + "swagger-ui.html")
                        if err != nil {
                            http.Error(w, "Failed to read HTML file", http.StatusInternalServerError)
                Severity: Major
                Found in rpc/web3/web3.go and 1 other location - About 1 hr to fix
                rpc/web3/web3.go on lines 144..155

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 151.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Method MemPool.Receive has 58 lines of code (exceeds 50 allowed). Consider refactoring.
                Open

                func (mp *MemPool) Receive(context actor.Context) {
                
                    switch msg := context.Message().(type) {
                    case *message.MemPoolPut:
                        mp.verifier.Request(msg.Tx, context.Sender())
                Severity: Minor
                Found in mempool/mempool.go - About 1 hr to fix

                  Identical blocks of code found in 2 locations. Consider refactoring.
                  Open

                  func resetAccount(account *state.AccountState, fee *big.Int, nonce *uint64) error {
                      account.Reset()
                      if fee != nil {
                          if account.Balance().Cmp(fee) < 0 {
                              return &types.InternalError{Reason: "fee is greater than balance"}
                  Severity: Major
                  Found in contract/vm_direct/vm_direct.go and 1 other location - About 1 hr to fix
                  chain/chainhandle.go on lines 932..944

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 149.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Identical blocks of code found in 2 locations. Consider refactoring.
                  Open

                  func resetAccount(account *state.AccountState, fee *big.Int, nonce *uint64) error {
                      account.Reset()
                      if fee != nil {
                          if account.Balance().Cmp(fee) < 0 {
                              return &types.InternalError{Reason: "fee is greater than balance"}
                  Severity: Major
                  Found in chain/chainhandle.go and 1 other location - About 1 hr to fix
                  contract/vm_direct/vm_direct.go on lines 364..376

                  Duplicated Code

                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                  Tuning

                  This issue has a mass of 149.

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

                  Method Cluster.isEnableChangeMembership has 57 lines of code (exceeds 50 allowed). Consider refactoring.
                  Open

                  func (cl *Cluster) isEnableChangeMembership(cc *raftpb.ConfChange) error {
                      status := cl.rs.Status()
                      if status.ID == 0 {
                          logger.Debug().Msg("raft node is not initialized")
                          return ErrRaftStatusEmpty
                  Severity: Minor
                  Found in consensus/impl/raftv2/cluster.go - About 1 hr to fix

                    Method getHashRequestHandler.Handle has 57 lines of code (exceeds 50 allowed). Consider refactoring.
                    Open

                    func (bh *getHashRequestHandler) Handle(msg p2pcommon.Message, msgBody p2pcommon.MessageBody) {
                        remotePeer := bh.peer
                        data := msgBody.(*types.GetHashesRequest)
                        p2putil.DebugLogReceive(bh.logger, bh.protocol, msg.ID().String(), remotePeer, data)
                        chainAccessor := bh.actor.GetChainAccessor()
                    Severity: Minor
                    Found in p2p/subproto/blockhash.go - About 1 hr to fix

                      Similar blocks of code found in 2 locations. Consider refactoring.
                      Open

                      LOOP:
                          for i := 0; i < cnt; i++ {
                              blockHash, err := tchain.GetHashByNo(blkNo)
                              if err != nil {
                                  logger.Info().Msg("assertion - hash get failed")
                      Severity: Major
                      Found in chain/stubchain.go and 1 other location - About 1 hr to fix
                      chain/chainanchor.go on lines 31..53

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 146.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      Similar blocks of code found in 2 locations. Consider refactoring.
                      Open

                      LOOP:
                          for i := 0; i < cnt; i++ {
                              blockHash, err := cs.getHashByNo(blkNo)
                              if err != nil {
                                  logger.Info().Msg("assertion - hash get failed")
                      Severity: Major
                      Found in chain/chainanchor.go and 1 other location - About 1 hr to fix
                      chain/stubchain.go on lines 178..200

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 146.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      Severity
                      Category
                      Status
                      Source
                      Language