Skip to content

Commit

Permalink
working
Browse files Browse the repository at this point in the history
  • Loading branch information
coachchucksol committed Nov 14, 2024
1 parent 40e9381 commit 84d9252
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions core/src/epoch_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,23 +423,26 @@ impl OperatorSnapshot {
self.vault_operator_delegations_registered() == self.vault_operator_delegation_count()
}

pub fn contains_vault_index(&self, vault_index: u64) -> bool {
self.vault_operator_votes
.iter()
.any(|v| v.vault_index() == vault_index)
}

pub fn insert_vault_operator_votes(
&mut self,
vault: Pubkey,
vault_index: u64,
votes: u128,
) -> Result<(), TipRouterError> {
// Check for duplicate vaults
for vault_operator_vote in self.vault_operator_votes.iter_mut() {
if vault_operator_vote.vault_index() == vault_index {
return Err(TipRouterError::DuplicateVaultOperatorDelegation);
}
}

if self.vault_operator_delegations_registered() > Self::MAX_VAULT_OPERATOR_VOTES as u64 {
return Err(TipRouterError::TooManyVaultOperatorDelegations);
}

if self.contains_vault_index(vault_index) {
return Err(TipRouterError::DuplicateVaultOperatorDelegation);
}

self.vault_operator_votes[self.vault_operator_delegations_registered() as usize] =
VaultOperatorVotes::new(vault, votes, vault_index);

Expand Down

0 comments on commit 84d9252

Please sign in to comment.