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