bitbucket.org/number571/tendermint@v0.8.14/state/indexer/indexer.go (about) 1 package indexer 2 3 import ( 4 "context" 5 "errors" 6 7 abci "bitbucket.org/number571/tendermint/abci/types" 8 "bitbucket.org/number571/tendermint/libs/pubsub/query" 9 "bitbucket.org/number571/tendermint/types" 10 ) 11 12 // TxIndexer interface defines methods to index and search transactions. 13 type TxIndexer interface { 14 // Index analyzes, indexes and stores transactions. For indexing multiple 15 // Transacions must guarantee the Index of the TxResult is in order. 16 // See Batch struct. 17 Index(results []*abci.TxResult) error 18 19 // Get returns the transaction specified by hash or nil if the transaction is not indexed 20 // or stored. 21 Get(hash []byte) (*abci.TxResult, error) 22 23 // Search allows you to query for transactions. 24 Search(ctx context.Context, q *query.Query) ([]*abci.TxResult, error) 25 } 26 27 // BlockIndexer defines an interface contract for indexing block events. 28 type BlockIndexer interface { 29 // Has returns true if the given height has been indexed. An error is returned 30 // upon database query failure. 31 Has(height int64) (bool, error) 32 33 // Index indexes BeginBlock and EndBlock events for a given block by its height. 34 Index(types.EventDataNewBlockHeader) error 35 36 // Search performs a query for block heights that match a given BeginBlock 37 // and Endblock event search criteria. 38 Search(ctx context.Context, q *query.Query) ([]int64, error) 39 } 40 41 // Batch groups together multiple Index operations to be performed at the same time. 42 // NOTE: Batch is NOT thread-safe and must not be modified after starting its execution. 43 type Batch struct { 44 Ops []*abci.TxResult 45 } 46 47 // NewBatch creates a new Batch. 48 func NewBatch(n int64) *Batch { 49 return &Batch{ 50 Ops: make([]*abci.TxResult, n), 51 } 52 } 53 54 // Add or update an entry for the given result.Index. 55 func (b *Batch) Add(result *abci.TxResult) error { 56 b.Ops[result.Index] = result 57 return nil 58 } 59 60 // Size returns the total number of operations inside the batch. 61 func (b *Batch) Size() int { 62 return len(b.Ops) 63 } 64 65 // ErrorEmptyHash indicates empty hash 66 var ErrorEmptyHash = errors.New("transaction hash cannot be empty")