diff --git a/programs/mpl-core/src/plugins/freeze.rs b/programs/mpl-core/src/plugins/freeze.rs index e63338a5..dc76aff3 100644 --- a/programs/mpl-core/src/plugins/freeze.rs +++ b/programs/mpl-core/src/plugins/freeze.rs @@ -1,7 +1,7 @@ use borsh::{BorshDeserialize, BorshSerialize}; use solana_program::{account_info::AccountInfo, program_error::ProgramError}; -use crate::state::{Asset, Authority, DataBlob}; +use crate::state::{Authority, CoreAsset, DataBlob}; use super::{PluginValidation, ValidationResult}; @@ -54,21 +54,21 @@ impl PluginValidation for Freeze { Ok(ValidationResult::Pass) } - fn validate_update_plugin( + fn validate_update_plugin( &self, - asset: &Asset, + core_asset: &T, authority_info: &AccountInfo, authority: &Authority, ) -> Result { // The owner can't update the freeze status. - if (authority_info.key != &asset.owner - && (authority_info.key == &asset.update_authority.key() + if (authority_info.key != core_asset.owner() + && (authority_info.key == &core_asset.update_authority().key() && authority == (&Authority::UpdateAuthority)) || authority == (&Authority::Pubkey { address: *authority_info.key, })) // Unless the owner is the only authority. - || (authority_info.key == &asset.owner + || (authority_info.key == core_asset.owner() && authority == (&Authority::Owner)) { Ok(ValidationResult::Approved) diff --git a/programs/mpl-core/src/plugins/lifecycle.rs b/programs/mpl-core/src/plugins/lifecycle.rs index ce3fef81..d709dfd6 100644 --- a/programs/mpl-core/src/plugins/lifecycle.rs +++ b/programs/mpl-core/src/plugins/lifecycle.rs @@ -4,7 +4,7 @@ use solana_program::{account_info::AccountInfo, program_error::ProgramError}; use crate::{ error::MplCoreError, - state::{Asset, Authority, Key}, + state::{Authority, CoreAsset, Key}, }; use super::{Plugin, PluginType, RegistryRecord}; @@ -116,9 +116,9 @@ impl Plugin { /// Route the validation of the update_plugin action to the appropriate plugin. /// There is no check for updating a plugin because the plugin itself MUST validate the change. - pub(crate) fn validate_update_plugin( + pub(crate) fn validate_update_plugin( plugin: &Plugin, - asset: &Asset, + core_asset: &T, authority: &AccountInfo, _unused: Option<&AccountInfo>, authorities: &Authority, @@ -126,15 +126,17 @@ impl Plugin { match plugin { Plugin::Reserved => Err(MplCoreError::InvalidPlugin.into()), Plugin::Royalties(royalties) => { - royalties.validate_update_plugin(asset, authority, authorities) + royalties.validate_update_plugin(core_asset, authority, authorities) } - Plugin::Freeze(freeze) => freeze.validate_update_plugin(asset, authority, authorities), - Plugin::Burn(burn) => burn.validate_update_plugin(asset, authority, authorities), + Plugin::Freeze(freeze) => { + freeze.validate_update_plugin(core_asset, authority, authorities) + } + Plugin::Burn(burn) => burn.validate_update_plugin(core_asset, authority, authorities), Plugin::Transfer(transfer) => { - transfer.validate_update_plugin(asset, authority, authorities) + transfer.validate_update_plugin(core_asset, authority, authorities) } Plugin::UpdateDelegate(update_delegate) => { - update_delegate.validate_update_plugin(asset, authority, authorities) + update_delegate.validate_update_plugin(core_asset, authority, authorities) } } } @@ -296,14 +298,14 @@ pub(crate) trait PluginValidation { ) -> Result; /// Validate the update_plugin lifecycle action. - fn validate_update_plugin( + fn validate_update_plugin( &self, - asset: &Asset, + core_asset: &T, authority_info: &AccountInfo, authority: &Authority, ) -> Result { - if (authority_info.key == &asset.owner && authority == &Authority::Owner) - || (authority_info.key == &asset.update_authority.key() + if (authority_info.key == core_asset.owner() && authority == &Authority::Owner) + || (authority_info.key == &core_asset.update_authority().key() && authority == &Authority::UpdateAuthority) || authority == (&Authority::Pubkey { diff --git a/programs/mpl-core/src/processor/update_plugin.rs b/programs/mpl-core/src/processor/update_plugin.rs index 3b071083..cb990be4 100644 --- a/programs/mpl-core/src/processor/update_plugin.rs +++ b/programs/mpl-core/src/processor/update_plugin.rs @@ -6,7 +6,7 @@ use crate::{ error::MplCoreError, instruction::accounts::{UpdateCollectionPluginAccounts, UpdatePluginAccounts}, plugins::{Plugin, PluginType, ValidationResult}, - state::Key, + state::{Asset, Collection, Key}, utils::{fetch_core_data, load_key}, }; @@ -34,7 +34,7 @@ pub(crate) fn update_plugin<'a>( return Err(MplCoreError::NotAvailable.into()); } - let (asset, _, plugin_registry) = fetch_core_data(ctx.accounts.asset)?; + let (asset, _, plugin_registry) = fetch_core_data::(ctx.accounts.asset)?; let plugin_registry = plugin_registry.ok_or(MplCoreError::PluginsNotInitialized)?; let plugin_type: PluginType = (&args.plugin).into(); @@ -83,7 +83,7 @@ pub(crate) fn update_collection_plugin<'a>( assert_signer(payer)?; } - let (asset, _, plugin_registry) = fetch_core_data(ctx.accounts.collection)?; + let (collection, _, plugin_registry) = fetch_core_data::(ctx.accounts.collection)?; let plugin_registry = plugin_registry.ok_or(MplCoreError::PluginsNotInitialized)?; let plugin_type: PluginType = (&args.plugin).into(); @@ -95,7 +95,7 @@ pub(crate) fn update_collection_plugin<'a>( let result = Plugin::validate_update_plugin( &Plugin::load(ctx.accounts.collection, registry_record.offset)?, - &asset, + &collection, ctx.accounts.authority, None, ®istry_record.authority,