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.

32 lines
845 B

  1. package indexer
  2. import "github.com/tendermint/tendermint/types"
  3. // A Batch groups together multiple Index operations you would like performed
  4. // at the same time. The Batch structure is NOT thread-safe. You should only
  5. // perform operations on a batch from a single thread at a time. Once batch
  6. // execution has started, you may not modify it.
  7. type Batch struct {
  8. Ops map[string]types.TxResult
  9. }
  10. // NewBatch creates a new Batch.
  11. func NewBatch() *Batch {
  12. return &Batch{
  13. Ops: make(map[string]types.TxResult),
  14. }
  15. }
  16. // Index adds or updates entry for the given hash.
  17. func (b *Batch) Index(hash []byte, result types.TxResult) error {
  18. if len(hash) == 0 {
  19. return ErrorEmptyHash
  20. }
  21. b.Ops[string(hash)] = result
  22. return nil
  23. }
  24. // Size returns the total number of operations inside the batch.
  25. func (b *Batch) Size() int {
  26. return len(b.Ops)
  27. }