github.com/unicornultrafoundation/go-u2u@v1.0.0-rc1.0.20240205080301-e74a83d3fadc/u2u/genesis/gpos/validators.go (about)

     1  package gpos
     2  
     3  import (
     4  	"github.com/unicornultrafoundation/go-u2u/common"
     5  	"github.com/unicornultrafoundation/go-u2u/native"
     6  
     7  	"github.com/unicornultrafoundation/go-helios/native/idx"
     8  	"github.com/unicornultrafoundation/go-u2u/native/validatorpk"
     9  )
    10  
    11  type (
    12  	// Validator is a helper structure to define genesis validators
    13  	Validator struct {
    14  		ID               idx.ValidatorID
    15  		Address          common.Address
    16  		PubKey           validatorpk.PubKey
    17  		CreationTime     native.Timestamp
    18  		CreationEpoch    idx.Epoch
    19  		DeactivatedTime  native.Timestamp
    20  		DeactivatedEpoch idx.Epoch
    21  		Status           uint64
    22  	}
    23  
    24  	Validators []Validator
    25  )
    26  
    27  // Map converts Validators to map
    28  func (gv Validators) Map() map[idx.ValidatorID]Validator {
    29  	validators := map[idx.ValidatorID]Validator{}
    30  	for _, val := range gv {
    31  		validators[val.ID] = val
    32  	}
    33  	return validators
    34  }
    35  
    36  // PubKeys returns not sorted genesis pub keys
    37  func (gv Validators) PubKeys() []validatorpk.PubKey {
    38  	res := make([]validatorpk.PubKey, 0, len(gv))
    39  	for _, v := range gv {
    40  		res = append(res, v.PubKey)
    41  	}
    42  	return res
    43  }
    44  
    45  // Addresses returns not sorted genesis addresses
    46  func (gv Validators) Addresses() []common.Address {
    47  	res := make([]common.Address, 0, len(gv))
    48  	for _, v := range gv {
    49  		res = append(res, v.Address)
    50  	}
    51  	return res
    52  }