Add a NewSet event to validator-sets

Updates to the latest serai-dex/substrate due to depending on
10ccaca0eb498a2316bbf627d419b29b1a75933a.
This commit is contained in:
Luke Parker
2023-04-15 00:40:33 -04:00
parent 2e2bc59703
commit 124b994c23
5 changed files with 165 additions and 131 deletions

View File

@@ -64,27 +64,12 @@ pub mod pallet {
pub type VoteCount<T: Config> =
StorageMap<_, Blake2_128Concat, (ValidatorSet, KeyPair), u16, ValueQuery>;
#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
fn build(&self) {
let mut participants = Vec::new();
for participant in self.participants.clone() {
participants.push((participant, self.bond));
}
let participants = BoundedVec::try_from(participants).unwrap();
for (id, network) in self.networks.clone() {
ValidatorSets::<T>::set(
ValidatorSet { session: Session(0), network: id },
Some(ValidatorSetData { bond: self.bond, network, participants: participants.clone() }),
);
}
}
}
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
NewSet {
set: ValidatorSet,
},
Vote {
voter: T::AccountId,
set: ValidatorSet,
@@ -98,6 +83,26 @@ pub mod pallet {
},
}
#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
fn build(&self) {
let mut participants = Vec::new();
for participant in self.participants.clone() {
participants.push((participant, self.bond));
}
let participants = BoundedVec::try_from(participants).unwrap();
for (id, network) in self.networks.clone() {
let set = ValidatorSet { session: Session(0), network: id };
ValidatorSets::<T>::set(
set,
Some(ValidatorSetData { bond: self.bond, network, participants: participants.clone() }),
);
Pallet::<T>::deposit_event(Event::NewSet { set })
}
}
}
#[pallet::error]
pub enum Error<T> {
/// Validator Set doesn't exist.