metaplex-foundation / mpl-core

https://mpl-core-js-docs.vercel.app
Other
47 stars 26 forks source link

Missing Discriminator trait of CoreAsset and CoreCollection for Anchor 0.30.0 #151

Open alphafitz11 opened 4 months ago

alphafitz11 commented 4 months ago

Anchor 0.30.0 require CoreAsset and CoreCollection to implement the Discriminator trait to build IDL. When using anchor 0.30.0, compiling IDL will encounter the following errors:

error[E0599]: no function or associated item named `create_type` found for struct `mpl_core::CoreAsset` in the current scope
  --> programs/solana-marketplace/src/ins/mpl/mpl_core/core_sell_nft.rs:20:10
   |
20 | #[derive(Accounts)]
   |          ^^^^^^^^ function or associated item not found in `CoreAsset`
   |
  ::: programs/solana-marketplace/src/ins/mpl/mpl_core/mod.rs:20:1
   |
20 | pub struct CoreAsset(mpl_core::accounts::BaseAssetV1);
   | -------------------- function or associated item `create_type` not found for this struct
   |
   = help: items from traits can only be used if the trait is implemented and in scope
   = note: the following trait defines an item `create_type`, perhaps you need to implement it:
           candidate #1: `anchor_lang::IdlBuild`
   = note: this error originates in the derive macro `Accounts` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `mpl_core::CoreAsset: Discriminator` is not satisfied
  --> programs/solana-marketplace/src/ins/mpl/mpl_core/core_sell_nft.rs:56:40
   |
56 |     pub core_asset: Box<Account<'info, CoreAsset>>,
   |                                        ^^^^^^^^^ the trait `Discriminator` is not implemented for `mpl_core::CoreAsset`
   |
   = help: the following other types implement trait `Discriminator`:
             BuyCnft
             CancelBuyCnft
             CancelCollectionBuyCnft
             CancelSellCnft
             CollectionBuyCnft
             ExecuteBuyCnft
             ExecuteCollectionBuyCnft
             ExecuteSellCnft
           and 49 others
blockiosaurus commented 4 months ago

Hey @alphafitz11, thanks for calling this out. Right now Core isn't supported as an explicit account in the Accounts structure. This is because of the way it's composed of a set of base data and a collection of plugins, with most users only needing to read a subset. However integrating this into the Anchor Accounts is something we're actively working on. Right now the recommended way to work with Core in Anchor is to treat it as an UncheckedAccount and deserialize it within the instruction.