Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add client helper for ProgrammableNonFungible master editions #64

Merged
merged 8 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export function setAndVerifySizedCollectionItem(
collection: { index: 5, isWritable: true, value: input.collection ?? null },
collectionMasterEditionAccount: {
index: 6,
isWritable: true,
isWritable: false,
value: input.collectionMasterEditionAccount ?? null,
},
collectionAuthorityRecord: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl SetAndVerifySizedCollectionItem {
self.collection,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.collection_master_edition_account,
false,
));
Expand Down Expand Up @@ -333,7 +333,7 @@ impl<'a, 'b> SetAndVerifySizedCollectionItemCpi<'a, 'b> {
*self.collection.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.collection_master_edition_account.key,
false,
));
Expand Down
18 changes: 18 additions & 0 deletions clients/rust/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
use crate::{errors::MplTokenMetadataError, types::TokenStandard};

/// The offset of the token standard byte in the master edition
/// from the end of the account data.
const TOKEN_STANDARD_OFFSET: usize = 1;

/// Removes all null bytes from a string.
pub fn clean(value: String) -> String {
value.replace('\0', "")
}

/// Checks that the `master_edition` is Programmable NFT master edition.
pub fn assert_edition_is_programmable(edition_data: &[u8]) -> Result<(), MplTokenMetadataError> {
if !edition_data.is_empty()
&& edition_data[edition_data.len() - TOKEN_STANDARD_OFFSET]
danenbm marked this conversation as resolved.
Show resolved Hide resolved
== TokenStandard::ProgrammableNonFungible as u8
{
Ok(())
} else {
Err(MplTokenMetadataError::InvalidTokenStandard)
}
}
2 changes: 1 addition & 1 deletion idls/token_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2288,7 +2288,7 @@
},
{
"name": "collectionMasterEditionAccount",
"isMut": true,
"isMut": false,
"isSigner": false,
"docs": [
"MasterEdition2 Account of the Collection Token"
Expand Down
2 changes: 1 addition & 1 deletion programs/token-metadata/program/src/instruction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ pub enum MetadataInstruction {
#[account(3, name="update_authority", desc="Update Authority of Collection NFT and NFT")]
#[account(4, name="collection_mint", desc="Mint of the Collection")]
#[account(5, writable, name="collection", desc="Metadata Account of the Collection")]
#[account(6, writable, name="collection_master_edition_account", desc="MasterEdition2 Account of the Collection Token")]
#[account(6, name="collection_master_edition_account", desc="MasterEdition2 Account of the Collection Token")]
#[account(7, optional, name="collection_authority_record", desc="Collection Authority Record PDA")]
#[legacy_optional_accounts_strategy]
SetAndVerifySizedCollectionItem,
Expand Down
Loading