Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Add amalgamation traits for NFT CollectionId and ItemId #13514

Conversation

jasl
Copy link
Contributor

@jasl jasl commented Mar 2, 2023

I don't know this is the right direction but I believe this would help when people interacting with NFT traits return values in their own pallets

Basically I'm imitating how fungible traits does

Background:
I'm learning NFTs pallet so I'm building my own pallet that invoking pallet_nfts via nonfungibles_v2 interface,
I tried:

  • Create collections in my pallet and deposit an event
  • Mint items in my pallet

then, I found few problems:

  • create_collection returns collection_id but can't be used in event's payload because the trait `Clone` is not implemented for `<<T as pallet::Config>::NonFungibles as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId
  • mint_into requires ItemConfig but it can be constructed out of pallet_nfts

and a question:

How to construct CollectionId and ItemId from a 3rd pallet?

@jasl jasl force-pushed the amalgamation-traits-for-nft-types branch 2 times, most recently from 04fe4b8 to 9fdc72d Compare March 2, 2023 16:26
@jasl
Copy link
Contributor Author

jasl commented Mar 2, 2023

Add a non topic change (perhaps I need update the title?)

@jasl
Copy link
Contributor Author

jasl commented Mar 2, 2023

@jsidorenko Could you help to take a look? (don't know how to assign reviewers...)

@jsidorenko
Copy link
Contributor

Hey @jasl ,

How to construct CollectionId and ItemId from a 3rd pallet?

Could you pls provide some code snippet or push your code to GH and put a link here?
I don't quite understand the problem you're facing when constructing the ItemId, won't the 1234u32.into() do the magic?

@jasl
Copy link
Contributor Author

jasl commented Mar 3, 2023

Hey @jasl ,

How to construct CollectionId and ItemId from a 3rd pallet?

Could you pls provide some code snippet or push your code to GH and put a link here?

I don't quite understand the problem you're facing when constructing the ItemId, won't the 1234u32.into() do the magic?

I remeber I tried but not work,
I'll re-check and make a public repo for you if not works

@jasl
Copy link
Contributor Author

jasl commented Mar 3, 2023

Hey @jasl ,

How to construct CollectionId and ItemId from a 3rd pallet?

Could you pls provide some code snippet or push your code to GH and put a link here? I don't quite understand the problem you're facing when constructing the ItemId, won't the 1234u32.into() do the magic?

I pushed minimal reproducible code

Background:
I'm trying to build a pallet to work with pallet_nft,
my goal is disable most of pallet_nfts extrinsic and my pallet will help to management collection, minting nfts and update them, users can only own and burn NFTs, rest of other operations are restricted.

version 1: https://github.com/jasl/learn_nft/blob/main/src/lib.rs
my pallet extending pallet_nft (relates to #13517 )

error[E0603]: type alias `NextCollectionId` is private
   --> src/lib.rs:116:18
    |
116 |                 pallet_nfts::NextCollectionId::<T, I>::get().unwrap_or(CollectionIdOf::<T, I>::initial_value());
    |                              ^^^^^^^^^^^^^^^^ private type alias
    |
note: the type alias `NextCollectionId` is defined here
   --> /Users/jasl/.cargo/git/checkouts/substrate-7e08433d4c370a21/2cb4825/frame/nfts/src/lib.rs:59:9
    |
59  | pub use pallet::*;
    |         ^^^^^^^^^

error[E0277]: the trait bound `<T as pallet_nfts::Config<I>>::ItemId: From<u32>` is not satisfied
   --> src/lib.rs:147:10
    |
147 |                 0u32.into(),
    |                      ^^^^ the trait `From<u32>` is not implemented for `<T as pallet_nfts::Config<I>>::ItemId`
    |
    = note: required for `u32` to implement `Into<<T as pallet_nfts::Config<I>>::ItemId>`
help: consider further restricting the associated type
    |
135 |         ) -> DispatchResult where <T as pallet_nfts::Config<I>>::ItemId: From<u32> {
    |                             ++++++++++++++++++++++++++++++++++++++++++++++++++++++

Some errors have detailed explanations: E0277, E0603.
For more information about an error, try `rustc --explain E0277`.

version 2: https://github.com/jasl/learn_nft/blob/another-case/src/lib.rs
use nonfungibles_v2 trait

error[E0277]: the trait bound `<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId: Clone` is not satisfied
  --> src/lib.rs:83:42
   |
83 |         CollectionCreated { who: T::AccountId, collection_id: CollectionIdOf<T> },
   |                                                ^^^^^^^^^^^^^ the trait `Clone` is not implemented for `<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId`

error[E0369]: binary operation `==` cannot be applied to type `&<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId`
  --> src/lib.rs:83:42
   |
83 |         CollectionCreated { who: T::AccountId, collection_id: CollectionIdOf<T> },
   |                                                ^^^^^^^^^^^^^

error[E0277]: `<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId` doesn't implement `std::fmt::Debug`
  --> src/lib.rs:83:42
   |
83 |         CollectionCreated { who: T::AccountId, collection_id: CollectionIdOf<T> },
   |                                                ^^^^^^^^^^^^^ `<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
   |
   = help: the trait `std::fmt::Debug` is not implemented for `<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId`
   = note: required for `&<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId` to implement `std::fmt::Debug`
   = note: required for the cast from `&<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId` to the object type `dyn std::fmt::Debug`

error[E0277]: the trait bound `&<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::ItemId: From<u32>` is not satisfied
   --> src/lib.rs:145:10
    |
145 |                 1u32.into(),
    |                      ^^^^ the trait `From<u32>` is not implemented for `&<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::ItemId`
    |
    = note: required for `u32` to implement `Into<&<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::ItemId>`

error[E0308]: mismatched types
   --> src/lib.rs:144:5
    |
143 |             T::NFTCollection::mint_into(
    |             --------------------------- arguments to this function are incorrect
144 |                 collection,
    |                 ^^^^^^^^^^
    |                 |
    |                 expected `&<... as Inspect<...>>::CollectionId`, found associated type
    |                 help: consider borrowing here: `&collection`
    |
    = note:    expected reference `&<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId`
            found associated type `<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId`
    = help: consider constraining the associated type `<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId` to `&<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId`
    = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
note: associated function defined here
   --> /Users/jasl/.cargo/git/checkouts/substrate-7e08433d4c370a21/2cb4825/frame/support/src/traits/tokens/nonfungibles_v2.rs:224:5
    |
224 |     fn mint_into(
    |        ^^^^^^^^^

error[E0277]: `<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId` doesn't implement `std::fmt::Debug`
   --> src/lib.rs:136:4
    |
136 |             collection: CollectionIdOf<T>
    |             ^^^^^^^^^^ `<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
    |
    = help: the trait `std::fmt::Debug` is not implemented for `<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId`
    = note: required for `&<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId` to implement `std::fmt::Debug`
    = note: required for the cast from `&<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId` to the object type `dyn std::fmt::Debug`

error[E0277]: the trait bound `<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId: Clone` is not satisfied
   --> src/lib.rs:136:4
    |
136 |             collection: CollectionIdOf<T>
    |             ^^^^^^^^^^ the trait `Clone` is not implemented for `<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId`

error[E0369]: binary operation `==` cannot be applied to type `&<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId`
   --> src/lib.rs:136:4
    |
136 |             collection: CollectionIdOf<T>
    |             ^^^^^^^^^^

error[E0277]: the trait bound `<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId: WrapperTypeEncode` is not satisfied
   --> src/lib.rs:136:4
    |
52  | #[frame_support::pallet]
    | ------------------------ required by a bound introduced by this call
...
136 |             collection: CollectionIdOf<T>
    |             ^^^^^^^^^^ the trait `WrapperTypeEncode` is not implemented for `<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId`
    |
    = note: required for `<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId` to implement `parity_scale_codec::Encode`

error[E0277]: the trait bound `<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId: WrapperTypeDecode` is not satisfied
   --> src/lib.rs:93:12
    |
93  |       #[pallet::call]
    |  _______________^
94  | |     impl<T: Config> Pallet<T> {
95  | |         #[pallet::call_index(0)]
96  | |         #[pallet::weight(0)]
...   |
135 | |             origin: OriginFor<T>,
136 | |             collection: CollectionIdOf<T>
    | |_________________________________________^ the trait `WrapperTypeDecode` is not implemented for `<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId`
    |
    = note: required for `<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId` to implement `Decode`

error[E0277]: the trait bound `<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId: TypeInfo` is not satisfied
   --> src/lib.rs:93:12
    |
93  |     #[pallet::call]
    |               ^^^^ the trait `TypeInfo` is not implemented for `<<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId`
    |
note: required for `pallet::Call<T>` to implement `TypeInfo`
   --> src/lib.rs:52:1
    |
52  | #[frame_support::pallet]
    | ^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
...
93  |     #[pallet::call]
    |               ^^^^
note: required by a bound in `meta_type`
   --> /Users/jasl/.cargo/registry/src/github.com-1ecc6299db9ec823/scale-info-2.3.1/src/lib.rs:394:17
    |
394 |     T: ?Sized + TypeInfo + 'static,
    |                 ^^^^^^^^ required by this bound in `meta_type`
    = note: this error originates in the derive macro `frame_support::scale_info::TypeInfo` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider further restricting the associated type
    |
93  |     #[pallet::call where <<T as pallet::Config>::NFTCollection as frame_support::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId: TypeInfo]
    |                    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Some errors have detailed explanations: E0277, E0308, E0369.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `pallet-nft_computing` due to 11 previous errors
warning: build failed, waiting for other jobs to finish...
error[E0277]: the trait bound `<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId: Clone` is not satisfied
  --> src/lib.rs:83:42
   |
83 |         CollectionCreated { who: T::AccountId, collection_id: CollectionIdOf<T> },
   |                                                ^^^^^^^^^^^^^ the trait `Clone` is not implemented for `<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId`

error[E0369]: binary operation `==` cannot be applied to type `&<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId`
  --> src/lib.rs:83:42
   |
83 |         CollectionCreated { who: T::AccountId, collection_id: CollectionIdOf<T> },
   |                                                ^^^^^^^^^^^^^

error[E0277]: `<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId` doesn't implement `std::fmt::Debug`
  --> src/lib.rs:83:42
   |
83 |         CollectionCreated { who: T::AccountId, collection_id: CollectionIdOf<T> },
   |                                                ^^^^^^^^^^^^^ `<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
   |
   = help: the trait `std::fmt::Debug` is not implemented for `<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId`
   = note: required for `&<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId` to implement `std::fmt::Debug`
   = note: required for the cast from `&<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId` to the object type `dyn std::fmt::Debug`

error[E0277]: the trait bound `&<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::ItemId: From<u32>` is not satisfied
   --> src/lib.rs:145:10
    |
145 |                 1u32.into(),
    |                      ^^^^ the trait `From<u32>` is not implemented for `&<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::ItemId`
    |
    = note: required for `u32` to implement `Into<&<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::ItemId>`

error[E0308]: mismatched types
   --> src/lib.rs:144:5
    |
143 |             T::NFTCollection::mint_into(
    |             --------------------------- arguments to this function are incorrect
144 |                 collection,
    |                 ^^^^^^^^^^
    |                 |
    |                 expected `&<... as Inspect<...>>::CollectionId`, found associated type
    |                 help: consider borrowing here: `&collection`
    |
    = note:    expected reference `&<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId`
            found associated type `<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId`
    = help: consider constraining the associated type `<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId` to `&<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId`
    = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
note: associated function defined here
   --> /Users/jasl/.cargo/git/checkouts/substrate-7e08433d4c370a21/2cb4825/frame/support/src/traits/tokens/nonfungibles_v2.rs:224:5
    |
224 |     fn mint_into(
    |        ^^^^^^^^^

error[E0277]: `<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId` doesn't implement `std::fmt::Debug`
   --> src/lib.rs:136:4
    |
136 |             collection: CollectionIdOf<T>
    |             ^^^^^^^^^^ `<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
    |
    = help: the trait `std::fmt::Debug` is not implemented for `<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId`
    = note: required for `&<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId` to implement `std::fmt::Debug`
    = note: required for the cast from `&<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId` to the object type `dyn std::fmt::Debug`

error[E0277]: the trait bound `<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId: Clone` is not satisfied
   --> src/lib.rs:136:4
    |
136 |             collection: CollectionIdOf<T>
    |             ^^^^^^^^^^ the trait `Clone` is not implemented for `<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId`

error[E0369]: binary operation `==` cannot be applied to type `&<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId`
   --> src/lib.rs:136:4
    |
use nonfungibles_v2
136 |             collection: CollectionIdOf<T>
    |             ^^^^^^^^^^

error[E0277]: the trait bound `<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId: WrapperTypeEncode` is not satisfied
   --> src/lib.rs:136:4
    |
52  | #[frame_support::pallet]
    | ------------------------ required by a bound introduced by this call
...
136 |             collection: CollectionIdOf<T>
    |             ^^^^^^^^^^ the trait `WrapperTypeEncode` is not implemented for `<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId`
    |
    = note: required for `<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId` to implement `parity_scale_codec::Encode`

error[E0277]: the trait bound `<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId: WrapperTypeDecode` is not satisfied
   --> src/lib.rs:93:12
    |
93  |       #[pallet::call]
    |  _______________^
94  | |     impl<T: Config> Pallet<T> {
95  | |         #[pallet::call_index(0)]
96  | |         #[pallet::weight(0)]
...   |
135 | |             origin: OriginFor<T>,
136 | |             collection: CollectionIdOf<T>
    | |_________________________________________^ the trait `WrapperTypeDecode` is not implemented for `<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId`
    |
    = note: required for `<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId` to implement `Decode`

error[E0277]: the trait bound `<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId: TypeInfo` is not satisfied
   --> src/lib.rs:93:12
    |
93  |     #[pallet::call]
    |               ^^^^ the trait `TypeInfo` is not implemented for `<<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId`
    |
note: required for `pallet::Call<T>` to implement `TypeInfo`
   --> src/lib.rs:52:1
    |
52  | #[frame_support::pallet]
    | ^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
...
93  |     #[pallet::call]
    |               ^^^^
note: required by a bound in `meta_type`
   --> /Users/jasl/.cargo/registry/src/github.com-1ecc6299db9ec823/scale-info-2.3.1/src/lib.rs:394:17
    |
394 |     T: ?Sized + TypeInfo + 'static,
    |                 ^^^^^^^^ required by this bound in `meta_type`
    = note: this error originates in the derive macro `frame_support::scale_info::TypeInfo` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider further restricting the associated type
    |
93  |     #[pallet::call where <<T as pallet::Config>::NFTCollection as hidden_include::traits::tokens::nonfungibles_v2::Inspect<<T as frame_system::Config>::AccountId>>::CollectionId: TypeInfo]
    |                    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

error: could not compile `pallet-nft_computing` due to 11 previous errors

@dmitry-markin dmitry-markin added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit labels Mar 6, 2023
@jsidorenko
Copy link
Contributor

Hi @jasl, I'm wondering why don't you want to connect the nfts pallet in a loosely coupled way?
Then you will be able to access the mint_into and create_collection methods. In the case of the create_collection(), you won't need to pass the collection id and deal with the NextCollectionId storage item.
You can find the example of connecting the pallet in this PR: #12565

@jsidorenko
Copy link
Contributor

Sorry, I just checked the second example where you used the traits

@jsidorenko
Copy link
Contributor

so, the item_id problem I was able able to solve locally by adding + From<u32> to type's definition in your pallet

@jasl
Copy link
Contributor Author

jasl commented Mar 9, 2023

Hi @jasl, I'm wondering why don't you want to connect the nfts pallet in a loosely coupled way? Then you will be able to access the mint_into and create_collection methods. In the case of the create_collection(), you won't need to pass the collection id and deal with the NextCollectionId storage item. You can find the example of connecting the pallet in this PR: #12565

My another case (https://github.com/jasl/learn_nft/blob/another-case/src/lib.rs) use that way, I'll learn from that PR first.

thank you

@jsidorenko
Copy link
Contributor

@jasl regarding the Copy/Clone issue, I found it doesn't complain if you provide the ItemId/CollectionId via the runtime config: https://github.com/paritytech/substrate/pull/12565/files#diff-d757e0d131cebbebb0176e5448e53b54970ebb64f1c5d7f01537a4e221e587b0R175-R176

@jasl
Copy link
Contributor Author

jasl commented Mar 9, 2023

@jasl regarding the Copy/Clone issue, I found it doesn't complain if you provide the ItemId/CollectionId via the runtime config: https://github.com/paritytech/substrate/pull/12565/files#diff-d757e0d131cebbebb0176e5448e53b54970ebb64f1c5d7f01537a4e221e587b0R175-R176

I'll try this tonight, thank you for metion this.

@jasl jasl force-pushed the amalgamation-traits-for-nft-types branch 2 times, most recently from 6abfae6 to bc6be4b Compare March 9, 2023 11:56
@jasl jasl force-pushed the amalgamation-traits-for-nft-types branch from bc6be4b to b2e3b88 Compare March 9, 2023 12:00
@jasl jasl requested a review from jsidorenko March 9, 2023 12:01
Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need new traits for all of them, we can just use what is already there.

frame/support/src/traits/tokens/nonfungibles_v2.rs Outdated Show resolved Hide resolved
frame/support/src/traits/tokens/nonfungibles_v2.rs Outdated Show resolved Hide resolved
frame/support/src/traits/tokens/nonfungibles_v2.rs Outdated Show resolved Hide resolved
frame/support/src/traits/tokens/nonfungibles_v2.rs Outdated Show resolved Hide resolved
frame/support/src/traits/tokens/nonfungibles_v2.rs Outdated Show resolved Hide resolved
frame/support/src/traits/tokens/nonfungible_v2.rs Outdated Show resolved Hide resolved
frame/support/src/traits/tokens/nonfungible_v2.rs Outdated Show resolved Hide resolved
frame/support/src/traits/tokens/nonfungible_v2.rs Outdated Show resolved Hide resolved
frame/support/src/traits/tokens/misc.rs Outdated Show resolved Hide resolved
@jasl
Copy link
Contributor Author

jasl commented Mar 9, 2023

I'll apply all Basti's suggests then squash them

@jasl
Copy link
Contributor Author

jasl commented Mar 9, 2023

@bkchr I basically follow how AssetId does, do you think AssetId (and maybe Balance) can apply this?

@jasl jasl force-pushed the amalgamation-traits-for-nft-types branch from 14c1b8b to cc29fe6 Compare March 9, 2023 15:41
@jsidorenko
Copy link
Contributor

can you pls run cargo +nightly fmt?

@bkchr
Copy link
Member

bkchr commented Mar 9, 2023

@bkchr I basically follow how AssetId does, do you think AssetId (and maybe Balance) can apply this?

Good questions :P IDK, I would need to check the code.

@bkchr
Copy link
Member

bkchr commented Mar 9, 2023

bot fmt

@command-bot
Copy link

command-bot bot commented Mar 9, 2023

@bkchr https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/2504577 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh". Check out https://gitlab.parity.io/parity/mirrors/substrate/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 34-8516d894-46f0-48e0-8e8f-852b42384013 to cancel this command or bot cancel to cancel all commands in this pull request.

@command-bot
Copy link

command-bot bot commented Mar 9, 2023

@bkchr Command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh" has finished. Result: https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/2504577 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/2504577/artifacts/download.

@jsidorenko
Copy link
Contributor

P. S. @jasl I think we should simplify the collection's creation via traits and remove the config param.
If the advanced (non-default) settings are needed, they should be set via separate methods.
I've opened a PR for this today: #13572

@jasl
Copy link
Contributor Author

jasl commented Mar 9, 2023

#13572

GREAT! Thank you !
After this one merge, I'll refactor my code

@jasl
Copy link
Contributor Author

jasl commented Mar 9, 2023

@bkchr Could you help to merge this?

@jsidorenko
Copy link
Contributor

bot merge

@paritytech-processbot paritytech-processbot bot merged commit 33eee69 into paritytech:master Mar 9, 2023
@jasl jasl deleted the amalgamation-traits-for-nft-types branch March 9, 2023 17:46
ukint-vs pushed a commit to gear-tech/substrate that referenced this pull request Apr 10, 2023
…3514)

* Add amalgamation traits for NFT CollectionId, ItemId, and DestroyWitness

* Apply @bkchr suggests

* ".git/.scripts/commands/fmt/fmt.sh"

---------

Co-authored-by: command-bot <>
nathanwhit pushed a commit to nathanwhit/substrate that referenced this pull request Jul 19, 2023
…3514)

* Add amalgamation traits for NFT CollectionId, ItemId, and DestroyWitness

* Apply @bkchr suggests

* ".git/.scripts/commands/fmt/fmt.sh"

---------

Co-authored-by: command-bot <>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants