github.com/PikeEcosystem/tendermint@v0.0.4/state/indexer/sink/psql/backport.go (about) 1 package psql 2 3 // This file adds code to the psql package that is needed for integration with 4 // v0.34, but which is not part of the original implementation. 5 // 6 // In v0.35, ADR 65 was implemented in which the TxIndexer and BlockIndexer 7 // interfaces were merged into a hybrid EventSink interface. The Backport* 8 // types defined here bridge the psql EventSink (which was built in terms of 9 // the v0.35 interface) to the old interfaces. 10 // 11 // We took this narrower approach to backporting to avoid pulling in a much 12 // wider-reaching set of changes in v0.35 that would have broken several of the 13 // v0.34.x APIs. The result is sufficient to work with the node plumbing as it 14 // exists in the v0.34 branch. 15 16 import ( 17 "context" 18 "errors" 19 20 abci "github.com/tendermint/tendermint/abci/types" 21 22 "github.com/PikeEcosystem/tendermint/libs/pubsub/query" 23 "github.com/PikeEcosystem/tendermint/state/txindex" 24 "github.com/PikeEcosystem/tendermint/types" 25 ) 26 27 const ( 28 eventTypeBeginBlock = "begin_block" 29 eventTypeEndBlock = "end_block" 30 ) 31 32 // TxIndexer returns a bridge from es to the Tendermint v0.34 transaction indexer. 33 func (es *EventSink) TxIndexer() BackportTxIndexer { 34 return BackportTxIndexer{psql: es} 35 } 36 37 // BackportTxIndexer implements the txindex.TxIndexer interface by delegating 38 // indexing operations to an underlying PostgreSQL event sink. 39 type BackportTxIndexer struct{ psql *EventSink } 40 41 // AddBatch indexes a batch of transactions in Postgres, as part of TxIndexer. 42 func (b BackportTxIndexer) AddBatch(batch *txindex.Batch) error { 43 return b.psql.IndexTxEvents(batch.Ops) 44 } 45 46 // Index indexes a single transaction result in Postgres, as part of TxIndexer. 47 func (b BackportTxIndexer) Index(txr *abci.TxResult) error { 48 return b.psql.IndexTxEvents([]*abci.TxResult{txr}) 49 } 50 51 // Get is implemented to satisfy the TxIndexer interface, but is not supported 52 // by the psql event sink and reports an error for all inputs. 53 func (BackportTxIndexer) Get([]byte) (*abci.TxResult, error) { 54 return nil, errors.New("the TxIndexer.Get method is not supported") 55 } 56 57 // Search is implemented to satisfy the TxIndexer interface, but it is not 58 // supported by the psql event sink and reports an error for all inputs. 59 func (BackportTxIndexer) Search(context.Context, *query.Query) ([]*abci.TxResult, error) { 60 return nil, errors.New("the TxIndexer.Search method is not supported") 61 } 62 63 // BlockIndexer returns a bridge that implements the Tendermint v0.34 block 64 // indexer interface, using the Postgres event sink as a backing store. 65 func (es *EventSink) BlockIndexer() BackportBlockIndexer { 66 return BackportBlockIndexer{psql: es} 67 } 68 69 // BackportBlockIndexer implements the indexer.BlockIndexer interface by 70 // delegating indexing operations to an underlying PostgreSQL event sink. 71 type BackportBlockIndexer struct{ psql *EventSink } 72 73 // Has is implemented to satisfy the BlockIndexer interface, but it is not 74 // supported by the psql event sink and reports an error for all inputs. 75 func (BackportBlockIndexer) Has(height int64) (bool, error) { 76 return false, errors.New("the BlockIndexer.Has method is not supported") 77 } 78 79 // Index indexes block begin and end events for the specified block. It is 80 // part of the BlockIndexer interface. 81 func (b BackportBlockIndexer) Index(block types.EventDataNewBlockHeader) error { 82 return b.psql.IndexBlockEvents(block) 83 } 84 85 // Search is implemented to satisfy the BlockIndexer interface, but it is not 86 // supported by the psql event sink and reports an error for all inputs. 87 func (BackportBlockIndexer) Search(context.Context, *query.Query) ([]int64, error) { 88 return nil, errors.New("the BlockIndexer.Search method is not supported") 89 }