You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.6 KiB

  1. package kv
  2. import (
  3. "context"
  4. abci "github.com/tendermint/tendermint/abci/types"
  5. "github.com/tendermint/tendermint/libs/pubsub/query"
  6. "github.com/tendermint/tendermint/state/indexer"
  7. kvb "github.com/tendermint/tendermint/state/indexer/block/kv"
  8. kvt "github.com/tendermint/tendermint/state/indexer/tx/kv"
  9. "github.com/tendermint/tendermint/types"
  10. dbm "github.com/tendermint/tm-db"
  11. )
  12. var _ indexer.EventSink = (*EventSink)(nil)
  13. // The EventSink is an aggregator for redirecting the call path of the tx/block kvIndexer.
  14. // For the implementation details please see the kv.go in the indexer/block and indexer/tx folder.
  15. type EventSink struct {
  16. txi *kvt.TxIndex
  17. bi *kvb.BlockerIndexer
  18. }
  19. func NewEventSink(store dbm.DB) indexer.EventSink {
  20. return &EventSink{
  21. txi: kvt.NewTxIndex(store),
  22. bi: kvb.New(store),
  23. }
  24. }
  25. func (kves *EventSink) Type() indexer.EventSinkType {
  26. return indexer.KV
  27. }
  28. func (kves *EventSink) IndexBlockEvents(bh types.EventDataNewBlockHeader) error {
  29. return kves.bi.Index(bh)
  30. }
  31. func (kves *EventSink) IndexTxEvents(results []*abci.TxResult) error {
  32. return kves.txi.Index(results)
  33. }
  34. func (kves *EventSink) SearchBlockEvents(ctx context.Context, q *query.Query) ([]int64, error) {
  35. return kves.bi.Search(ctx, q)
  36. }
  37. func (kves *EventSink) SearchTxEvents(ctx context.Context, q *query.Query) ([]*abci.TxResult, error) {
  38. return kves.txi.Search(ctx, q)
  39. }
  40. func (kves *EventSink) GetTxByHash(hash []byte) (*abci.TxResult, error) {
  41. return kves.txi.Get(hash)
  42. }
  43. func (kves *EventSink) HasBlock(h int64) (bool, error) {
  44. return kves.bi.Has(h)
  45. }
  46. func (kves *EventSink) Stop() error {
  47. return nil
  48. }