1

I am trying to use one pallet function inside my own pallet... but the argument types have problems...

  #[pallet::config]
    pub trait Config: frame_system::Config + pallet_vesting::Config {
    ...}
  #[pallet::call]
  impl<T: Config> Pallet<T> {
    ...
    pub fn vested_transfer(
        origin: OriginFor<T>,
        target: <T::Lookup as StaticLookup>::Source,
        locked: BalanceOf<T>,
        per_block: BalanceOf<T>,
        starting_block: BlockNumberFor<T>,
    ) -> DispatchResultWithPostInfo {
        let vesting_info = pallet_vesting::VestingInfo::<BalanceOf<T>, BlockNumberFor<T>>::new(
            locked,
            per_block,
            starting_block,
        );
        let is_valid = vesting_info.is_valid();
        ensure!(is_valid, "invalid vesting_info");
        let res = pallet_vesting::Pallet::<T>::vested_transfer(origin, target, vesting_info);

Then the error message for the 3rd argument vesting_info: ... vesting_info... expected pallet_vesting::Config::Currency, found pallet::Config::Currency

Then I tried this to cast the vesting_info type:

vesting_info as pallet_vesting::Config::Currency

... error message: use fully-qualified syntax: <Type as pallet_vesting::Config>::Currency

Then I tried this to fix that the 3rd argument:

vesting_info as <<T as pallet::Config>::Currency as pallet_vesting::Config>::Currency,

... error message: use of undeclared crate or module pallet

Then I tried this to fix that the 3rd argument:

vesting_info as <<T as Config>::Currency as pallet_vesting::Config>::Currency,

... error message: the trait pallet_vesting::Config is not implemented for <T as pallet::Config>::Currency... an as expression can only be used to convert between primitive types or to coerce to a specific trait object

Then I tried this to fix that the 3rd argument:

vesting_info as <<T as Self::Config>::Currency as pallet_vesting::Config>::Currency,

... error message: the name Config is defined multiple times; cannot find associated type Currency in Self::Config

how to use "pallet" or different pallet function argument types ?

1

1 Answer 1

2

The quick and easy way to solve your issue would be to tightly couple your pallet's Config trait with the one of pallet_vesting. This way, you would not have to define the Currency trait in your Config.

type BalanceOf<T> = <<T as pallet_vesting::Config>::Currency as Currency<
        <T as frame_system::Config>::AccountId,
    >>::Balance;

pub trait Config: frame_system::Config + pallet_vesting::Config {
   // your custom associated types
}

Then you can simply call the vested_transfer like so

#[pallet::weight(10_000)]
pub fn your_custom_extrinsic(
    origin: OriginFor<T>,
    target: <T::Lookup as sp_runtime::traits::StaticLookup>::Source,
    vesting_amount: BalanceOf<T>,
    per_block: BalanceOf<T>,
    lock_period: T::BlockNumber,
) -> DispatchResult {
    let vesting_info = pallet_vesting::VestingInfo::<BalanceOf<T>, T::BlockNumber>::new(
        vesting_amount,
        per_block,
        lock_period,
    );
    pallet_vesting::Pallet::<T>::vested_transfer(origin, target, vesting_info)
}

Without tight coupling, it is more complicated. On a high level, you would need to provide a conversion from your pallet::Config::Currency trait to the one of pallet_vesting::Config::Currency.

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.