Tightly Coupling pallet error: ambiguous associated type `Currency` in bounds of `T`

Viewed 126

I have following config file, I added schelling game pallet as tightly coupling pallet:

 use frame_support::{
    traits::{Currency, ExistenceRequirement, Get, ReservableCurrency, WithdrawReasons},
};    
#[pallet::config]
pub trait Config: frame_system::Config + schelling_game::Config{
    type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;

    type Currency: ReservableCurrency<Self::AccountId>;

    type RandomnessSource: Randomness<Self::Hash, Self::BlockNumber>;
}

I have following code in the function:

#[pallet::weight(10_000 + T::DbWeight::get().reads_writes(2,2))]
    pub fn add_profile_fund(origin: OriginFor<T>, citizenid: u128) -> DispatchResult {
        let who = ensure_signed(origin)?;       
        let deposit = <RegistrationFee<T>>::get();

        let imb = T::Currency::withdraw(
            &who,
            deposit,
            WithdrawReasons::TRANSFER,
            ExistenceRequirement::AllowDeath,
        )?;

It gives error:

ambiguous associated type Currency in bounds of T

ambiguous associated type Currency

note: associated type T could derive from schelling_game::Config help: use fully qualified syntax to disambiguate: <T as pallet::Config>::Currency

When I add

let imb = <T as frame_system::Config>::Currency::withdraw()

It gives error:
cannot find associated type Currency in trait frame_system::Config

not found in frame_system::Config

Edit:
The error is because I have used currency trait in both the pallet. How can I use currency trait in both pallets?

1 Answers

I think the error/warning message has given you the answer you need . Could you try:

let imb = <T as pallet::Config>::Currency::withdraw();

and see if this works?

What I am not sure how is Currency ambiguous, as the associated type is only defined in your pallet and not in System Pallet? But well, if the compiler tells us to do so, let's not argue with it for now.


Update:

oh, I think the pallet module exports the Config trait out and the trait is now accessible as schelling_game::Config also as mentioned in the error message. So there are two names now - pallet::Config and schelling_game::Config and rust compiler treats them as ambiguous, but they are the same thing really.

Related