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