Skip to content

Commit

Permalink
Addressing first round of feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
blockiosaurus committed Aug 29, 2024
1 parent 6b2e869 commit bb4c4d8
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 12 deletions.
16 changes: 16 additions & 0 deletions clients/js/src/generated/errors/mplTokenMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2939,6 +2939,22 @@ nameToErrorMap.set(
ExpectedUninitializedAccountError
);

/** InvalidEditionAccountLength: Edition account has an invalid length */
export class InvalidEditionAccountLengthError extends ProgramError {
override readonly name: string = 'InvalidEditionAccountLength';

readonly code: number = 0xc8; // 200

constructor(program: Program, cause?: Error) {
super('Edition account has an invalid length', program, cause);
}
}
codeToErrorMap.set(0xc8, InvalidEditionAccountLengthError);
nameToErrorMap.set(
'InvalidEditionAccountLength',
InvalidEditionAccountLengthError
);

/**
* Attempts to resolve a custom program error from the provided error code.
* @category Errors
Expand Down
3 changes: 3 additions & 0 deletions clients/rust/src/generated/errors/mpl_token_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,9 @@ pub enum MplTokenMetadataError {
/// 199 (0xC7) - Expected account to be uninitialized
#[error("Expected account to be uninitialized")]
ExpectedUninitializedAccount,
/// 200 (0xC8) - Edition account has an invalid length
#[error("Edition account has an invalid length")]
InvalidEditionAccountLength,
}

impl solana_program::program_error::PrintProgramError for MplTokenMetadataError {
Expand Down
5 changes: 5 additions & 0 deletions idls/token_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -7833,6 +7833,11 @@
"code": 199,
"name": "ExpectedUninitializedAccount",
"msg": "Expected account to be uninitialized"
},
{
"code": 200,
"name": "InvalidEditionAccountLength",
"msg": "Edition account has an invalid length"
}
],
"metadata": {
Expand Down
2 changes: 1 addition & 1 deletion programs/token-metadata/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
license-file = "../../../LICENSE"
name = "token_metadata"
readme = "README.md"
repository = "https://github.com/metaplex-foundation/metaplex-program-library"
repository = "https://github.com/metaplex-foundation/mpl-token-metadata"
version = "1.14.0"

[features]
Expand Down
2 changes: 1 addition & 1 deletion programs/token-metadata/program/src/assertions/edition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ pub fn assert_edition_is_not_programmable(edition_info: &AccountInfo) -> Program

// Check if it's a master edition of a pNFT
if (edition_data[0] == Key::MasterEditionV2 as u8
// Check if it's an edition of a pNFT
&& (edition_data[edition_data.len() - MASTER_EDITION_TOKEN_STANDARD_OFFSET] == TokenStandard::ProgrammableNonFungible as u8))
// Check if it's an edition of a pNFT
|| (edition_data[0] == Key::EditionV1 as u8
&& edition_data[edition_data.len() - EDITION_TOKEN_STANDARD_OFFSET]
== TokenStandard::ProgrammableNonFungible as u8)
Expand Down
4 changes: 4 additions & 0 deletions programs/token-metadata/program/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,10 @@ pub enum MetadataError {
/// 199
#[error("Expected account to be uninitialized")]
ExpectedUninitializedAccount,

/// 200
#[error("Edition account has an invalid length")]
InvalidEditionAccountLength,
}

impl PrintProgramError for MetadataError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ fn print_logic<'a>(
let mut data = edition_account_info.data.borrow_mut();

if data.len() < MAX_EDITION_LEN {
return Err(MetadataError::InvalidMasterEditionAccountLength.into());
return Err(MetadataError::InvalidEditionAccountLength.into());
}

data[data_len - EDITION_TOKEN_STANDARD_OFFSET] =
Expand Down
25 changes: 23 additions & 2 deletions programs/token-metadata/program/tests/utils/digital_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ use token_metadata::{
ID,
};

use super::{airdrop, create_mint, create_token_account, get_account, mint_tokens};
use crate::upsize_edition;

use super::{
airdrop, create_mint, create_token_account, get_account, mint_tokens, upsize_master_edition,
upsize_metadata,
};

pub const DEFAULT_NAME: &str = "Digital Asset";
pub const DEFAULT_SYMBOL: &str = "DA";
Expand Down Expand Up @@ -359,7 +364,17 @@ impl DigitalAsset {
self.edition = edition;
self.token_standard = Some(token_standard);

context.banks_client.process_transaction(tx).await
context.banks_client.process_transaction(tx).await?;

#[cfg(feature = "padded")]
{
upsize_metadata(context, &self.metadata).await;
if let Some(edition) = self.edition {
upsize_master_edition(context, &edition).await;
}
}

Ok(())
}

pub async fn mint(
Expand Down Expand Up @@ -869,6 +884,12 @@ impl DigitalAsset {
.await
.unwrap();

#[cfg(feature = "padded")]
{
upsize_metadata(context, &print_metadata).await;
upsize_edition(context, &print_edition).await;
}

Ok(DigitalAsset {
mint: print_mint,
token: Some(print_token.pubkey()),
Expand Down
20 changes: 16 additions & 4 deletions programs/token-metadata/program/tests/utils/edition_marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,10 @@ impl EditionMarker {
.await?;

#[cfg(feature = "padded")]
upsize_edition(context, &self.new_edition_pubkey).await;
{
upsize_metadata(context, &self.new_metadata_pubkey).await;
upsize_edition(context, &self.new_edition_pubkey).await;
}

Ok(())
}
Expand Down Expand Up @@ -341,7 +344,10 @@ impl EditionMarker {
.await?;

#[cfg(feature = "padded")]
upsize_edition(context, &self.new_edition_pubkey).await;
{
upsize_metadata(context, &self.new_metadata_pubkey).await;
upsize_edition(context, &self.new_edition_pubkey).await;
}

Ok(())
}
Expand Down Expand Up @@ -406,7 +412,10 @@ impl EditionMarker {
.await?;

#[cfg(feature = "padded")]
upsize_edition(context, &self.new_edition_pubkey).await;
{
upsize_metadata(context, &self.new_metadata_pubkey).await;
upsize_edition(context, &self.new_edition_pubkey).await;
}

Ok(())
}
Expand Down Expand Up @@ -470,7 +479,10 @@ impl EditionMarker {
context.banks_client.process_transaction(tx).await?;

#[cfg(feature = "padded")]
upsize_edition(context, &self.new_edition_pubkey).await;
{
upsize_metadata(context, &self.new_metadata_pubkey).await;
upsize_edition(context, &self.new_edition_pubkey).await;
}

Ok(())
}
Expand Down
3 changes: 0 additions & 3 deletions programs/token-metadata/program/tests/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,6 @@ pub async fn upsize_metadata(context: &mut ProgramTestContext, address: &Pubkey)
extended[678] = original[606];

account_shared.set_data(extended);
// account_shared
// .checked_add_lamports(15616720 - 15115600)
// .expect("Overflow");
context.set_account(address, &account_shared);
airdrop(context, address, 15616720 - 15115600)
.await
Expand Down

0 comments on commit bb4c4d8

Please sign in to comment.