Skip to content

Commit

Permalink
Optimize compute (#412)
Browse files Browse the repository at this point in the history
* Optimize compute

* Remove error

* Compute change everywhere for pnft migration
  • Loading branch information
jpbogle authored Feb 14, 2023
1 parent aff08f9 commit 51cf1e3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 55 deletions.
26 changes: 8 additions & 18 deletions programs/cardinal-token-manager/src/instructions/claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,16 @@ pub fn handler<'key, 'accounts, 'remaining, 'info>(ctx: Context<'key, 'accounts,
if token_manager.kind != TokenManagerKind::Programmable as u8 {
// look at next account
if let Some(next_account) = remaining_accs.peek() {
match assert_derivation(
&mpl_token_metadata::id(),
&next_account.to_account_info(),
&[mpl_token_metadata::state::PREFIX.as_bytes(), mpl_token_metadata::id().as_ref(), mint.as_ref()],
) {
// migrated pnft
Ok(_) => {
let mint_metadata_data = next_account.try_borrow_mut_data().expect("Failed to borrow data");
let metadata = Metadata::deserialize(&mut mint_metadata_data.as_ref()).expect("Failed to deserialize metadata");
match metadata.token_standard {
Some(TokenStandard::ProgrammableNonFungible) => {
// pop this account and update type
next_account_info(remaining_accs)?;
token_manager.kind = TokenManagerKind::Programmable as u8;
}
_ => return Err(error!(ErrorCode::InvalidTokenManagerKind)),
if next_account.owner == &mpl_token_metadata::id() {
let mint_metadata_data = next_account.try_borrow_mut_data().expect("Failed to borrow data");
if let Ok(metadata) = Metadata::deserialize(&mut mint_metadata_data.as_ref()) {
// migrated pnft
if metadata.token_standard == Some(TokenStandard::ProgrammableNonFungible) && metadata.mint == mint {
// pop this account and update type
next_account_info(remaining_accs)?;
token_manager.kind = TokenManagerKind::Programmable as u8;
}
}
// regular edition
_ => {}
}
}
}
Expand Down
26 changes: 8 additions & 18 deletions programs/cardinal-token-manager/src/instructions/invalidate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,16 @@ pub fn handler<'key, 'accounts, 'remaining, 'info>(ctx: Context<'key, 'accounts,
if token_manager.kind != TokenManagerKind::Programmable as u8 {
// look at next account
if let Some(next_account) = remaining_accs.peek() {
match assert_derivation(
&mpl_token_metadata::id(),
&next_account.to_account_info(),
&[mpl_token_metadata::state::PREFIX.as_bytes(), mpl_token_metadata::id().as_ref(), mint.as_ref()],
) {
// migrated pnft
Ok(_) => {
let mint_metadata_data = next_account.try_borrow_mut_data().expect("Failed to borrow data");
let metadata = Metadata::deserialize(&mut mint_metadata_data.as_ref()).expect("Failed to deserialize metadata");
match metadata.token_standard {
Some(TokenStandard::ProgrammableNonFungible) => {
// pop this account and update type
next_account_info(remaining_accs)?;
token_manager.kind = TokenManagerKind::Programmable as u8;
}
_ => return Err(error!(ErrorCode::InvalidTokenManagerKind)),
if next_account.owner == &mpl_token_metadata::id() {
let mint_metadata_data = next_account.try_borrow_mut_data().expect("Failed to borrow data");
if let Ok(metadata) = Metadata::deserialize(&mut mint_metadata_data.as_ref()) {
// migrated pnft
if metadata.token_standard == Some(TokenStandard::ProgrammableNonFungible) && metadata.mint == mint {
// pop this account and update type
next_account_info(remaining_accs)?;
token_manager.kind = TokenManagerKind::Programmable as u8;
}
}
// regular edition
_ => {}
}
}
}
Expand Down
27 changes: 8 additions & 19 deletions programs/cardinal-token-manager/src/instructions/unissue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use mpl_token_metadata::instruction::MetadataInstruction;
use mpl_token_metadata::instruction::TransferArgs;
use mpl_token_metadata::state::Metadata;
use mpl_token_metadata::state::TokenStandard;
use mpl_token_metadata::utils::assert_derivation;
use solana_program::instruction::Instruction;
use solana_program::program::invoke_signed;

Expand Down Expand Up @@ -43,26 +42,16 @@ pub fn handler<'key, 'accounts, 'remaining, 'info>(ctx: Context<'key, 'accounts,
if token_manager.kind != TokenManagerKind::Programmable as u8 {
// look at next account
if let Some(next_account) = remaining_accs.peek() {
match assert_derivation(
&mpl_token_metadata::id(),
&next_account.to_account_info(),
&[mpl_token_metadata::state::PREFIX.as_bytes(), mpl_token_metadata::id().as_ref(), mint.as_ref()],
) {
// migrated pnft
Ok(_) => {
let mint_metadata_data = next_account.try_borrow_mut_data().expect("Failed to borrow data");
let metadata = Metadata::deserialize(&mut mint_metadata_data.as_ref()).expect("Failed to deserialize metadata");
match metadata.token_standard {
Some(TokenStandard::ProgrammableNonFungible) => {
// pop this account and update type
next_account_info(remaining_accs)?;
token_manager.kind = TokenManagerKind::Programmable as u8;
}
_ => return Err(error!(ErrorCode::InvalidTokenManagerKind)),
if next_account.owner == &mpl_token_metadata::id() {
let mint_metadata_data = next_account.try_borrow_mut_data().expect("Failed to borrow data");
if let Ok(metadata) = Metadata::deserialize(&mut mint_metadata_data.as_ref()) {
// migrated pnft
if metadata.token_standard == Some(TokenStandard::ProgrammableNonFungible) && metadata.mint == mint {
// pop this account and update type
next_account_info(remaining_accs)?;
token_manager.kind = TokenManagerKind::Programmable as u8;
}
}
// regular edition
_ => {}
}
}
}
Expand Down

0 comments on commit 51cf1e3

Please sign in to comment.