validator-sets pallet event expansion

This commit is contained in:
Luke Parker 2023-10-22 03:28:42 -04:00
parent 52eb68677a
commit a702d65c3d
No known key found for this signature in database

View file

@ -291,13 +291,30 @@ pub mod pallet {
#[pallet::getter(fn keys)]
pub type Keys<T: Config> = StorageMap<_, Twox64Concat, ValidatorSet, KeyPair, OptionQuery>;
// TODO: Expand
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
NewSet { set: ValidatorSet },
KeyGen { set: ValidatorSet, key_pair: KeyPair },
SetRetired { set: ValidatorSet },
NewSet {
set: ValidatorSet,
},
KeyGen {
set: ValidatorSet,
key_pair: KeyPair,
},
AllocationIncreased {
validator: T::AccountId,
network: NetworkId,
amount: Amount,
},
AllocationDecreased {
validator: T::AccountId,
network: NetworkId,
amount: Amount,
delayed_until: Option<Session>,
},
SetRetired {
set: ValidatorSet,
},
}
impl<T: Config> Pallet<T> {
@ -502,6 +519,7 @@ pub mod pallet {
// Increase the allocation now
Self::set_allocation(network, account, Amount(new_allocation));
Self::deposit_event(Event::AllocationIncreased { validator: account, network, amount });
if let Some(was_bft) = was_bft {
if was_bft && (!Self::is_bft(network)) {
@ -582,6 +600,12 @@ pub mod pallet {
Some(Amount(TotalAllocatedStake::<T>::get(network).unwrap_or(Amount(0)).0 - amount.0)),
);
}
Self::deposit_event(Event::AllocationDecreased {
validator: account,
network,
amount,
delayed_until: None,
});
return Ok(true);
}
@ -604,6 +628,13 @@ pub mod pallet {
Some(Amount(existing.0 + amount.0)),
);
Self::deposit_event(Event::AllocationDecreased {
validator: account,
network,
amount,
delayed_until: Some(to_unlock_on),
});
Ok(false)
}