0

#[derive(AnchorDeserialize, AnchorSerialize)] pub struct UpdateNFTParams { id: String, name: String, symbol: String, uri: String, }

#[derive(Accounts)] #[instruction(params: UpdateNFTParams)] pub struct UpdateNFT<'info> { #[account( mut, mint::decimals = 0, mint::authority = nft_pda )] pub mint_nft: Account<'info, Mint>,

#[account(
    mut,
    seeds = [NFTPda::SEED_PREFIX, params.id.as_bytes().as_ref()],
    bump
)]
pub nft_pda: Account<'info, NFTPda>,

/// CHECK: From metaplex
#[account(mut)]
pub metadata_account: AccountInfo<'info>,
/// CHECK: From metaplex
#[account(mut)]
pub master_edition_account: AccountInfo<'info>,
pub token_metadata_program: Program<'info, Metadata>,
pub token_program: Program<'info, Token>,
pub system_program: Program<'info, System>,
pub buyer: Signer<'info>,
pub rent: Sysvar<'info, Rent>,

}

pub fn update_nft_handler(ctx: Context, params: UpdateNFTParams) -> Result<()> { let mint_nft = &ctx.accounts.mint_nft; let metadata_account = &ctx.accounts.metadata_account; let master_edition_account = &ctx.accounts.master_edition_account; let token_metadata_program = &ctx.accounts.token_metadata_program; let token_program = &ctx.accounts.token_program; let system_program = &ctx.accounts.system_program; let buyer = &ctx.accounts.buyer; let rent = &ctx.accounts.rent; let nft_pda = &ctx.accounts.nft_pda;

let cpi_program = token_metadata_program.to_account_info().clone();
let cpi_accounts = CreateMetadataAccountsV3 {
    metadata: metadata_account.to_account_info(),
    mint: mint_nft.to_account_info(),
    mint_authority: nft_pda.to_account_info(),
    update_authority: nft_pda.to_account_info(),

    payer: buyer.to_account_info(),
    system_program: system_program.to_account_info(),
    rent: rent.to_account_info(),
};

let seed_mint = NFTPda::SEED_PREFIX;
let seeds = &[seed_mint, &params.id.as_bytes(), &[ctx.bumps.nft_pda]];
let signer = &[&seeds[..]];

let cpi_ctx_update_metadata = CpiContext::new_with_signer(cpi_program, cpi_accounts, signer);

let creators = vec![Creator {
    address: buyer.key(),
    verified: false,
    share: 100,
}];

let data_v2 = DataV2 {
    name: params.name.clone(),
    symbol: params.symbol.clone(),
    uri: params.uri.clone(),
    seller_fee_basis_points: 0,
    creators: Some(creators.clone()),
    collection: None,
    uses: None,
};
create_metadata_accounts_v3(cpi_ctx_update_metadata, data_v2, false, true, None)?;

let cpi_program = token_metadata_program.to_account_info().clone();
let cpi_accounts = CreateMasterEditionV3 {
    edition: master_edition_account.to_account_info(),
    mint: mint_nft.to_account_info(),
    mint_authority: nft_pda.to_account_info(),
    update_authority: nft_pda.to_account_info(),
    payer: buyer.to_account_info(),
    metadata: metadata_account.to_account_info(),
    token_program: token_program.to_account_info(),
    system_program: system_program.to_account_info(),
    rent: rent.to_account_info(),
};

let seed_mint = NFTPda::SEED_PREFIX;
let seeds = &[seed_mint, &params.id.as_bytes(), &[ctx.bumps.nft_pda]];
let signer = &[&seeds[..]];

let cpi_ctx_update_master_edition =
    CpiContext::new_with_signer(cpi_program, cpi_accounts, signer);

create_master_edition_v3(cpi_ctx_update_master_edition, None)?;

Ok(())

}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.