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.

47 lines
882 B

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