github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/acm/validator/validator.go (about)

     1  package validator
     2  
     3  import (
     4  	"fmt"
     5  	"math/big"
     6  
     7  	"github.com/hyperledger/burrow/crypto"
     8  
     9  	"github.com/hyperledger/burrow/acm"
    10  )
    11  
    12  func New(publicKey *crypto.PublicKey, power *big.Int) *Validator {
    13  	v := &Validator{
    14  		PublicKey: publicKey,
    15  		Power:     power.Uint64(),
    16  	}
    17  	v.FillAddress()
    18  	return v
    19  }
    20  
    21  func (v *Validator) String() string {
    22  	return fmt.Sprintf("Validator{Address: %v, PublicKey: %v, Power: %v}", v.Address, v.PublicKey, v.Power)
    23  }
    24  
    25  func (v *Validator) FillAddress() {
    26  	if v.Address == nil {
    27  		address := v.PublicKey.GetAddress()
    28  		v.Address = &address
    29  	}
    30  }
    31  
    32  func (v *Validator) BigPower() *big.Int {
    33  	return new(big.Int).SetUint64(v.Power)
    34  }
    35  
    36  func (v *Validator) GetAddress() crypto.Address {
    37  	return *v.Address
    38  }
    39  
    40  func FromAccount(acc *acm.Account, power uint64) *Validator {
    41  	pubKey := acc.GetPublicKey()
    42  	address, _ := crypto.AddressFromBytes(pubKey.TendermintAddress().Bytes())
    43  	return &Validator{
    44  		Address:   &address,
    45  		PublicKey: pubKey,
    46  		Power:     power,
    47  	}
    48  }