1

I was making a new event in the function nominate of Staking pallet which is going to show when the nominator is going to be added. But i facing one issue

#[pallet::call_index(5)]
    #[pallet::weight(T::WeightInfo::nominate(targets.len() as u32))]
    pub fn nominate(
        origin: OriginFor<T>,
        targets: Vec<AccountIdLookupOf<T>>,
    ) -> DispatchResult {
        let controller = ensure_signed(origin)?;

        let ledger = Self::ledger(&controller).ok_or(Error::<T>::NotController)?;
        ensure!(ledger.active >= MinNominatorBond::<T>::get(), Error::<T>::InsufficientBond);
        let stash = &ledger.stash;

        // Only check limits if they are not already a nominator.
        if !Nominators::<T>::contains_key(stash) {
            // If this error is reached, we need to adjust the `MinNominatorBond` and start
            // calling `chill_other`. Until then, we explicitly block new nominators to protect
            // the runtime.
            if let Some(max_nominators) = MaxNominatorsCount::<T>::get() {
                ensure!(
                    Nominators::<T>::count() < max_nominators,
                    Error::<T>::TooManyNominators
                );
            }
        }

        ensure!(!targets.is_empty(), Error::<T>::EmptyTargets);
        ensure!(targets.len() <= T::MaxNominations::get() as usize, Error::<T>::TooManyTargets);

        let old = Nominators::<T>::get(stash).map_or_else(Vec::new, |x| x.targets.into_inner());

        let targets: BoundedVec<_, _> = targets
            .into_iter()
            .map(|t| T::Lookup::lookup(t).map_err(DispatchError::from))
            .map(|n| {
                n.and_then(|n| {
                    if old.contains(&n) || !Validators::<T>::get(&n).blocked {
                        Ok(n)
                    } else {
                        Err(Error::<T>::BadTarget.into())
                    }
                })
            })
            .collect::<Result<Vec<_>, _>>()?
            .try_into()
            .map_err(|_| Error::<T>::TooManyNominators)?;

        let nominations = Nominations {
            targets,
            // Initial nominations are considered submitted at era 0. See `Nominations` doc.
            submitted_in: Self::current_era().unwrap_or(0),
            suppressed: false,
        };

        //let put = &nominations.put;

        Self::do_remove_validator(stash);
        Self::do_add_nominator(stash, nominations);
        Self::deposit_event(Event::<T>::NominatorSet { stash: ledger.stash, nominations });

        Ok(())
    }

and in Event

#[pallet::event]
#[pallet::generate_deposit(pub(crate) fn deposit_event)]
pub enum Event<T: Config> {
  NominatorSet{stash: T::AccountId, nominations: Nominations<T>},
}

and it is this error enter image description here

1 Answer 1

1

You need to change Clone in derive above Nominations to CloneNoBound. The difference between Clone and CloneNoBound is the handling of T. In case of Clone it adds the bound Clone to T. CloneNoBound doesn't add this bound. The bound to Clone is wrong you don't need that T implements Clone, you only require that some of the associated types implement Clone.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.