Skip to content

Commit

Permalink
correctly read collection plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
nhanphan committed Feb 29, 2024
1 parent e5cfd1c commit f296482
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
28 changes: 28 additions & 0 deletions programs/mpl-core/src/plugins/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,34 @@ pub fn fetch_plugin(
))
}

/// Fetch the collection plugin from the registry.
pub fn fetch_collection_plugin(
account: &AccountInfo,
plugin_type: PluginType,
) -> Result<(Vec<Authority>, Plugin, usize), ProgramError> {
let collection = CollectionData::load(account, 0)?;

let header = PluginHeader::load(account, collection.get_size())?;
let PluginRegistry { registry, .. } =
PluginRegistry::load(account, header.plugin_registry_offset)?;

// Find the plugin in the registry.
let registry_record = registry
.iter()
.find(|record| record.plugin_type == plugin_type)
.ok_or(MplCoreError::PluginNotFound)?;

// Deserialize the plugin.
let plugin = Plugin::deserialize(&mut &(*account.data).borrow()[registry_record.offset..])?;

// Return the plugin and its authorities.
Ok((
registry_record.authorities.clone(),
plugin,
registry_record.offset,
))
}

/// Fetch the plugin registry.
pub fn fetch_plugins(account: &AccountInfo) -> Result<Vec<RegistryRecord>, ProgramError> {
let asset = Asset::load(account, 0)?;
Expand Down
4 changes: 2 additions & 2 deletions programs/mpl-core/src/state/update_authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
BurnAccounts, CompressAccounts, CreateAccounts, DecompressAccounts, TransferAccounts,
UpdateAccounts,
},
plugins::{fetch_plugin, CheckResult, PluginType, ValidationResult},
plugins::{fetch_collection_plugin, CheckResult, PluginType, ValidationResult},
processor::CreateArgs,
state::{Authority, CollectionData, SolanaAccount},
utils::assert_collection_authority,
Expand Down Expand Up @@ -69,7 +69,7 @@ impl UpdateAuthority {
};

let maybe_update_delegate =
fetch_plugin(collection_info, PluginType::UpdateDelegate);
fetch_collection_plugin(collection_info, PluginType::UpdateDelegate);

if let Ok((mut authorities, _, _)) = maybe_update_delegate {
authorities.push(Authority::UpdateAuthority);
Expand Down

0 comments on commit f296482

Please sign in to comment.