Skip to main content
edited tags
Link
Source Link

How to use mpl_bubblegum::instructions::VerifyLeafCpiBuilder?

questions

  1. Can someone tell me how to verify that the transaction signer is the owner of the cNFT within a Solana program instruction?
  2. Is it done using VerifyLeafCpiBuilder?
  3. If so, how should VerifyLeafCpiBuilder be used correctly? I encountered an error when using it, as shown below:

error

53 |     pub fn process(ctx: Context<Card>, params: &VerifyParams) -> Result<()> {
   |                    ---
   |                    |
   |                    has type `anchor_lang::context::Context<'_, '_, '_, '1, scratching_card::ScratchingCard<'_>>`
   |                    has type `anchor_lang::context::Context<'_, '_, '_, '_, scratching_card::ScratchingCard<'2>>`
...
66 |             .map(|acc| (acc, acc.is_writable, acc.is_signer))
   |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`

code

  pub fn process(ctx: Context<Card>, params: &VerifyParams) -> Result<()> {

        let leaf = LeafSchema::V1 {
            id: params.asset_id,
            owner: ctx.accounts.leaf_owner.key(),
            delegate: ctx.accounts.leaf_owner.key(),
            nonce: params.nonce,
            data_hash: params.data_hash,
            creator_hash: params.creator_hash,
        }.hash();
        let card_proofs: Vec<(&AccountInfo, bool, bool)> = ctx.remaining_accounts
            .iter()
            .take(params.proofs_length.into())
            .map(|acc| (acc, acc.is_writable, acc.is_signer))
            .collect();

        VerifyLeafCpiBuilder::new(&ctx.accounts.bubblegum_program.to_account_info())
            .merkle_tree(&ctx.accounts.merkle_tree.to_account_info())
            .root(params.root)
            .leaf(leaf)
            .index(params.index)
            .add_remaining_accounts(&card_proofs)
            .invoke()?;
}