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

MET-126: Added new option: CollectionDetails::V2 #96

Merged
merged 4 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 18 additions & 2 deletions clients/js/src/generated/types/collectionDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@ import {
GetDataEnumKind,
GetDataEnumKindContent,
Serializer,
array,
dataEnum,
struct,
u64,
u8,
} from '@metaplex-foundation/umi/serializers';

export type CollectionDetails = { __kind: 'V1'; size: bigint };
export type CollectionDetails =
| { __kind: 'V1'; size: bigint }
| { __kind: 'V2'; padding: Array<number> };

export type CollectionDetailsArgs = { __kind: 'V1'; size: number | bigint };
export type CollectionDetailsArgs =
| { __kind: 'V1'; size: number | bigint }
| { __kind: 'V2'; padding: Array<number> };

export function getCollectionDetailsSerializer(): Serializer<
CollectionDetailsArgs,
Expand All @@ -31,6 +37,12 @@ export function getCollectionDetailsSerializer(): Serializer<
['size', u64()],
]),
],
[
'V2',
struct<GetDataEnumKindContent<CollectionDetails, 'V2'>>([
['padding', array(u8(), { size: 8 })],
]),
],
],
{ description: 'CollectionDetails' }
) as Serializer<CollectionDetailsArgs, CollectionDetails>;
Expand All @@ -41,6 +53,10 @@ export function collectionDetails(
kind: 'V1',
data: GetDataEnumKindContent<CollectionDetailsArgs, 'V1'>
): GetDataEnumKind<CollectionDetailsArgs, 'V1'>;
export function collectionDetails(
kind: 'V2',
data: GetDataEnumKindContent<CollectionDetailsArgs, 'V2'>
): GetDataEnumKind<CollectionDetailsArgs, 'V2'>;
export function collectionDetails<K extends CollectionDetailsArgs['__kind']>(
kind: K,
data?: any
Expand Down
1 change: 1 addition & 0 deletions clients/rust/src/generated/types/collection_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ use borsh::BorshSerialize;
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum CollectionDetails {
V1 { size: u64 },
V2 { padding: [u8; 8] },
}
14 changes: 14 additions & 0 deletions idls/token_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -6584,6 +6584,20 @@
"type": "u64"
}
]
},
{
"name": "V2",
"fields": [
{
"name": "padding",
"type": {
"array": [
"u8",
8
]
}
}
]
}
]
}
Expand Down
3 changes: 1 addition & 2 deletions programs/token-metadata/program/src/assertions/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use solana_program::{
};
use spl_token_2022::state::Account;

use super::assert_owner_in;
use crate::{
assertions::assert_owned_by,
error::MetadataError,
Expand All @@ -18,8 +19,6 @@ use crate::{
utils::unpack_initialized,
};

use super::assert_owner_in;

pub fn assert_data_valid(
data: &Data,
update_authority: &Pubkey,
Expand Down
3 changes: 1 addition & 2 deletions programs/token-metadata/program/src/instruction/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ use solana_program::{
pubkey::Pubkey,
};

use crate::state::fee::FEE_AUTHORITY;

use super::*;
use crate::state::fee::FEE_AUTHORITY;

pub fn collect_fees(recipient: Pubkey, fee_accounts: Vec<Pubkey>) -> Instruction {
let mut accounts = vec![
Expand Down
1 change: 0 additions & 1 deletion programs/token-metadata/program/src/instruction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub use fee::collect_fees;
pub use freeze::*;
pub use metadata::*;
use mpl_token_metadata_context_derive::AccountContext;

#[cfg(feature = "serde-feature")]
use serde::{Deserialize, Serialize};
use shank::ShankInstruction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub fn bubblegum_set_collection_size(
match details {
#[allow(deprecated)]
CollectionDetails::V1 { size } => size,
CollectionDetails::V2 { padding: _ } => 0,
}
} else {
return Err(MetadataError::NotACollectionParent.into());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use mpl_utils::assert_signer;
use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey};
use spl_token_2022::state::Account as TokenAccount;

use super::nonfungible_edition::burn_nonfungible_edition;
use crate::{
assertions::assert_owned_by,
error::MetadataError,
Expand All @@ -11,8 +12,6 @@ use crate::{
utils::{assert_initialized, SPL_TOKEN_ID},
};

use super::nonfungible_edition::burn_nonfungible_edition;

pub fn process_burn_edition_nft<'a>(
program_id: &Pubkey,
accounts: &'a [AccountInfo<'a>],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ use solana_program::{
};
use spl_token_2022::state::Account;

use super::*;
use super::{
nonfungible::{burn_nonfungible, BurnNonFungibleArgs},
*,
};
use crate::{
assertions::assert_owned_by,
instruction::{Burn, Context},
state::{Metadata, TokenMetadataAccount},
utils::{unpack_initialized, SPL_TOKEN_ID},
};

use super::nonfungible::{burn_nonfungible, BurnNonFungibleArgs};

pub fn process_burn_nft<'a>(program_id: &Pubkey, accounts: &'a [AccountInfo<'a>]) -> ProgramResult {
let account_info_iter = &mut accounts.iter();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use spl_token_2022::state::Account;

use super::*;
use crate::{
pda::MARKER,
state::{EditionMarkerV2, MasterEdition, MasterEditionV2, EDITION_MARKER_BIT_SIZE},
utils::unpack_initialized,
};

use super::*;

pub(crate) fn burn_nonfungible_edition(
ctx: &Context<Burn>,
edition_close_authority: bool,
Expand Down
3 changes: 1 addition & 2 deletions programs/token-metadata/program/src/processor/fee/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ use mpl_utils::assert_signer;
use num_traits::FromPrimitive;
use solana_program::{account_info::next_account_info, rent::Rent, system_program, sysvar::Sysvar};

use super::*;
use crate::{
state::{fee::FEE_AUTHORITY, MAX_METADATA_LEN},
utils::fee::clear_fee_flag,
};

use super::*;

pub(crate) fn process_collect_fees(program_id: &Pubkey, accounts: &[AccountInfo]) -> ProgramResult {
let account_info_iter = &mut accounts.iter();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use mpl_utils::{assert_signer, token::SPL_TOKEN_PROGRAM_IDS};
use solana_program::{entrypoint::ProgramResult, pubkey::Pubkey};

use crate::{
assertions::{
assert_owned_by, assert_owner_in, collection::assert_collection_verify_is_valid,
Expand All @@ -8,8 +11,6 @@ use crate::{
state::{AuthorityRequest, AuthorityType, Metadata, TokenMetadataAccount},
utils::{clean_write_metadata, decrement_collection_size, increment_collection_size},
};
use mpl_utils::{assert_signer, token::SPL_TOKEN_PROGRAM_IDS};
use solana_program::{entrypoint::ProgramResult, pubkey::Pubkey};

pub(crate) fn verify_collection_v1(program_id: &Pubkey, ctx: Context<Verify>) -> ProgramResult {
// Assert program ownership/signers.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use mpl_utils::assert_signer;
use solana_program::{entrypoint::ProgramResult, pubkey::Pubkey};

use crate::{
assertions::assert_owned_by,
error::MetadataError,
instruction::{Context, Unverify, Verify},
state::{Creator, Metadata, TokenMetadataAccount},
utils::clean_write_metadata,
};
use mpl_utils::assert_signer;
use solana_program::{entrypoint::ProgramResult, pubkey::Pubkey};

pub(crate) fn verify_creator_v1(program_id: &Pubkey, ctx: Context<Verify>) -> ProgramResult {
// Assert program ownership/signers.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey};

use crate::{
instruction::{Unverify, VerificationArgs, Verify},
processor::verification::{
collection::{unverify_collection_v1, verify_collection_v1},
creator::{unverify_creator_v1, verify_creator_v1},
},
};
use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey};

pub fn verify<'a>(
program_id: &Pubkey,
Expand Down
7 changes: 6 additions & 1 deletion programs/token-metadata/program/src/state/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ pub enum CollectionDetails {
since = "1.13.1",
note = "The collection size tracking feature is deprecated and will soon be removed."
)]
V1 { size: u64 },
V1 {
size: u64,
},
V2 {
padding: [u8; 8],
},
}

#[cfg(test)]
Expand Down
2 changes: 2 additions & 0 deletions programs/token-metadata/program/src/utils/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub fn increment_collection_size(
clean_write_metadata(metadata, metadata_info)?;
Ok(())
}
CollectionDetails::V2 { padding: _ } => Ok(()),
}
} else {
msg!("No collection details. Can't increment.");
Expand All @@ -43,6 +44,7 @@ pub fn decrement_collection_size(
clean_write_metadata(metadata, metadata_info)?;
Ok(())
}
CollectionDetails::V2 { padding: _ } => Ok(()),
}
} else {
msg!("No collection details. Can't decrement.");
Expand Down
3 changes: 3 additions & 0 deletions programs/token-metadata/program/src/utils/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ pub fn process_create_metadata_accounts_logic(
CollectionDetails::V1 { size: _size } => {
metadata.collection_details = Some(CollectionDetails::V1 { size: 0 });
}
CollectionDetails::V2 { padding: _ } => {
metadata.collection_details = None;
}
}
} else {
metadata.collection_details = None;
Expand Down
3 changes: 1 addition & 2 deletions programs/token-metadata/program/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ pub use collection::*;
pub use compression::*;
pub use master_edition::*;
pub use metadata::*;
pub(crate) use token::*;

pub use mpl_utils::{
assert_signer, close_account_raw, create_or_allocate_account_raw,
resize_or_reallocate_account_raw,
Expand All @@ -29,6 +27,7 @@ use spl_token_2022::{
extension::{BaseState, StateWithExtensions},
instruction::{set_authority, AuthorityType},
};
pub(crate) use token::*;

pub const SPL_TOKEN_ID: Pubkey = pubkey!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");

Expand Down
5 changes: 5 additions & 0 deletions programs/token-metadata/program/tests/burn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2187,6 +2187,7 @@ mod nft {
CollectionDetails::V1 { size } => {
assert_eq!(size, 0);
}
CollectionDetails::V2 { padding: _ } => (),
}
} else {
panic!("CollectionDetails is not set!");
Expand Down Expand Up @@ -2216,6 +2217,7 @@ mod nft {
CollectionDetails::V1 { size } => {
assert_eq!(size, 1);
}
CollectionDetails::V2 { padding: _ } => (),
}
} else {
panic!("CollectionDetails is not set!");
Expand Down Expand Up @@ -2247,6 +2249,7 @@ mod nft {
CollectionDetails::V1 { size } => {
assert_eq!(size, 0);
}
CollectionDetails::V2 { padding: _ } => (),
}
} else {
panic!("CollectionDetails is not set!");
Expand Down Expand Up @@ -2602,6 +2605,7 @@ mod nft {
CollectionDetails::V1 { size } => {
assert_eq!(size, 0);
}
CollectionDetails::V2 { padding: _ } => (),
}
} else {
panic!("CollectionDetails is not set!");
Expand Down Expand Up @@ -2630,6 +2634,7 @@ mod nft {
CollectionDetails::V1 { size } => {
assert_eq!(size, 1);
}
CollectionDetails::V2 { padding: _ } => (),
}
} else {
panic!("CollectionDetails is not set");
Expand Down
5 changes: 5 additions & 0 deletions programs/token-metadata/program/tests/burn_nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ mod burn_nft {
CollectionDetails::V1 { size } => {
assert_eq!(size, 0);
}
CollectionDetails::V2 { padding: _ } => (),
}
} else {
panic!("CollectionDetails is not set!");
Expand Down Expand Up @@ -303,6 +304,7 @@ mod burn_nft {
CollectionDetails::V1 { size } => {
assert_eq!(size, 1);
}
CollectionDetails::V2 { padding: _ } => (),
}
} else {
panic!("CollectionDetails is not set");
Expand Down Expand Up @@ -393,6 +395,7 @@ mod burn_nft {
CollectionDetails::V1 { size } => {
assert_eq!(size, 0);
}
CollectionDetails::V2 { padding: _ } => (),
}
} else {
panic!("CollectionDetails is not set!");
Expand Down Expand Up @@ -422,6 +425,7 @@ mod burn_nft {
CollectionDetails::V1 { size } => {
assert_eq!(size, 1);
}
CollectionDetails::V2 { padding: _ } => (),
}
} else {
panic!("CollectionDetails is not set!");
Expand Down Expand Up @@ -450,6 +454,7 @@ mod burn_nft {
CollectionDetails::V1 { size } => {
assert_eq!(size, 0);
}
CollectionDetails::V2 { padding: _ } => (),
}
} else {
panic!("CollectionDetails is not set!");
Expand Down
Loading
Loading