fn slash(&mut self, validator_public_keys: Vec<PublicKey>) -> Result<(), Error> {
        if self.get_caller() != PublicKey::System.to_account_hash() {
            return Err(Error::InvalidCaller);
        }

        let mut burned_amount: U512 = U512::zero();

        for validator_public_key in validator_public_keys {
            // Burn stake, deactivate
            let validator_account_hash = AccountHash::from(&validator_public_key);
            if let Some(mut bid) = self.read_bid(&validator_account_hash)? {
                burned_amount += *bid.staked_amount();
                *bid.staked_amount_mut() = U512::zero();
                bid.deactivate();
                // Reset delegator stakes when deactivating validator bid.
                for delegator in bid.delegators_mut().values_mut() {
                    *delegator.staked_amount_mut() = U512::zero();
                }
                self.write_bid(validator_account_hash, bid)?;
            };

            let validator_account_hash = AccountHash::from(&validator_public_key);
            // Update unbonding entries for given validator
            let unbonding_purses = self.read_withdraw(&validator_account_hash)?;
            if !unbonding_purses.is_empty() {
                burned_amount += unbonding_purses
                    .into_iter()
                    .map(|unbonding_purse| *unbonding_purse.amount())
                    .sum();
                self.write_withdraw(validator_account_hash, Vec::new())?;
            }
        }

        self.reduce_total_supply(burned_amount)?;

        Ok(())
    }
/// Slashes each validator.
///
/// This can be only invoked through a system call.
Slashes each validator.
This can be only invoked through a system call.
Slashes each validator . This can be only invoked through a system call .
fn slash(&mut self, validator_public_keys: Vec<PublicKey>) -> Result<(), Error> {
        if self.get_caller() != PublicKey::System.to_account_hash() {
            return Err(Error::InvalidCaller);
        }
        let mut burned_amount: U512 = U512::zero();
        for validator_public_key in validator_public_keys {
            // Burn stake, deactivate
            let validator_account_hash = AccountHash::from(&validator_public_key);
            if let Some(mut bid) = self.read_bid(&validator_account_hash)? {
                burned_amount += *bid.staked_amount();
                *bid.staked_amount_mut() = U512::zero();
                bid.deactivate();
                // Reset delegator stakes when deactivating validator bid.
                for delegator in bid.delegators_mut().values_mut() {
                    *delegator.staked_amount_mut() = U512::zero();
                }
                self.write_bid(validator_account_hash, bid)?;
            };
            let validator_account_hash = AccountHash::from(&validator_public_key);
            // Update unbonding entries for given validator
            let unbonding_purses = self.read_withdraw(&validator_account_hash)?;
            if !unbonding_purses.is_empty() {
                burned_amount += unbonding_purses
                    .into_iter()
                    .map(|unbonding_purse| *unbonding_purse.amount())
                    .sum();
                self.write_withdraw(validator_account_hash, Vec::new())?;
            }
        }
        self.reduce_total_supply(burned_amount)?;
        Ok(())
    }
fn slash ( & mut self , validator_public_keys : Vec < PublicKey > ) -> Result < ( ) , Error > { if self . get_caller ( ) != PublicKey :: System . to_account_hash ( ) { return Err ( Error :: InvalidCaller ) ; } let mut burned_amount : U512 = U512 :: zero ( ) ; for validator_public_key in validator_public_keys { // Burn stake, deactivate let validator_account_hash = AccountHash :: from ( & validator_public_key ) ; if let Some ( mut bid ) = self . read_bid ( & validator_account_hash ) ? { burned_amount += * bid . staked_amount ( ) ; * bid . staked_amount_mut ( ) = U512 :: zero ( ) ; bid . deactivate ( ) ; // Reset delegator stakes when deactivating validator bid. for delegator in bid . delegators_mut ( ) . values_mut ( ) { * delegator . staked_amount_mut ( ) = U512 :: zero ( ) ; } self . write_bid ( validator_account_hash , bid ) ? ; } ; let validator_account_hash = AccountHash :: from ( & validator_public_key ) ; // Update unbonding entries for given validator let unbonding_purses = self . read_withdraw ( & validator_account_hash ) ? ; if ! unbonding_purses . is_empty ( ) { burned_amount += unbonding_purses . into_iter ( ) . map ( | unbonding_purse | * unbonding_purse . amount ( ) ) . sum ( ) ; self . write_withdraw ( validator_account_hash , Vec :: new ( ) ) ? ; } } self . reduce_total_supply ( burned_amount ) ? ; Ok ( ( ) ) }
Slashes each validator.
Slashes each validator .
&mut self
validator_public_keys
Vec<PublicKey>
&mut self
validator_public_keys
Vec<PublicKey>