Skip to content

Commit

Permalink
check edition is derived from mint for initialize (#879)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelvanderwaal authored Nov 6, 2022
1 parent 87dadfb commit 1063506
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use mpl_token_metadata::{
};
use solana_program::program::{invoke, invoke_signed};

use crate::{cmp_pubkeys, constants::AUTHORITY_SEED, CandyError, CandyMachine};
use crate::{
cmp_pubkeys, constants::AUTHORITY_SEED, utils::assert_edition_from_mint, CandyError,
CandyMachine,
};

pub fn set_collection(ctx: Context<SetCollection>) -> Result<()> {
let accounts = ctx.accounts;
Expand Down Expand Up @@ -93,6 +96,7 @@ pub fn approve_collection_authority_helper(
}

assert_master_edition(&collection_data, &collection_master_edition)?;
assert_edition_from_mint(&collection_master_edition, &collection_mint)?;

let approve_collection_authority_ix = approve_collection_authority(
token_metadata_program.key(),
Expand Down
24 changes: 24 additions & 0 deletions candy-machine-core/program/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
use anchor_lang::prelude::*;
use arrayref::array_ref;
use mpl_token_metadata::{
error::MetadataError,
state::{EDITION, PREFIX},
utils::assert_derivation,
};
use solana_program::{
account_info::AccountInfo,
program::invoke,
Expand All @@ -8,6 +13,7 @@ use solana_program::{
pubkey::{Pubkey, PUBKEY_BYTES},
system_instruction,
};
use std::result::Result as StdResult;

use crate::{
constants::{HIDDEN_SECTION, NULL_STRING, REPLACEMENT_INDEX, REPLACEMENT_INDEX_INCREMENT},
Expand Down Expand Up @@ -80,6 +86,24 @@ pub fn replace_patterns(value: String, index: usize) -> String {
mutable
}

pub fn assert_edition_from_mint(
edition_account: &AccountInfo,
mint_account: &AccountInfo,
) -> StdResult<(), ProgramError> {
assert_derivation(
&mpl_token_metadata::id(),
edition_account,
&[
PREFIX.as_bytes(),
mpl_token_metadata::id().as_ref(),
mint_account.key().as_ref(),
EDITION.as_bytes(),
],
)
.map_err(|_| MetadataError::CollectionMasterEditionAccountInvalid)?;
Ok(())
}

#[cfg(test)]
pub mod tests {
use super::*;
Expand Down

0 comments on commit 1063506

Please sign in to comment.