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.

41 lines
747 B

  1. package types
  2. import (
  3. "bytes"
  4. "github.com/tendermint/go-wire"
  5. )
  6. // validators implements sort
  7. type Validators []*Validator
  8. func (v Validators) Len() int {
  9. return len(v)
  10. }
  11. // XXX: doesn't distinguish same validator with different power
  12. func (v Validators) Less(i, j int) bool {
  13. return bytes.Compare(v[i].PubKey, v[j].PubKey) <= 0
  14. }
  15. func (v Validators) Swap(i, j int) {
  16. v1 := v[i]
  17. v[i] = v[j]
  18. v[j] = v1
  19. }
  20. //-------------------------------------
  21. type validatorPretty struct {
  22. PubKey []byte `json:"pub_key"`
  23. Power uint64 `json:"power"`
  24. }
  25. func ValidatorsString(vs Validators) string {
  26. s := make([]validatorPretty, len(vs))
  27. for i, v := range vs {
  28. s[i] = validatorPretty{v.PubKey, v.Power}
  29. }
  30. return string(wire.JSONBytes(s))
  31. }