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.

62 lines
1.6 KiB

cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
  1. package kv
  2. import (
  3. "context"
  4. dbm "github.com/tendermint/tm-db"
  5. abci "github.com/tendermint/tendermint/abci/types"
  6. "github.com/tendermint/tendermint/internal/state/indexer"
  7. kvb "github.com/tendermint/tendermint/internal/state/indexer/block/kv"
  8. kvt "github.com/tendermint/tendermint/internal/state/indexer/tx/kv"
  9. "github.com/tendermint/tendermint/libs/pubsub/query"
  10. "github.com/tendermint/tendermint/types"
  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. }