github.com/prysmaticlabs/prysm@v1.4.4/beacon-chain/state/v1/validator_getters.go (about)

     1  package v1
     2  
     3  import (
     4  	types "github.com/prysmaticlabs/eth2-types"
     5  	ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
     6  )
     7  
     8  // ReadOnlyValidator returns a wrapper that only allows fields from a validator
     9  // to be read, and prevents any modification of internal validator fields.
    10  type ReadOnlyValidator struct {
    11  	validator *ethpb.Validator
    12  }
    13  
    14  // EffectiveBalance returns the effective balance of the
    15  // read only validator.
    16  func (v ReadOnlyValidator) EffectiveBalance() uint64 {
    17  	if v.IsNil() {
    18  		return 0
    19  	}
    20  	return v.validator.EffectiveBalance
    21  }
    22  
    23  // ActivationEligibilityEpoch returns the activation eligibility epoch of the
    24  // read only validator.
    25  func (v ReadOnlyValidator) ActivationEligibilityEpoch() types.Epoch {
    26  	if v.IsNil() {
    27  		return 0
    28  	}
    29  	return v.validator.ActivationEligibilityEpoch
    30  }
    31  
    32  // ActivationEpoch returns the activation epoch of the
    33  // read only validator.
    34  func (v ReadOnlyValidator) ActivationEpoch() types.Epoch {
    35  	if v.IsNil() {
    36  		return 0
    37  	}
    38  	return v.validator.ActivationEpoch
    39  }
    40  
    41  // WithdrawableEpoch returns the withdrawable epoch of the
    42  // read only validator.
    43  func (v ReadOnlyValidator) WithdrawableEpoch() types.Epoch {
    44  	if v.IsNil() {
    45  		return 0
    46  	}
    47  	return v.validator.WithdrawableEpoch
    48  }
    49  
    50  // ExitEpoch returns the exit epoch of the
    51  // read only validator.
    52  func (v ReadOnlyValidator) ExitEpoch() types.Epoch {
    53  	if v.IsNil() {
    54  		return 0
    55  	}
    56  	return v.validator.ExitEpoch
    57  }
    58  
    59  // PublicKey returns the public key of the
    60  // read only validator.
    61  func (v ReadOnlyValidator) PublicKey() [48]byte {
    62  	if v.IsNil() {
    63  		return [48]byte{}
    64  	}
    65  	var pubkey [48]byte
    66  	copy(pubkey[:], v.validator.PublicKey)
    67  	return pubkey
    68  }
    69  
    70  // WithdrawalCredentials returns the withdrawal credentials of the
    71  // read only validator.
    72  func (v ReadOnlyValidator) WithdrawalCredentials() []byte {
    73  	creds := make([]byte, len(v.validator.WithdrawalCredentials))
    74  	copy(creds, v.validator.WithdrawalCredentials)
    75  	return creds
    76  }
    77  
    78  // Slashed returns the read only validator is slashed.
    79  func (v ReadOnlyValidator) Slashed() bool {
    80  	if v.IsNil() {
    81  		return false
    82  	}
    83  	return v.validator.Slashed
    84  }
    85  
    86  // IsNil returns true if the validator is nil.
    87  func (v ReadOnlyValidator) IsNil() bool {
    88  	return v.validator == nil
    89  }