0

I'm using fresh node template and trying to implement below code:

#[pallet::storage]
    pub type Author<T: Config> = StorageValue<_, sr25519::Public, OptionQuery>;
pub struct DataProvider;

impl<T: Config> DataProvider {
    fn details() -> T::AccountId {
        Author::<T>::get().map(|a| a.into())
    }
}

But getting this error:

impl<T: Config> DataProvider {
     ^ unconstrained type parameter

How to solve this issue?

1 Answer 1

1

You have to constrain the struct with generic phantom type.

pub struct DataProvider<T>(sp_std::marker::PhantomData<T>);

impl<T: Config> DataProvider<T> {
    fn details() -> T::AccountId {
        Author::<T>::get().map(|a| a.into())
    }
}

1
  • Yeah worked!, But why we need to put phantom type? and why we get unconstrained error? Jan 17 at 13:54

Your Answer

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

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