Skip to content

Commit

Permalink
Merge branch 'main' of github.com:metaplex-foundation/mpl-asset
Browse files Browse the repository at this point in the history
* 'main' of github.com:metaplex-foundation/mpl-asset:
  Add checks to fail early if compressed NFTs are sent into other ixs
  • Loading branch information
nhanphan committed Mar 8, 2024
2 parents eaea964 + 4c75f9e commit 56497f0
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 18 deletions.
12 changes: 9 additions & 3 deletions programs/mpl-core/src/processor/add_plugin.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use borsh::{BorshDeserialize, BorshSerialize};
use mpl_utils::assert_signer;
use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult};
use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, msg};

use crate::{
error::MplCoreError,
instruction::accounts::{AddCollectionPluginAccounts, AddPluginAccounts},
plugins::{create_meta_idempotent, initialize_plugin, Plugin},
state::{Asset, Authority, Collection, DataBlob, SolanaAccount},
utils::resolve_payer,
state::{Asset, Authority, Collection, DataBlob, Key, SolanaAccount},
utils::{load_key, resolve_payer},
};

#[repr(C)]
Expand All @@ -26,6 +27,11 @@ pub(crate) fn add_plugin<'a>(
assert_signer(ctx.accounts.authority)?;
let payer = resolve_payer(ctx.accounts.authority, ctx.accounts.payer)?;

if let Key::HashedAsset = load_key(ctx.accounts.asset, 0)? {
msg!("Error: Adding plugin to compressed is not available");
return Err(MplCoreError::NotAvailable.into());
}

process_add_plugin::<Asset>(
ctx.accounts.asset,
payer,
Expand Down
11 changes: 8 additions & 3 deletions programs/mpl-core/src/processor/approve_plugin_authority.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use borsh::{BorshDeserialize, BorshSerialize};
use mpl_utils::assert_signer;
use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult};
use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, msg};

use crate::{
error::MplCoreError,
instruction::accounts::{
ApproveCollectionPluginAuthorityAccounts, ApprovePluginAuthorityAccounts,
},
plugins::{approve_authority_on_plugin, PluginType},
state::{Asset, Authority, Collection, CoreAsset, DataBlob, SolanaAccount},
utils::{fetch_core_data, resolve_payer},
state::{Asset, Authority, Collection, CoreAsset, DataBlob, Key, SolanaAccount},
utils::{fetch_core_data, load_key, resolve_payer},
};

#[repr(C)]
Expand All @@ -29,6 +29,11 @@ pub(crate) fn approve_plugin_authority<'a>(
assert_signer(ctx.accounts.authority)?;
let payer = resolve_payer(ctx.accounts.authority, ctx.accounts.payer)?;

if let Key::HashedAsset = load_key(ctx.accounts.asset, 0)? {
msg!("Error: Approve plugin authority for compressed is not available");
return Err(MplCoreError::NotAvailable.into());
}

process_approve_plugin_authority::<Asset>(
ctx.accounts.asset,
ctx.accounts.authority,
Expand Down
2 changes: 1 addition & 1 deletion programs/mpl-core/src/processor/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub(crate) fn create<'a>(accounts: &'a [AccountInfo<'a>], args: CreateArgs) -> P
DataState::AccountState => serialized_data,
DataState::LedgerState => {
// TODO Enable minting compressed.
msg!("Error: Minting compressed currently not available");
msg!("Error: Minting compressed is currently not available");
return Err(MplCoreError::NotAvailable.into());
}
};
Expand Down
11 changes: 8 additions & 3 deletions programs/mpl-core/src/processor/remove_plugin.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use borsh::{BorshDeserialize, BorshSerialize};
use mpl_utils::assert_signer;
use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult};
use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, msg};

use crate::{
error::MplCoreError,
instruction::accounts::{RemoveCollectionPluginAccounts, RemovePluginAccounts},
plugins::{delete_plugin, PluginType},
state::{Asset, Authority, Collection},
utils::{fetch_core_data, resolve_payer, resolve_to_authority},
state::{Asset, Authority, Collection, Key},
utils::{fetch_core_data, load_key, resolve_payer, resolve_to_authority},
};

#[repr(C)]
Expand All @@ -26,6 +26,11 @@ pub(crate) fn remove_plugin<'a>(
assert_signer(ctx.accounts.authority)?;
let payer = resolve_payer(ctx.accounts.authority, ctx.accounts.payer)?;

if let Key::HashedAsset = load_key(ctx.accounts.asset, 0)? {
msg!("Error: Remove plugin for compressed is not available");
return Err(MplCoreError::NotAvailable.into());
}

let (asset, plugin_header, plugin_registry) = fetch_core_data::<Asset>(ctx.accounts.asset)?;

// We don't have anything to delete if there's no plugin meta.
Expand Down
11 changes: 8 additions & 3 deletions programs/mpl-core/src/processor/revoke_plugin_authority.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use borsh::{BorshDeserialize, BorshSerialize};
use mpl_utils::assert_signer;
use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult};
use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, msg};

use crate::{
error::MplCoreError,
instruction::accounts::{
RevokeCollectionPluginAuthorityAccounts, RevokePluginAuthorityAccounts,
},
plugins::{revoke_authority_on_plugin, PluginHeader, PluginRegistry, PluginType},
state::{Asset, Authority, Collection},
utils::{fetch_core_data, resolve_payer, resolve_to_authority},
state::{Asset, Authority, Collection, Key},
utils::{fetch_core_data, load_key, resolve_payer, resolve_to_authority},
};

#[repr(C)]
Expand All @@ -28,6 +28,11 @@ pub(crate) fn revoke_plugin_authority<'a>(
assert_signer(ctx.accounts.authority)?;
let payer = resolve_payer(ctx.accounts.authority, ctx.accounts.payer)?;

if let Key::HashedAsset = load_key(ctx.accounts.asset, 0)? {
msg!("Error: Revoke plugin authority for compressed is not available");
return Err(MplCoreError::NotAvailable.into());
}

let (asset, plugin_header, mut plugin_registry) = fetch_core_data::<Asset>(ctx.accounts.asset)?;

//TODO: Make this better.
Expand Down
11 changes: 8 additions & 3 deletions programs/mpl-core/src/processor/update.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use borsh::{BorshDeserialize, BorshSerialize};
use mpl_utils::assert_signer;
use solana_program::{
account_info::AccountInfo, entrypoint::ProgramResult, program_memory::sol_memcpy,
account_info::AccountInfo, entrypoint::ProgramResult, msg, program_memory::sol_memcpy,
};

use crate::{
error::MplCoreError,
instruction::accounts::{UpdateAccounts, UpdateCollectionAccounts},
plugins::{Plugin, PluginType, RegistryRecord},
state::{Asset, Collection, DataBlob, SolanaAccount, UpdateAuthority},
state::{Asset, Collection, DataBlob, Key, SolanaAccount, UpdateAuthority},
utils::{
resize_or_reallocate_account, resolve_payer, validate_asset_permissions,
load_key, resize_or_reallocate_account, resolve_payer, validate_asset_permissions,
validate_collection_permissions,
},
};
Expand All @@ -30,6 +30,11 @@ pub(crate) fn update<'a>(accounts: &'a [AccountInfo<'a>], args: UpdateArgs) -> P
assert_signer(ctx.accounts.authority)?;
let payer = resolve_payer(ctx.accounts.authority, ctx.accounts.payer)?;

if let Key::HashedAsset = load_key(ctx.accounts.asset, 0)? {
msg!("Error: Update for compressed is not available");
return Err(MplCoreError::NotAvailable.into());
}

let (mut asset, plugin_header, plugin_registry) = validate_asset_permissions(
ctx.accounts.authority,
ctx.accounts.asset,
Expand Down
10 changes: 8 additions & 2 deletions programs/mpl-core/src/processor/update_plugin.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use borsh::{BorshDeserialize, BorshSerialize};
use mpl_utils::assert_signer;
use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult};
use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, msg};

use crate::{
error::MplCoreError,
instruction::accounts::{UpdateCollectionPluginAccounts, UpdatePluginAccounts},
plugins::{Plugin, PluginType, ValidationResult},
utils::fetch_core_data,
state::Key,
utils::{fetch_core_data, load_key},
};

#[repr(C)]
Expand All @@ -28,6 +29,11 @@ pub(crate) fn update_plugin<'a>(
assert_signer(payer)?;
}

if let Key::HashedAsset = load_key(ctx.accounts.asset, 0)? {
msg!("Error: Update plugin for compressed is not available");
return Err(MplCoreError::NotAvailable.into());
}

let (asset, _, plugin_registry) = fetch_core_data(ctx.accounts.asset)?;
let plugin_registry = plugin_registry.ok_or(MplCoreError::PluginsNotInitialized)?;

Expand Down

0 comments on commit 56497f0

Please sign in to comment.