synapsecns/sanguine

View on GitHub
services/scribe/service/indexer/indexer.go

Summary

Maintainability
D
2 days
Test Coverage

Method Indexer.Index has a Cognitive Complexity of 47 (exceeds 20 allowed). Consider refactoring.
Open

func (x *Indexer) Index(parentCtx context.Context, startHeight uint64, endHeight uint64) (err error) {
    ctx, span := x.handler.Tracer().Start(parentCtx, "contract.Backfill", trace.WithAttributes(
        attribute.Int("chain", int(x.indexerConfig.ChainID)),
        attribute.String("address", x.addressesToString(x.indexerConfig.Addresses)),
        attribute.Int("start", int(startHeight)),
Severity: Minor
Found in services/scribe/service/indexer/indexer.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

Method Indexer.store has a Cognitive Complexity of 43 (exceeds 20 allowed). Consider refactoring.
Open

func (x *Indexer) store(parentCtx context.Context, log types.Log) (err error) {
    ctx, span := x.handler.Tracer().Start(parentCtx, "store", trace.WithAttributes(
        attribute.String("contract", x.addressesToString(x.indexerConfig.Addresses)),
        attribute.String("tx", log.TxHash.Hex()),
        attribute.String("block", fmt.Sprintf("%d", log.BlockNumber)),
Severity: Minor
Found in services/scribe/service/indexer/indexer.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

Method Indexer.store has 98 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (x *Indexer) store(parentCtx context.Context, log types.Log) (err error) {
    ctx, span := x.handler.Tracer().Start(parentCtx, "store", trace.WithAttributes(
        attribute.String("contract", x.addressesToString(x.indexerConfig.Addresses)),
        attribute.String("tx", log.TxHash.Hex()),
        attribute.String("block", fmt.Sprintf("%d", log.BlockNumber)),
Severity: Major
Found in services/scribe/service/indexer/indexer.go - About 2 hrs to fix

    Method Indexer.Index has 81 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (x *Indexer) Index(parentCtx context.Context, startHeight uint64, endHeight uint64) (err error) {
        ctx, span := x.handler.Tracer().Start(parentCtx, "contract.Backfill", trace.WithAttributes(
            attribute.Int("chain", int(x.indexerConfig.ChainID)),
            attribute.String("address", x.addressesToString(x.indexerConfig.Addresses)),
            attribute.Int("start", int(startHeight)),
    Severity: Major
    Found in services/scribe/service/indexer/indexer.go - About 2 hrs to fix

      Method Indexer.store has 14 return statements (exceeds 4 allowed).
      Open

      func (x *Indexer) store(parentCtx context.Context, log types.Log) (err error) {
          ctx, span := x.handler.Tracer().Start(parentCtx, "store", trace.WithAttributes(
              attribute.String("contract", x.addressesToString(x.indexerConfig.Addresses)),
              attribute.String("tx", log.TxHash.Hex()),
              attribute.String("block", fmt.Sprintf("%d", log.BlockNumber)),
      Severity: Major
      Found in services/scribe/service/indexer/indexer.go - About 1 hr to fix

        Method Indexer.Index has 12 return statements (exceeds 4 allowed).
        Open

        func (x *Indexer) Index(parentCtx context.Context, startHeight uint64, endHeight uint64) (err error) {
            ctx, span := x.handler.Tracer().Start(parentCtx, "contract.Backfill", trace.WithAttributes(
                attribute.Int("chain", int(x.indexerConfig.ChainID)),
                attribute.String("address", x.addressesToString(x.indexerConfig.Addresses)),
                attribute.Int("start", int(startHeight)),
        Severity: Major
        Found in services/scribe/service/indexer/indexer.go - About 1 hr to fix

          Method Indexer.fetchEventData has 51 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (x *Indexer) fetchEventData(parentCtx context.Context, txhash common.Hash, blockNumber uint64) (tx *txData, err error) {
              ctx, span := x.handler.Tracer().Start(parentCtx, "fetchEventData", trace.WithAttributes(
                  attribute.String("tx", txhash.Hex()),
                  attribute.String("block", fmt.Sprintf("%d", blockNumber)),
              ))
          Severity: Minor
          Found in services/scribe/service/indexer/indexer.go - About 1 hr to fix

            Method Indexer.fetchEventData has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
            Open

            func (x *Indexer) fetchEventData(parentCtx context.Context, txhash common.Hash, blockNumber uint64) (tx *txData, err error) {
                ctx, span := x.handler.Tracer().Start(parentCtx, "fetchEventData", trace.WithAttributes(
                    attribute.String("tx", txhash.Hex()),
                    attribute.String("block", fmt.Sprintf("%d", blockNumber)),
                ))
            Severity: Minor
            Found in services/scribe/service/indexer/indexer.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 NewIndexer has 7 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            func NewIndexer(chainConfig config.ChainConfig, addresses []common.Address, eventDB db.EventDB, client []backend.ScribeBackend, handler metrics.Handler, blockMeter otelMetrics.Int64Histogram, toHead bool) (*Indexer, error) {
            Severity: Major
            Found in services/scribe/service/indexer/indexer.go - About 50 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                      if err != nil {
                                          logger.ReportIndexerError(err, x.indexerConfig, logger.StoreError)
                                          return fmt.Errorf("could not store last indexed: %w", err)
                                      }
              Severity: Major
              Found in services/scribe/service/indexer/indexer.go - About 45 mins to fix

                Method Indexer.fetchEventData has 6 return statements (exceeds 4 allowed).
                Open

                func (x *Indexer) fetchEventData(parentCtx context.Context, txhash common.Hash, blockNumber uint64) (tx *txData, err error) {
                    ctx, span := x.handler.Tracer().Start(parentCtx, "fetchEventData", trace.WithAttributes(
                        attribute.String("tx", txhash.Hex()),
                        attribute.String("block", fmt.Sprintf("%d", blockNumber)),
                    ))
                Severity: Major
                Found in services/scribe/service/indexer/indexer.go - About 40 mins to fix

                  There are no issues that match your filters.

                  Category
                  Status