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.

34 lines
836 B

  1. package types
  2. import (
  3. "bytes"
  4. "sort"
  5. )
  6. //------------------------------------------------------------------------------
  7. // ValidatorUpdates is a list of validators that implements the Sort interface
  8. type ValidatorUpdates []ValidatorUpdate
  9. var _ sort.Interface = (ValidatorUpdates)(nil)
  10. // All these methods for ValidatorUpdates:
  11. // Len, Less and Swap
  12. // are for ValidatorUpdates to implement sort.Interface
  13. // which will be used by the sort package.
  14. // See Issue https://github.com/tendermint/abci/issues/212
  15. func (v ValidatorUpdates) Len() int {
  16. return len(v)
  17. }
  18. // XXX: doesn't distinguish same validator with different power
  19. func (v ValidatorUpdates) Less(i, j int) bool {
  20. return bytes.Compare(v[i].PubKey.Data, v[j].PubKey.Data) <= 0
  21. }
  22. func (v ValidatorUpdates) Swap(i, j int) {
  23. v1 := v[i]
  24. v[i] = v[j]
  25. v[j] = v1
  26. }