OSDN Git Service

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