func (s *State) ProcessDeposit(pubkey *bls.PublicKey, amount uint64, proofOfPossession [48]byte, withdrawalCredentials chainhash.Hash, skipValidation bool, c *config.Config) (uint32, error) {
	if !skipValidation {
		sig, err := bls.DeserializeSignature(proofOfPossession)
		if err != nil {
			return 0, err
		}

		sigValid, err := s.ValidateProofOfPossession(pubkey, *sig, withdrawalCredentials)
		if err != nil {
			return 0, err
		}
		if !sigValid {
			return 0, errors.New("invalid deposit signature")
		}
	}

	pubSer := pubkey.Serialize()

	validatorAlreadyRegisteredIndex := -1

	for i := range s.ValidatorRegistry {
		if bytes.Equal(s.ValidatorRegistry[i].Pubkey[:], pubSer[:]) {
			validatorAlreadyRegisteredIndex = i
		}
	}

	var index int

	if validatorAlreadyRegisteredIndex == -1 {
		validator := Validator{
			Pubkey:                  pubSer,
			WithdrawalCredentials:   withdrawalCredentials,
			Status:                  PendingActivation,
			LatestStatusChangeSlot:  s.Slot,
			ExitCount:               0,
			LastPoCChangeSlot:       0,
			SecondLastPoCChangeSlot: 0,
		}

		index = MinEmptyValidator(s.ValidatorRegistry, s.ValidatorBalances, c, s.Slot)
		if index == -1 {
			s.ValidatorRegistry = append(s.ValidatorRegistry, validator)
			s.ValidatorBalances = append(s.ValidatorBalances, amount)
			index = len(s.ValidatorRegistry) - 1
		} else {
			s.ValidatorRegistry[index] = validator
			s.ValidatorBalances[index] = amount
		}
	} else {
		index = validatorAlreadyRegisteredIndex
		if !bytes.Equal(s.ValidatorRegistry[index].WithdrawalCredentials[:], withdrawalCredentials[:]) {
			return 0, errors.New("withdrawal credentials do not match")
		}

		s.ValidatorBalances[index] += amount
	}
	return uint32(index), nil
}
// ProcessDeposit processes a deposit with the context of the current state.
ProcessDeposit processes a deposit with the context of the current state.
// ProcessDeposit processes a deposit with the context of the current state .
func (s *State) ProcessDeposit(pubkey *bls.PublicKey, amount uint64, proofOfPossession [48]byte, withdrawalCredentials chainhash.Hash, skipValidation bool, c *config.Config) (uint32, error) {
	if !skipValidation {
		sig, err := bls.DeserializeSignature(proofOfPossession)
		if err != nil {
			return 0, err
		}
		sigValid, err := s.ValidateProofOfPossession(pubkey, *sig, withdrawalCredentials)
		if err != nil {
			return 0, err
		}
		if !sigValid {
			return 0, errors.New("invalid deposit signature")
		}
	}
	pubSer := pubkey.Serialize()
	validatorAlreadyRegisteredIndex := -1
	for i := range s.ValidatorRegistry {
		if bytes.Equal(s.ValidatorRegistry[i].Pubkey[:], pubSer[:]) {
			validatorAlreadyRegisteredIndex = i
		}
	}
	var index int
	if validatorAlreadyRegisteredIndex == -1 {
		validator := Validator{
			Pubkey:                  pubSer,
			WithdrawalCredentials:   withdrawalCredentials,
			Status:                  PendingActivation,
			LatestStatusChangeSlot:  s.Slot,
			ExitCount:               0,
			LastPoCChangeSlot:       0,
			SecondLastPoCChangeSlot: 0,
		}
		index = MinEmptyValidator(s.ValidatorRegistry, s.ValidatorBalances, c, s.Slot)
		if index == -1 {
			s.ValidatorRegistry = append(s.ValidatorRegistry, validator)
			s.ValidatorBalances = append(s.ValidatorBalances, amount)
			index = len(s.ValidatorRegistry) - 1
		} else {
			s.ValidatorRegistry[index] = validator
			s.ValidatorBalances[index] = amount
		}
	} else {
		index = validatorAlreadyRegisteredIndex
		if !bytes.Equal(s.ValidatorRegistry[index].WithdrawalCredentials[:], withdrawalCredentials[:]) {
			return 0, errors.New("withdrawal credentials do not match")
		}
		s.ValidatorBalances[index] += amount
	}
	return uint32(index), nil
}
func ( s * State ) ProcessDeposit ( pubkey * bls . PublicKey , amount uint64 , proofOfPossession [ 48 ] byte , withdrawalCredentials chainhash . Hash , skipValidation bool , c * config . Config ) ( uint32 , error ) { if ! skipValidation { sig , err := bls . DeserializeSignature ( proofOfPossession ) if err != nil { return 0 , err } sigValid , err := s . ValidateProofOfPossession ( pubkey , * sig , withdrawalCredentials ) if err != nil { return 0 , err } if ! sigValid { return 0 , errors . New ( " " ) } } pubSer := pubkey . Serialize ( ) validatorAlreadyRegisteredIndex := - 1 for i := range s . ValidatorRegistry { if bytes . Equal ( s . ValidatorRegistry [ i ] . Pubkey [ : ] , pubSer [ : ] ) { validatorAlreadyRegisteredIndex = i } } var index int if validatorAlreadyRegisteredIndex == - 1 { validator := Validator { Pubkey : pubSer , WithdrawalCredentials : withdrawalCredentials , Status : PendingActivation , LatestStatusChangeSlot : s . Slot , ExitCount : 0 , LastPoCChangeSlot : 0 , SecondLastPoCChangeSlot : 0 , } index = MinEmptyValidator ( s . ValidatorRegistry , s . ValidatorBalances , c , s . Slot ) if index == - 1 { s . ValidatorRegistry = append ( s . ValidatorRegistry , validator ) s . ValidatorBalances = append ( s . ValidatorBalances , amount ) index = len ( s . ValidatorRegistry ) - 1 } else { s . ValidatorRegistry [ index ] = validator s . ValidatorBalances [ index ] = amount } } else { index = validatorAlreadyRegisteredIndex if ! bytes . Equal ( s . ValidatorRegistry [ index ] . WithdrawalCredentials [ : ] , withdrawalCredentials [ : ] ) { return 0 , errors . New ( " " ) } s . ValidatorBalances [ index ] += amount } return uint32 ( index ) , nil }
ProcessDeposit processes a deposit with the context of the current state.
ProcessDeposit processes a deposit with the context of the current state .