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.

43 lines
786 B

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