0

Here is my code:

#[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)]
#[scale_info(skip_type_params(T))]
    pub struct PayInstallmentOrder<Account, Balance, Time> {
        pub creator: Account,
        pub created_at: Time,
        pub periods_left: u8,
        pub paid: Balance,
        pub nft_id: [u8; 16],
    }
#[pallet::config]
    pub trait Config: frame_system::Config {
        /// Because this pallet emits events, it depends on the runtime's definition of an event.
        type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;

        type Currency: ReservableCurrency<Self::AccountId> + Currency<Self::AccountId>;

        type NFTRandomness: Randomness<Self::Hash, Self::BlockNumber>;

        type WeightInfo: WeightInfo;

        /// Deposit required for per byte.
        #[pallet::constant]
        type DataDepositPerByte: Get<BalanceOf<Self>>;

        type Moment: Parameter
            + Default
            + Scale<Self::BlockNumber, Output = Self::Moment>
            + Copy
            + MaxEncodedLen
            + StaticTypeInfo
            + MaybeSerializeDeserialize
            + Send;

        type Timestamp: Time<Moment = Self::Moment>;
    }
impl<T: Config> Pallet<T> {
    pub fn get_installment_orders() -> Vec<PayInstallmentOrder<T::AccountId, BalanceOf<T>, T::Moment>> {
            OrderByTokenId::<T>::iter_values().collect()
        }
}

// then I do tightly coupling in another pallet to call get_installment_orders() and take the created_at field in orders

I have this error when I try to convert T::Moment to u64 in the other pallet

error[E0277]: the trait bound `u64: From<<T as pallet_nft::Config>::Moment>` is not satisfied
   --> pallets/ocw/src/lib.rs:193:30
    |
193 |                 let y = order.created_at.saturated_into::<u64>();
    |                                          ^^^^^^^^^^^^^^ the trait `From<<T as pallet_nft::Config>::Moment>` is not implemented for `u64`
    |    
= note: required because of the requirements on the impl of `Into<u64>` for `<T as pallet_nft::Config>::Moment`
= note: required because of the requirements on the impl of `std::convert::TryFrom<<T as pallet_nft::Config>::Moment>` for `u64`
= note: required because of the requirements on the impl of `TryInto<u64>` for `<T as pallet_nft::Config>::Moment`
= note: required because of the requirements on the impl of `UniqueSaturatedInto<u64>` for `<T as pallet_nft::Config>::Moment`
note: required by a bound in `saturated_into`

So how to fix this. Thanks for reading!

2
  • 1
    The T::Moment is an associated type and not a concrete type. The Moment type depends on what you give in the runtime pallet_nft config. So it's not a good solution to do saturate_* convert here. Commented Apr 17, 2022 at 9:11
  • Please provide links as reference for the specific types, traits, and source to give context in the form of a stackoverflow.com/help/minimal-reproducible-example
    – Nuke
    Commented Apr 17, 2022 at 18:47

1 Answer 1

2

What if you just define Moment(associated type) in the following way:

type Moment: Parameter
        + Default
        + Scale<Self::BlockNumber, Output = Self::Moment>
        + Copy
        + MaxEncodedLen
        + StaticTypeInfo
        + MaybeSerializeDeserialize
        + Send
        + Into<u64>;

Take care of the bottom line "+ Into".

1
  • It works! Thank you so much!!!
    – marethyu
    Commented Apr 18, 2022 at 13:28

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.