Fantom-foundation/go-lachesis

View on GitHub
ethapi/api.go

Summary

Maintainability
F
6 days
Test Coverage

File api.go has 1526 lines of code (exceeds 500 allowed). Consider refactoring.
Open

// Copyright 2015 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
Severity: Major
Found in ethapi/api.go - About 3 days to fix

    Function DoEstimateGas has a Cognitive Complexity of 45 (exceeds 20 allowed). Consider refactoring.
    Open

    func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.BlockNumberOrHash, gasCap uint64) (hexutil.Uint64, error) {
        // Binary search the gas requirement, as it may be higher than the amount used
        var (
            lo  uint64 = params.TxGas - 1
            hi  uint64
    Severity: Minor
    Found in ethapi/api.go - About 4 hrs 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 DoEstimateGas has 81 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.BlockNumberOrHash, gasCap uint64) (hexutil.Uint64, error) {
        // Binary search the gas requirement, as it may be higher than the amount used
        var (
            lo  uint64 = params.TxGas - 1
            hi  uint64
    Severity: Major
    Found in ethapi/api.go - About 2 hrs to fix

      Method PublicTransactionPoolAPI.Resend has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring.
      Open

      func (s *PublicTransactionPoolAPI) Resend(ctx context.Context, sendArgs SendTxArgs, gasPrice *hexutil.Big, gasLimit *hexutil.Uint64) (common.Hash, error) {
          if sendArgs.Nonce == nil {
              return common.Hash{}, fmt.Errorf("missing transaction nonce in transaction spec")
          }
          if err := sendArgs.setDefaults(ctx, s.b); err != nil {
      Severity: Minor
      Found in ethapi/api.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 DoCall has 55 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides map[common.Address]account, vmCfg vm.Config, timeout time.Duration, globalGasCap uint64) (*evmcore.ExecutionResult, error) {
          defer func(start time.Time) { log.Debug("Executing EVM call finished", "runtime", time.Since(start)) }(time.Now())
      
          state, header, err := b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash)
          if state == nil || err != nil {
      Severity: Minor
      Found in ethapi/api.go - About 1 hr to fix

        Function DoEstimateGas has 11 return statements (exceeds 4 allowed).
        Open

        func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.BlockNumberOrHash, gasCap uint64) (hexutil.Uint64, error) {
            // Binary search the gas requirement, as it may be higher than the amount used
            var (
                lo  uint64 = params.TxGas - 1
                hi  uint64
        Severity: Major
        Found in ethapi/api.go - About 1 hr to fix

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

          func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides map[common.Address]account, vmCfg vm.Config, timeout time.Duration, globalGasCap uint64) (*evmcore.ExecutionResult, error) {
              defer func(start time.Time) { log.Debug("Executing EVM call finished", "runtime", time.Since(start)) }(time.Now())
          
              state, header, err := b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash)
              if state == nil || err != nil {
          Severity: Minor
          Found in ethapi/api.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 SendTxArgs.setDefaults has 52 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (args *SendTxArgs) setDefaults(ctx context.Context, b Backend) error {
              if args.GasPrice == nil {
                  price, err := b.SuggestPrice(ctx)
                  if err != nil {
                      return err
          Severity: Minor
          Found in ethapi/api.go - About 1 hr to fix

            Method PublicTransactionPoolAPI.GetTransactionReceipt has 51 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func (s *PublicTransactionPoolAPI) GetTransactionReceipt(ctx context.Context, hash common.Hash) (map[string]interface{}, error) {
                tx, blockNumber, index, err := s.b.GetTransaction(ctx, hash)
                if tx == nil || err != nil {
                    return nil, err
                }
            Severity: Minor
            Found in ethapi/api.go - About 1 hr to fix

              Function DoCall has 8 arguments (exceeds 4 allowed). Consider refactoring.
              Open

              func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides map[common.Address]account, vmCfg vm.Config, timeout time.Duration, globalGasCap uint64) (*evmcore.ExecutionResult, error) {
              Severity: Major
              Found in ethapi/api.go - About 1 hr to fix

                Method PublicTransactionPoolAPI.SignTransaction has 8 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")
                    }
                    if args.GasPrice == nil {
                Severity: Major
                Found in ethapi/api.go - About 50 mins to fix

                  Method PublicTransactionPoolAPI.Resend has 8 return statements (exceeds 4 allowed).
                  Open

                  func (s *PublicTransactionPoolAPI) Resend(ctx context.Context, sendArgs SendTxArgs, gasPrice *hexutil.Big, gasLimit *hexutil.Uint64) (common.Hash, error) {
                      if sendArgs.Nonce == nil {
                          return common.Hash{}, fmt.Errorf("missing transaction nonce in transaction spec")
                      }
                      if err := sendArgs.setDefaults(ctx, s.b); err != nil {
                  Severity: Major
                  Found in ethapi/api.go - About 50 mins to fix

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

                    func (s *PrivateAccountAPI) SignTransaction(ctx context.Context, args SendTxArgs, passwd string) (*SignTransactionResult, error) {
                        // No need to obtain the noncelock mutex, since we won't be sending this
                        // tx into the transaction pool, but right back to the user
                        if args.Gas == nil {
                            return nil, fmt.Errorf("gas not specified")
                    Severity: Major
                    Found in ethapi/api.go - About 45 mins to fix

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

                      func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides map[common.Address]account, vmCfg vm.Config, timeout time.Duration, globalGasCap uint64) (*evmcore.ExecutionResult, error) {
                          defer func(start time.Time) { log.Debug("Executing EVM call finished", "runtime", time.Since(start)) }(time.Now())
                      
                          state, header, err := b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash)
                          if state == nil || err != nil {
                      Severity: Major
                      Found in ethapi/api.go - About 45 mins to fix

                        Method SendTxArgs.setDefaults has 6 return statements (exceeds 4 allowed).
                        Open

                        func (args *SendTxArgs) setDefaults(ctx context.Context, b Backend) error {
                            if args.GasPrice == nil {
                                price, err := b.SuggestPrice(ctx)
                                if err != nil {
                                    return err
                        Severity: Major
                        Found in ethapi/api.go - About 40 mins to fix

                          Function DoEstimateGas has 5 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                          func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.BlockNumberOrHash, gasCap uint64) (hexutil.Uint64, error) {
                          Severity: Minor
                          Found in ethapi/api.go - About 35 mins to fix

                            Method PublicTransactionPoolAPI.GetTransactionByHash has 5 return statements (exceeds 4 allowed).
                            Open

                            func (s *PublicTransactionPoolAPI) GetTransactionByHash(ctx context.Context, hash common.Hash) (*RPCTransaction, error) {
                                // Try to return an already finalized transaction
                                tx, blockNumber, index, err := s.b.GetTransaction(ctx, hash)
                                if err != nil {
                                    return nil, err
                            Severity: Major
                            Found in ethapi/api.go - About 35 mins to fix

                              Method PublicTransactionPoolAPI.GetTransactionReceipt has 5 return statements (exceeds 4 allowed).
                              Open

                              func (s *PublicTransactionPoolAPI) GetTransactionReceipt(ctx context.Context, hash common.Hash) (map[string]interface{}, error) {
                                  tx, blockNumber, index, err := s.b.GetTransaction(ctx, hash)
                                  if tx == nil || err != nil {
                                      return nil, err
                                  }
                              Severity: Major
                              Found in ethapi/api.go - About 35 mins to fix

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

                                func (s *PublicTransactionPoolAPI) GetBlockTransactionCountByHash(ctx context.Context, blockHash common.Hash) *hexutil.Uint {
                                    if block, _ := s.b.BlockByHash(ctx, blockHash); block != nil {
                                        n := hexutil.Uint(len(block.Transactions))
                                        return &n
                                    }
                                Severity: Minor
                                Found in ethapi/api.go and 1 other location - About 45 mins to fix
                                ethapi/api.go on lines 1377..1383

                                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 114.

                                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 (s *PublicTransactionPoolAPI) GetBlockTransactionCountByNumber(ctx context.Context, blockNr rpc.BlockNumber) *hexutil.Uint {
                                    if block, _ := s.b.BlockByNumber(ctx, blockNr); block != nil {
                                        n := hexutil.Uint(len(block.Transactions))
                                        return &n
                                    }
                                Severity: Minor
                                Found in ethapi/api.go and 1 other location - About 45 mins to fix
                                ethapi/api.go on lines 1386..1392

                                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 114.

                                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 (s *PublicBlockChainAPI) GetUncleCountByBlockHash(ctx context.Context, blockHash common.Hash) *hexutil.Uint {
                                    if block, _ := s.b.BlockByHash(ctx, blockHash); block != nil {
                                        n := hexutil.Uint(len(noUncles))
                                        return &n
                                    }
                                Severity: Minor
                                Found in ethapi/api.go and 1 other location - About 40 mins to fix
                                ethapi/api.go on lines 729..735

                                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 110.

                                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 (s *PublicBlockChainAPI) GetUncleCountByBlockNumber(ctx context.Context, blockNr rpc.BlockNumber) *hexutil.Uint {
                                    if block, _ := s.b.BlockByNumber(ctx, blockNr); block != nil {
                                        n := hexutil.Uint(len(noUncles))
                                        return &n
                                    }
                                Severity: Minor
                                Found in ethapi/api.go and 1 other location - About 40 mins to fix
                                ethapi/api.go on lines 738..744

                                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 110.

                                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 (s *PublicTransactionPoolAPI) GetRawTransactionByBlockNumberAndIndex(ctx context.Context, blockNr rpc.BlockNumber, index hexutil.Uint) hexutil.Bytes {
                                    if block, _ := s.b.BlockByNumber(ctx, blockNr); block != nil {
                                        return newRPCRawTransactionFromBlockIndex(block, uint64(index))
                                    }
                                    return nil
                                Severity: Minor
                                Found in ethapi/api.go and 1 other location - About 35 mins to fix
                                ethapi/api.go on lines 1419..1424

                                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 107.

                                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 (s *PublicTransactionPoolAPI) GetRawTransactionByBlockHashAndIndex(ctx context.Context, blockHash common.Hash, index hexutil.Uint) hexutil.Bytes {
                                    if block, _ := s.b.BlockByHash(ctx, blockHash); block != nil {
                                        return newRPCRawTransactionFromBlockIndex(block, uint64(index))
                                    }
                                    return nil
                                Severity: Minor
                                Found in ethapi/api.go and 1 other location - About 35 mins to fix
                                ethapi/api.go on lines 1411..1416

                                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 107.

                                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 (s *PublicTransactionPoolAPI) GetTransactionByBlockHashAndIndex(ctx context.Context, blockHash common.Hash, index hexutil.Uint) *RPCTransaction {
                                    if block, _ := s.b.BlockByHash(ctx, blockHash); block != nil {
                                        return newRPCTransactionFromBlockIndex(block, uint64(index))
                                    }
                                    return nil
                                Severity: Minor
                                Found in ethapi/api.go and 1 other location - About 35 mins to fix
                                ethapi/api.go on lines 1395..1400

                                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 105.

                                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 (s *PublicTransactionPoolAPI) GetTransactionByBlockNumberAndIndex(ctx context.Context, blockNr rpc.BlockNumber, index hexutil.Uint) *RPCTransaction {
                                    if block, _ := s.b.BlockByNumber(ctx, blockNr); block != nil {
                                        return newRPCTransactionFromBlockIndex(block, uint64(index))
                                    }
                                    return nil
                                Severity: Minor
                                Found in ethapi/api.go and 1 other location - About 35 mins to fix
                                ethapi/api.go on lines 1403..1408

                                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 105.

                                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

                                There are no issues that match your filters.

                                Category
                                Status