Fantom-foundation/go-evm

View on GitHub

Showing 38 of 59 total issues

File web3_account_api.go has 713 lines of code (exceeds 500 allowed). Consider refactoring.
Open

package service

import (
    "bytes"
    "context"
Severity: Minor
Found in src/service/web3_account_api.go - About 7 hrs to fix

    File http_handlers.go has 699 lines of code (exceeds 500 allowed). Consider refactoring.
    Open

    package service
    
    import (
        "bytes"
        "encoding/json"
    Severity: Minor
    Found in src/service/http_handlers.go - About 6 hrs to fix

      File demo.js has 325 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      util = require('util');
      path = require("path");
      JSONbig = require('json-bigint');
      argv = require('minimist')(process.argv.slice(2));
      prompt = require('prompt');
      Severity: Minor
      Found in demo/nodejs/demo.js - About 3 hrs to fix

        Function blockByIdHandler has 107 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func blockByIdHandler(w http.ResponseWriter, r *http.Request, m *Service) {
            param := r.URL.Path[len("/blockById/"):]
            m.logger.WithField("param", param).Debug("GET account")
            id, err := strconv.ParseInt(param, 10, 64)
            if err != nil {
        Severity: Major
        Found in src/service/http_handlers.go - About 3 hrs to fix

          Function blockByHashHandler has 102 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func blockByHashHandler(w http.ResponseWriter, r *http.Request, m *Service) {
              param := r.URL.Path[len("/block/"):]
              m.logger.WithField("param", param).Debug("GET account")
              hash := common.HexToHash(param)
              m.logger.WithField("hash", hash.Hex()).Debug("GET blockByHashHandler")
          Severity: Major
          Found in src/service/http_handlers.go - About 3 hrs to fix

            RpcServer has 23 methods (exceeds 20 allowed). Consider refactoring.
            Open

            type RpcServer struct {
                backend *Service
            
                eventfeed *event.Feed // Event multiplexer used between the services of a stack
                config    *node.Config
            Severity: Minor
            Found in src/service/rpc_server.go - About 2 hrs to fix

              Function transactionReceiptHandler has 77 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func transactionReceiptHandler(w http.ResponseWriter, r *http.Request, m *Service) {
                  param := r.URL.Path[len("/transaction/"):]
                  txHash := common.HexToHash(param)
                  m.logger.WithField("tx_hash", txHash.Hex()).Debug("GET tx")
              
              
              Severity: Major
              Found in src/service/http_handlers.go - About 2 hrs to fix

                Function txReceiptHandler has 77 lines of code (exceeds 50 allowed). Consider refactoring.
                Open

                func txReceiptHandler(w http.ResponseWriter, r *http.Request, m *Service) {
                    param := r.URL.Path[len("/tx/"):]
                    txHash := common.HexToHash(param)
                    m.logger.WithField("tx_hash", txHash.Hex()).Debug("GET tx")
                
                
                Severity: Major
                Found in src/service/http_handlers.go - About 2 hrs to fix

                  Function NewInmemEngine has 63 lines of code (exceeds 50 allowed). Consider refactoring.
                  Open

                  func NewInmemEngine(config config.Config, logger *logrus.Logger) (*InmemEngine, error) {
                      submitCh := make(chan []byte)
                  
                      state, err := state.NewState(logger,
                          config.Eth.DbFile,
                  Severity: Minor
                  Found in src/engine/inmem_engine.go - About 1 hr to fix

                    Method State.applyTransaction has 57 lines of code (exceeds 50 allowed). Consider refactoring.
                    Open

                    func (s *State) applyTransaction(txBytes []byte, txIndex int, blockHash common.Hash) error {
                    
                        var t ethTypes.Transaction
                        if err := rlp.Decode(bytes.NewReader(txBytes), &t); err != nil {
                            s.logger.WithError(err).Error("Decoding Transaction")
                    Severity: Minor
                    Found in src/state/state.go - About 1 hr to fix

                      Function parseLogs has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      Contract.prototype.parseLogs = function(logs) {
                          let c = this
                          // pattern similar to lib/web3/contract.js:  addEventsToContract()
                          let decoders = c.w3.abi.filter(function (json) {
                              return json.type === 'event';
                      Severity: Minor
                      Found in demo/nodejs/contract-lite.js - About 1 hr to fix

                        Function blockByIdHandler has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring.
                        Open

                        func blockByIdHandler(w http.ResponseWriter, r *http.Request, m *Service) {
                            param := r.URL.Path[len("/blockById/"):]
                            m.logger.WithField("param", param).Debug("GET account")
                            id, err := strconv.ParseInt(param, 10, 64)
                            if err != nil {
                        Severity: Minor
                        Found in src/service/http_handlers.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 blockByHashHandler has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
                        Open

                        func blockByHashHandler(w http.ResponseWriter, r *http.Request, m *Service) {
                            param := r.URL.Path[len("/block/"):]
                            m.logger.WithField("param", param).Debug("GET account")
                            hash := common.HexToHash(param)
                            m.logger.WithField("hash", hash.Hex()).Debug("GET blockByHashHandler")
                        Severity: Minor
                        Found in src/service/http_handlers.go - About 55 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

                        Function blockByIdHandler has 9 return statements (exceeds 4 allowed).
                        Open

                        func blockByIdHandler(w http.ResponseWriter, r *http.Request, m *Service) {
                            param := r.URL.Path[len("/blockById/"):]
                            m.logger.WithField("param", param).Debug("GET account")
                            id, err := strconv.ParseInt(param, 10, 64)
                            if err != nil {
                        Severity: Major
                        Found in src/service/http_handlers.go - About 55 mins to fix

                          Function NewWriteAheadState has 7 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                          func NewWriteAheadState(db ethdb.Database,
                              root common.Hash,
                              signer ethTypes.Signer,
                              chainConfig params.ChainConfig,
                              vmConfig vm.Config,
                          Severity: Major
                          Found in src/state/was.go - About 50 mins to fix

                            Function blockByHashHandler has 8 return statements (exceeds 4 allowed).
                            Open

                            func blockByHashHandler(w http.ResponseWriter, r *http.Request, m *Service) {
                                param := r.URL.Path[len("/block/"):]
                                m.logger.WithField("param", param).Debug("GET account")
                                hash := common.HexToHash(param)
                                m.logger.WithField("hash", hash.Hex()).Debug("GET blockByHashHandler")
                            Severity: Major
                            Found in src/service/http_handlers.go - About 50 mins to fix

                              Function NewInmemEngine has 8 return statements (exceeds 4 allowed).
                              Open

                              func NewInmemEngine(config config.Config, logger *logrus.Logger) (*InmemEngine, error) {
                                  submitCh := make(chan []byte)
                              
                                  state, err := state.NewState(logger,
                                      config.Eth.DbFile,
                              Severity: Major
                              Found in src/engine/inmem_engine.go - About 50 mins to fix

                                Method RpcServer.startHTTP has 6 arguments (exceeds 4 allowed). Consider refactoring.
                                Open

                                func (n *RpcServer) startHTTP(endpoint string, apis []rpc.API, modules []string, cors []string, vhosts []string, timeouts rpc.HTTPTimeouts) error {
                                Severity: Minor
                                Found in src/service/rpc_server.go - About 45 mins to fix

                                  Method PublicTransactionPoolAPI.SignTransaction has 7 return statements (exceeds 4 allowed).
                                  Open

                                  func (s *PublicTransactionPoolAPI) SignTransaction(ctx context.Context, args SendTxArgs) (*SignTransactionResult, error) {
                                  
                                      if args.Gas == nil {
                                          return nil, fmt.Errorf("gas not specified")
                                      }
                                  Severity: Major
                                  Found in src/service/web3_account_api.go - About 45 mins to fix

                                    Method WriteAheadState.Commit has 7 return statements (exceeds 4 allowed).
                                    Open

                                    func (was *WriteAheadState) Commit() (common.Hash, error) {
                                        //commit all state changes to the database
                                        root, err := was.ethState.Commit(true)
                                        if err != nil {
                                            was.logger.WithError(err).Error("Committing state")
                                    Severity: Major
                                    Found in src/state/was.go - About 45 mins to fix
                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language