github.com/aergoio/aergo@v1.3.1/types/vote.go (about)

     1  package types
     2  
     3  import "math/big"
     4  
     5  const (
     6  	AergoSystem     = "aergo.system"
     7  	AergoName       = "aergo.name"
     8  	AergoEnterprise = "aergo.enterprise"
     9  
    10  	MaxCandidates = 30
    11  
    12  	votePrefixLen  = 2
    13  	VoteBP         = "v1voteBP"
    14  	VoteGasPrice   = "v1voteGasPrice"
    15  	VoteNumBP      = "v1voteNumBP"
    16  	VoteNamePrice  = "v1voteNamePrice"
    17  	VoteMinStaking = "v1voteMinStaking"
    18  )
    19  
    20  //var AllVotes = [...]string{VoteBP, VoteGasPrice, VoteNumBP, VoteNamePrice, VoteMinStaking}
    21  var AllVotes = [...]string{VoteBP}
    22  
    23  func (vl VoteList) Len() int { return len(vl.Votes) }
    24  func (vl VoteList) Less(i, j int) bool {
    25  	result := new(big.Int).SetBytes(vl.Votes[i].Amount).Cmp(new(big.Int).SetBytes(vl.Votes[j].Amount))
    26  	if result == -1 {
    27  		return true
    28  	} else if result == 0 {
    29  		if len(vl.Votes[i].Candidate) == 39 /*peer id length*/ {
    30  			return new(big.Int).SetBytes(vl.Votes[i].Candidate[7:]).Cmp(new(big.Int).SetBytes(vl.Votes[j].Candidate[7:])) > 0
    31  		}
    32  		return new(big.Int).SetBytes(vl.Votes[i].Candidate).Cmp(new(big.Int).SetBytes(vl.Votes[j].Candidate)) > 0
    33  	}
    34  	return false
    35  }
    36  func (vl VoteList) Swap(i, j int) { vl.Votes[i], vl.Votes[j] = vl.Votes[j], vl.Votes[i] }
    37  
    38  func (v Vote) GetAmountBigInt() *big.Int {
    39  	return new(big.Int).SetBytes(v.Amount)
    40  }