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!
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 dosaturate_*
convert here.