github.com/noirx94/tendermintmp@v0.0.1/state/txindex/indexer.go (about)

     1  package txindex
     2  
     3  import (
     4  	"context"
     5  	"errors"
     6  
     7  	abci "github.com/tendermint/tendermint/abci/types"
     8  	"github.com/tendermint/tendermint/libs/pubsub/query"
     9  )
    10  
    11  // XXX/TODO: These types should be moved to the indexer package.
    12  
    13  // TxIndexer interface defines methods to index and search transactions.
    14  type TxIndexer interface {
    15  	// AddBatch analyzes, indexes and stores a batch of transactions.
    16  	AddBatch(b *Batch) error
    17  
    18  	// Index analyzes, indexes and stores a single transaction.
    19  	Index(result *abci.TxResult) error
    20  
    21  	// Get returns the transaction specified by hash or nil if the transaction is not indexed
    22  	// or stored.
    23  	Get(hash []byte) (*abci.TxResult, error)
    24  
    25  	// Search allows you to query for transactions.
    26  	Search(ctx context.Context, q *query.Query) ([]*abci.TxResult, error)
    27  }
    28  
    29  // Batch groups together multiple Index operations to be performed at the same time.
    30  // NOTE: Batch is NOT thread-safe and must not be modified after starting its execution.
    31  type Batch struct {
    32  	Ops []*abci.TxResult
    33  }
    34  
    35  // NewBatch creates a new Batch.
    36  func NewBatch(n int64) *Batch {
    37  	return &Batch{
    38  		Ops: make([]*abci.TxResult, n),
    39  	}
    40  }
    41  
    42  // Add or update an entry for the given result.Index.
    43  func (b *Batch) Add(result *abci.TxResult) error {
    44  	b.Ops[result.Index] = result
    45  	return nil
    46  }
    47  
    48  // Size returns the total number of operations inside the batch.
    49  func (b *Batch) Size() int {
    50  	return len(b.Ops)
    51  }
    52  
    53  // ErrorEmptyHash indicates empty hash
    54  var ErrorEmptyHash = errors.New("transaction hash cannot be empty")