Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collection doesn't implement plugin_list or plugin_header #40

Open
joefitter opened this issue Mar 30, 2024 · 2 comments
Open

Collection doesn't implement plugin_list or plugin_header #40

joefitter opened this issue Mar 30, 2024 · 2 comments

Comments

@joefitter
Copy link
Contributor

joefitter commented Mar 30, 2024

mpl-core = "0.3.0"

Assets can be deserialised, Collections can not. I am only able to deserialise into a BaseCollection which doesn't contain the plugin_list so I am unable to see plugins applied to the collection in my program.

#[derive(Debug)]
pub struct Asset {
pub base: BaseAssetV1,
pub plugin_list: PluginsList,
pub plugin_header: Option<PluginHeaderV1>,
}
#[derive(Debug)]
pub struct Collection {
pub base: BaseCollectionV1,
pub plugin_list: PluginsList,
pub plugin_header: PluginHeaderV1,
}

// works
let asset_account = Asset::try_from(asset)?;
// does not work - try_from not implemented
let collection_account = Collection::try_from(collection)?;
@joefitter
Copy link
Contributor Author

joefitter commented Apr 2, 2024

to get this working in my implementation I just copied the impl from Asset into my program for Collection:

use anchor_lang::AnchorSerialize;

use mpl_core::{
    accounts::{BaseCollectionV1, PluginHeaderV1, PluginRegistryV1},
    registry_records_to_plugin_list, PluginsList,
};

pub struct Collection {
    pub base: BaseCollectionV1,
    pub plugin_list: PluginsList,
    pub plugin_header: PluginHeaderV1,
}

impl Collection {
    pub fn deserialize_asset(data: &[u8]) -> Result<Collection, std::io::Error> {
        let base = BaseCollectionV1::from_bytes(data)?;
        let base_data = base.try_to_vec()?;
        let (plugin_header, plugin_list) = if base_data.len() != data.len() {
            let plugin_header = PluginHeaderV1::from_bytes(&data[base_data.len()..])?;
            let plugin_registry = PluginRegistryV1::from_bytes(
                &data[plugin_header.plugin_registry_offset as usize..],
            )?;
            let plugin_list = registry_records_to_plugin_list(&plugin_registry.registry, data)?;

            (Some(plugin_header), Some(plugin_list))
        } else {
            (None, None)
        };

        Ok(Self {
            base,
            plugin_list: plugin_list.unwrap_or_default(),
            plugin_header: plugin_header.unwrap(),
        })
    }

    #[inline(always)]
    pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
        Self::deserialize_asset(data)
    }
}

impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for Collection {
    type Error = std::io::Error;

    fn try_from(
        account_info: &solana_program::account_info::AccountInfo<'a>,
    ) -> Result<Self, Self::Error> {
        let data: &[u8] = &(*account_info.data).borrow();
        Self::deserialize_asset(data)
    }
}

@danenbm
Copy link
Contributor

danenbm commented Jun 11, 2024

This should all be supported as of 012d081#diff-414d3e177a37705c274f497133d951f14ec67efa2d6350e7e4f2e7f936bcc4cb

However, I now see that it looks like we need to add support for external plugin adapters on collections

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants