Skip to content

Commit 51cf1e3

Browse files
authored
Optimize compute (#412)
* Optimize compute * Remove error * Compute change everywhere for pnft migration
1 parent aff08f9 commit 51cf1e3

3 files changed

Lines changed: 24 additions & 55 deletions

File tree

programs/cardinal-token-manager/src/instructions/claim.rs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,26 +64,16 @@ pub fn handler<'key, 'accounts, 'remaining, 'info>(ctx: Context<'key, 'accounts,
6464
if token_manager.kind != TokenManagerKind::Programmable as u8 {
6565
// look at next account
6666
if let Some(next_account) = remaining_accs.peek() {
67-
match assert_derivation(
68-
&mpl_token_metadata::id(),
69-
&next_account.to_account_info(),
70-
&[mpl_token_metadata::state::PREFIX.as_bytes(), mpl_token_metadata::id().as_ref(), mint.as_ref()],
71-
) {
72-
// migrated pnft
73-
Ok(_) => {
74-
let mint_metadata_data = next_account.try_borrow_mut_data().expect("Failed to borrow data");
75-
let metadata = Metadata::deserialize(&mut mint_metadata_data.as_ref()).expect("Failed to deserialize metadata");
76-
match metadata.token_standard {
77-
Some(TokenStandard::ProgrammableNonFungible) => {
78-
// pop this account and update type
79-
next_account_info(remaining_accs)?;
80-
token_manager.kind = TokenManagerKind::Programmable as u8;
81-
}
82-
_ => return Err(error!(ErrorCode::InvalidTokenManagerKind)),
67+
if next_account.owner == &mpl_token_metadata::id() {
68+
let mint_metadata_data = next_account.try_borrow_mut_data().expect("Failed to borrow data");
69+
if let Ok(metadata) = Metadata::deserialize(&mut mint_metadata_data.as_ref()) {
70+
// migrated pnft
71+
if metadata.token_standard == Some(TokenStandard::ProgrammableNonFungible) && metadata.mint == mint {
72+
// pop this account and update type
73+
next_account_info(remaining_accs)?;
74+
token_manager.kind = TokenManagerKind::Programmable as u8;
8375
}
8476
}
85-
// regular edition
86-
_ => {}
8777
}
8878
}
8979
}

programs/cardinal-token-manager/src/instructions/invalidate.rs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,26 +65,16 @@ pub fn handler<'key, 'accounts, 'remaining, 'info>(ctx: Context<'key, 'accounts,
6565
if token_manager.kind != TokenManagerKind::Programmable as u8 {
6666
// look at next account
6767
if let Some(next_account) = remaining_accs.peek() {
68-
match assert_derivation(
69-
&mpl_token_metadata::id(),
70-
&next_account.to_account_info(),
71-
&[mpl_token_metadata::state::PREFIX.as_bytes(), mpl_token_metadata::id().as_ref(), mint.as_ref()],
72-
) {
73-
// migrated pnft
74-
Ok(_) => {
75-
let mint_metadata_data = next_account.try_borrow_mut_data().expect("Failed to borrow data");
76-
let metadata = Metadata::deserialize(&mut mint_metadata_data.as_ref()).expect("Failed to deserialize metadata");
77-
match metadata.token_standard {
78-
Some(TokenStandard::ProgrammableNonFungible) => {
79-
// pop this account and update type
80-
next_account_info(remaining_accs)?;
81-
token_manager.kind = TokenManagerKind::Programmable as u8;
82-
}
83-
_ => return Err(error!(ErrorCode::InvalidTokenManagerKind)),
68+
if next_account.owner == &mpl_token_metadata::id() {
69+
let mint_metadata_data = next_account.try_borrow_mut_data().expect("Failed to borrow data");
70+
if let Ok(metadata) = Metadata::deserialize(&mut mint_metadata_data.as_ref()) {
71+
// migrated pnft
72+
if metadata.token_standard == Some(TokenStandard::ProgrammableNonFungible) && metadata.mint == mint {
73+
// pop this account and update type
74+
next_account_info(remaining_accs)?;
75+
token_manager.kind = TokenManagerKind::Programmable as u8;
8476
}
8577
}
86-
// regular edition
87-
_ => {}
8878
}
8979
}
9080
}

programs/cardinal-token-manager/src/instructions/unissue.rs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use mpl_token_metadata::instruction::MetadataInstruction;
1111
use mpl_token_metadata::instruction::TransferArgs;
1212
use mpl_token_metadata::state::Metadata;
1313
use mpl_token_metadata::state::TokenStandard;
14-
use mpl_token_metadata::utils::assert_derivation;
1514
use solana_program::instruction::Instruction;
1615
use solana_program::program::invoke_signed;
1716

@@ -43,26 +42,16 @@ pub fn handler<'key, 'accounts, 'remaining, 'info>(ctx: Context<'key, 'accounts,
4342
if token_manager.kind != TokenManagerKind::Programmable as u8 {
4443
// look at next account
4544
if let Some(next_account) = remaining_accs.peek() {
46-
match assert_derivation(
47-
&mpl_token_metadata::id(),
48-
&next_account.to_account_info(),
49-
&[mpl_token_metadata::state::PREFIX.as_bytes(), mpl_token_metadata::id().as_ref(), mint.as_ref()],
50-
) {
51-
// migrated pnft
52-
Ok(_) => {
53-
let mint_metadata_data = next_account.try_borrow_mut_data().expect("Failed to borrow data");
54-
let metadata = Metadata::deserialize(&mut mint_metadata_data.as_ref()).expect("Failed to deserialize metadata");
55-
match metadata.token_standard {
56-
Some(TokenStandard::ProgrammableNonFungible) => {
57-
// pop this account and update type
58-
next_account_info(remaining_accs)?;
59-
token_manager.kind = TokenManagerKind::Programmable as u8;
60-
}
61-
_ => return Err(error!(ErrorCode::InvalidTokenManagerKind)),
45+
if next_account.owner == &mpl_token_metadata::id() {
46+
let mint_metadata_data = next_account.try_borrow_mut_data().expect("Failed to borrow data");
47+
if let Ok(metadata) = Metadata::deserialize(&mut mint_metadata_data.as_ref()) {
48+
// migrated pnft
49+
if metadata.token_standard == Some(TokenStandard::ProgrammableNonFungible) && metadata.mint == mint {
50+
// pop this account and update type
51+
next_account_info(remaining_accs)?;
52+
token_manager.kind = TokenManagerKind::Programmable as u8;
6253
}
6354
}
64-
// regular edition
65-
_ => {}
6655
}
6756
}
6857
}

0 commit comments

Comments
 (0)