2016-11-21 23:42:42 -05:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2018-03-12 14:43:15 -07:00
|
|
|
"sort"
|
2016-11-21 23:42:42 -05:00
|
|
|
)
|
|
|
|
|
2017-12-01 00:51:20 -05:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2018-08-06 00:18:24 -04:00
|
|
|
// ValidatorUpdates is a list of validators that implements the Sort interface
|
|
|
|
type ValidatorUpdates []ValidatorUpdate
|
2016-11-21 23:42:42 -05:00
|
|
|
|
2018-08-06 00:18:24 -04:00
|
|
|
var _ sort.Interface = (ValidatorUpdates)(nil)
|
2018-03-12 14:43:15 -07:00
|
|
|
|
2018-08-06 00:18:24 -04:00
|
|
|
// All these methods for ValidatorUpdates:
|
2018-03-12 14:43:15 -07:00
|
|
|
// Len, Less and Swap
|
2018-08-06 00:18:24 -04:00
|
|
|
// are for ValidatorUpdates to implement sort.Interface
|
2018-03-12 14:43:15 -07:00
|
|
|
// which will be used by the sort package.
|
|
|
|
// See Issue https://github.com/tendermint/abci/issues/212
|
|
|
|
|
2018-08-06 00:18:24 -04:00
|
|
|
func (v ValidatorUpdates) Len() int {
|
2016-11-21 23:42:42 -05:00
|
|
|
return len(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX: doesn't distinguish same validator with different power
|
2018-08-06 00:18:24 -04:00
|
|
|
func (v ValidatorUpdates) Less(i, j int) bool {
|
2018-05-23 22:20:35 -04:00
|
|
|
return bytes.Compare(v[i].PubKey.Data, v[j].PubKey.Data) <= 0
|
2016-11-21 23:42:42 -05:00
|
|
|
}
|
|
|
|
|
2018-08-06 00:18:24 -04:00
|
|
|
func (v ValidatorUpdates) Swap(i, j int) {
|
2016-11-21 23:42:42 -05:00
|
|
|
v1 := v[i]
|
|
|
|
v[i] = v[j]
|
|
|
|
v[j] = v1
|
|
|
|
}
|