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)),
- Read upRead up
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)),
- Read upRead up
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)),
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)),
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)),
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)),
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)),
))
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)),
))
- Read upRead up
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) {
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)
}
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)),
))