github.com/line/ostracon@v1.0.10-0.20230328032236-7f20145f065d/abci/types/util.go (about)

     1  package types
     2  
     3  import (
     4  	"sort"
     5  
     6  	"github.com/tendermint/tendermint/abci/types"
     7  )
     8  
     9  //------------------------------------------------------------------------------
    10  
    11  // ValidatorUpdates is a list of validators that implements the Sort interface
    12  type ValidatorUpdates []types.ValidatorUpdate
    13  
    14  var _ sort.Interface = (ValidatorUpdates)(nil)
    15  
    16  // All these methods for ValidatorUpdates:
    17  //    Len, Less and Swap
    18  // are for ValidatorUpdates to implement sort.Interface
    19  // which will be used by the sort package.
    20  // See Issue https://github.com/tendermint/abci/issues/212
    21  
    22  func (v ValidatorUpdates) Len() int {
    23  	return len(v)
    24  }
    25  
    26  // XXX: doesn't distinguish same validator with different power
    27  func (v ValidatorUpdates) Less(i, j int) bool {
    28  	return v[i].PubKey.Compare(v[j].PubKey) <= 0
    29  }
    30  
    31  func (v ValidatorUpdates) Swap(i, j int) {
    32  	v[i], v[j] = v[j], v[i]
    33  }