1

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()?;
}

1 Answer 1

2

While I can't answer for the other questions, I can at least tell you how to fix your compile error! Try this, cloning the AccountInfo to avoid having a reference with a lifetime that's too short:

        let card_proofs: Vec<(AccountInfo, bool, bool)> = ctx.remaining_accounts
            .iter()
            .take(params.proofs_length.into())
            .map(|acc| (acc.clone(), acc.is_writable, acc.is_signer))
            .collect();

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.