diff --git a/clients/js/src/generated/types/delegate.ts b/clients/js/src/generated/types/delegate.ts index 55ad2c58..d775b8ce 100644 --- a/clients/js/src/generated/types/delegate.ts +++ b/clients/js/src/generated/types/delegate.ts @@ -7,18 +7,13 @@ */ import { Serializer, bool, struct } from '@metaplex-foundation/umi/serializers'; -import { Key, KeyArgs, getKeySerializer } from '.'; -export type Delegate = { key: Key; frozen: boolean }; +export type Delegate = { frozen: boolean }; -export type DelegateArgs = { key: KeyArgs; frozen: boolean }; +export type DelegateArgs = Delegate; export function getDelegateSerializer(): Serializer { - return struct( - [ - ['key', getKeySerializer()], - ['frozen', bool()], - ], - { description: 'Delegate' } - ) as Serializer; + return struct([['frozen', bool()]], { + description: 'Delegate', + }) as Serializer; } diff --git a/clients/js/src/generated/types/index.ts b/clients/js/src/generated/types/index.ts index 1695fdb1..f0983d70 100644 --- a/clients/js/src/generated/types/index.ts +++ b/clients/js/src/generated/types/index.ts @@ -17,6 +17,7 @@ export * from './extraAccounts'; export * from './key'; export * from './migrationLevel'; export * from './plugin'; +export * from './pluginType'; export * from './registryData'; export * from './registryRecord'; export * from './royalties'; diff --git a/clients/js/src/generated/types/key.ts b/clients/js/src/generated/types/key.ts index 8558a0b3..e7d0fac8 100644 --- a/clients/js/src/generated/types/key.ts +++ b/clients/js/src/generated/types/key.ts @@ -12,11 +12,8 @@ export enum Key { Uninitialized, Asset, HashedAsset, - Collection, - HashedCollection, PluginHeader, PluginRegistry, - Delegate, } export type KeyArgs = Key; diff --git a/clients/js/src/generated/types/plugin.ts b/clients/js/src/generated/types/plugin.ts index 889abca0..e10faa68 100644 --- a/clients/js/src/generated/types/plugin.ts +++ b/clients/js/src/generated/types/plugin.ts @@ -15,23 +15,35 @@ import { tuple, unit, } from '@metaplex-foundation/umi/serializers'; -import { Delegate, DelegateArgs, getDelegateSerializer } from '.'; +import { + Delegate, + DelegateArgs, + Royalties, + RoyaltiesArgs, + getDelegateSerializer, + getRoyaltiesSerializer, +} from '.'; export type Plugin = | { __kind: 'Reserved' } - | { __kind: 'Royalties' } + | { __kind: 'Royalties'; fields: [Royalties] } | { __kind: 'Delegate'; fields: [Delegate] }; export type PluginArgs = | { __kind: 'Reserved' } - | { __kind: 'Royalties' } + | { __kind: 'Royalties'; fields: [RoyaltiesArgs] } | { __kind: 'Delegate'; fields: [DelegateArgs] }; export function getPluginSerializer(): Serializer { return dataEnum( [ ['Reserved', unit()], - ['Royalties', unit()], + [ + 'Royalties', + struct>([ + ['fields', tuple([getRoyaltiesSerializer()])], + ]), + ], [ 'Delegate', struct>([ @@ -48,7 +60,8 @@ export function plugin( kind: 'Reserved' ): GetDataEnumKind; export function plugin( - kind: 'Royalties' + kind: 'Royalties', + data: GetDataEnumKindContent['fields'] ): GetDataEnumKind; export function plugin( kind: 'Delegate', diff --git a/clients/js/src/generated/types/pluginType.ts b/clients/js/src/generated/types/pluginType.ts new file mode 100644 index 00000000..9948bd21 --- /dev/null +++ b/clients/js/src/generated/types/pluginType.ts @@ -0,0 +1,26 @@ +/** + * This code was AUTOGENERATED using the kinobi library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun kinobi to update it. + * + * @see https://github.com/metaplex-foundation/kinobi + */ + +import { Serializer, scalarEnum } from '@metaplex-foundation/umi/serializers'; + +export enum PluginType { + Reserved, + Royalties, + Delegate, +} + +export type PluginTypeArgs = PluginType; + +export function getPluginTypeSerializer(): Serializer< + PluginTypeArgs, + PluginType +> { + return scalarEnum(PluginType, { + description: 'PluginType', + }) as Serializer; +} diff --git a/clients/js/src/generated/types/registryRecord.ts b/clients/js/src/generated/types/registryRecord.ts index 2680179a..5c7ea988 100644 --- a/clients/js/src/generated/types/registryRecord.ts +++ b/clients/js/src/generated/types/registryRecord.ts @@ -8,17 +8,20 @@ import { Serializer, struct } from '@metaplex-foundation/umi/serializers'; import { - Key, - KeyArgs, + PluginType, + PluginTypeArgs, RegistryData, RegistryDataArgs, - getKeySerializer, + getPluginTypeSerializer, getRegistryDataSerializer, } from '.'; -export type RegistryRecord = { key: Key; data: RegistryData }; +export type RegistryRecord = { pluginType: PluginType; data: RegistryData }; -export type RegistryRecordArgs = { key: KeyArgs; data: RegistryDataArgs }; +export type RegistryRecordArgs = { + pluginType: PluginTypeArgs; + data: RegistryDataArgs; +}; export function getRegistryRecordSerializer(): Serializer< RegistryRecordArgs, @@ -26,7 +29,7 @@ export function getRegistryRecordSerializer(): Serializer< > { return struct( [ - ['key', getKeySerializer()], + ['pluginType', getPluginTypeSerializer()], ['data', getRegistryDataSerializer()], ], { description: 'RegistryRecord' } diff --git a/clients/js/test/delegate.test.ts b/clients/js/test/delegate.test.ts index 5fecb3af..1eb03d1f 100644 --- a/clients/js/test/delegate.test.ts +++ b/clients/js/test/delegate.test.ts @@ -16,7 +16,8 @@ import { getAssetAccountDataSerializer, getDelegateSerializer, getPluginHeaderAccountDataSerializer, - getPluginRegistryAccountDataSerializer + getPluginRegistryAccountDataSerializer, + PluginType, } from '../src'; import { createUmi } from './_setup'; @@ -58,7 +59,7 @@ test('it can delegate a new authority', async (t) => { t.like(pluginRegistry, { key: Key.PluginRegistry, registry: [{ - key: Key.Delegate, + pluginType: PluginType.Delegate, data: { offset: BigInt(117), authorities: [{ __kind: 'Pubkey', address: delegateAddress.publicKey }], @@ -69,7 +70,6 @@ test('it can delegate a new authority', async (t) => { const delegatePlugin = getDelegateSerializer().deserialize(pluginData.data, Number(pluginRegistry.registry[0].data.offset))[0]; // console.log(delegatePlugin); t.like(delegatePlugin, { - key: Key.Delegate, frozen: false, }); } else { diff --git a/clients/js/test/delegateTransfer.test.ts b/clients/js/test/delegateTransfer.test.ts new file mode 100644 index 00000000..07395236 --- /dev/null +++ b/clients/js/test/delegateTransfer.test.ts @@ -0,0 +1,56 @@ +import { generateSigner } from '@metaplex-foundation/umi'; +import test from 'ava'; +// import { base58 } from '@metaplex-foundation/umi/serializers'; +import { Asset, DataState, create, delegate, fetchAsset, transfer } from '../src'; +import { createUmi } from './_setup'; + +test('it can transfer an asset as the delegate', async (t) => { + // Given a Umi instance and a new signer. + const umi = await createUmi(); + const assetAddress = generateSigner(umi); + const newOwner = generateSigner(umi); + const delegateAddress = generateSigner(umi); + + // When we create a new account. + await create(umi, { + dataState: DataState.AccountState, + assetAddress, + name: 'Test Bread', + uri: 'https://example.com/bread', + }).sendAndConfirm(umi); + + // Then an account was created with the correct data. + const beforeAsset = await fetchAsset(umi, assetAddress.publicKey); + // console.log("Account State:", beforeAsset); + t.like(beforeAsset, { + publicKey: assetAddress.publicKey, + updateAuthority: umi.identity.publicKey, + owner: umi.identity.publicKey, + name: 'Test Bread', + uri: 'https://example.com/bread', + }); + + await delegate(umi, { + assetAddress: assetAddress.publicKey, + owner: umi.identity, + delegate: delegateAddress.publicKey + }).sendAndConfirm(umi); + + await transfer(umi, { + assetAddress: assetAddress.publicKey, + newOwner: newOwner.publicKey, + authority: delegateAddress, + compressionProof: null + }).sendAndConfirm(umi); + + const afterAsset = await fetchAsset(umi, assetAddress.publicKey); + // console.log("Account State:", afterAsset); + t.like(afterAsset, { + publicKey: assetAddress.publicKey, + updateAuthority: umi.identity.publicKey, + owner: newOwner.publicKey, + name: 'Test Bread', + uri: 'https://example.com/bread', + }); +}); + diff --git a/clients/rust/src/generated/types/delegate.rs b/clients/rust/src/generated/types/delegate.rs index 8a51bd3d..889bbe82 100644 --- a/clients/rust/src/generated/types/delegate.rs +++ b/clients/rust/src/generated/types/delegate.rs @@ -5,13 +5,11 @@ //! [https://github.com/metaplex-foundation/kinobi] //! -use crate::generated::types::Key; use borsh::BorshDeserialize; use borsh::BorshSerialize; #[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Delegate { - pub key: Key, pub frozen: bool, } diff --git a/clients/rust/src/generated/types/key.rs b/clients/rust/src/generated/types/key.rs index 956e7fea..fac43a60 100644 --- a/clients/rust/src/generated/types/key.rs +++ b/clients/rust/src/generated/types/key.rs @@ -14,9 +14,6 @@ pub enum Key { Uninitialized, Asset, HashedAsset, - Collection, - HashedCollection, PluginHeader, PluginRegistry, - Delegate, } diff --git a/clients/rust/src/generated/types/mod.rs b/clients/rust/src/generated/types/mod.rs index 8481e0fc..d6d3d813 100644 --- a/clients/rust/src/generated/types/mod.rs +++ b/clients/rust/src/generated/types/mod.rs @@ -16,6 +16,7 @@ pub(crate) mod extra_accounts; pub(crate) mod key; pub(crate) mod migration_level; pub(crate) mod plugin; +pub(crate) mod plugin_type; pub(crate) mod registry_data; pub(crate) mod registry_record; pub(crate) mod royalties; @@ -31,6 +32,7 @@ pub use self::extra_accounts::*; pub use self::key::*; pub use self::migration_level::*; pub use self::plugin::*; +pub use self::plugin_type::*; pub use self::registry_data::*; pub use self::registry_record::*; pub use self::royalties::*; diff --git a/clients/rust/src/generated/types/plugin.rs b/clients/rust/src/generated/types/plugin.rs index c2241d62..17f2d2e7 100644 --- a/clients/rust/src/generated/types/plugin.rs +++ b/clients/rust/src/generated/types/plugin.rs @@ -6,6 +6,7 @@ //! use crate::generated::types::Delegate; +use crate::generated::types::Royalties; use borsh::BorshDeserialize; use borsh::BorshSerialize; @@ -13,6 +14,6 @@ use borsh::BorshSerialize; #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum Plugin { Reserved, - Royalties, + Royalties(Royalties), Delegate(Delegate), } diff --git a/clients/rust/src/generated/types/plugin_type.rs b/clients/rust/src/generated/types/plugin_type.rs new file mode 100644 index 00000000..5a846ec4 --- /dev/null +++ b/clients/rust/src/generated/types/plugin_type.rs @@ -0,0 +1,17 @@ +//! This code was AUTOGENERATED using the kinobi library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun kinobi to update it. +//! +//! [https://github.com/metaplex-foundation/kinobi] +//! + +use borsh::BorshDeserialize; +use borsh::BorshSerialize; + +#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq, PartialOrd, Hash)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub enum PluginType { + Reserved, + Royalties, + Delegate, +} diff --git a/clients/rust/src/generated/types/registry_record.rs b/clients/rust/src/generated/types/registry_record.rs index 741601f8..1f90655e 100644 --- a/clients/rust/src/generated/types/registry_record.rs +++ b/clients/rust/src/generated/types/registry_record.rs @@ -5,7 +5,7 @@ //! [https://github.com/metaplex-foundation/kinobi] //! -use crate::generated::types::Key; +use crate::generated::types::PluginType; use crate::generated::types::RegistryData; use borsh::BorshDeserialize; use borsh::BorshSerialize; @@ -13,6 +13,6 @@ use borsh::BorshSerialize; #[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct RegistryRecord { - pub key: Key, + pub plugin_type: PluginType, pub data: RegistryData, } diff --git a/idls/mpl_asset_program.json b/idls/mpl_asset_program.json index 33fbe564..96e2ae5a 100644 --- a/idls/mpl_asset_program.json +++ b/idls/mpl_asset_program.json @@ -828,9 +828,9 @@ "kind": "struct", "fields": [ { - "name": "key", + "name": "pluginType", "type": { - "defined": "Key" + "defined": "PluginType" } }, { @@ -883,12 +883,6 @@ "type": { "kind": "struct", "fields": [ - { - "name": "key", - "type": { - "defined": "Key" - } - }, { "name": "frozen", "type": "bool" @@ -1091,7 +1085,12 @@ "name": "Reserved" }, { - "name": "Royalties" + "name": "Royalties", + "fields": [ + { + "defined": "Royalties" + } + ] }, { "name": "Delegate", @@ -1104,6 +1103,23 @@ ] } }, + { + "name": "PluginType", + "type": { + "kind": "enum", + "variants": [ + { + "name": "Reserved" + }, + { + "name": "Royalties" + }, + { + "name": "Delegate" + } + ] + } + }, { "name": "DataState", "type": { @@ -1218,20 +1234,11 @@ { "name": "HashedAsset" }, - { - "name": "Collection" - }, - { - "name": "HashedCollection" - }, { "name": "PluginHeader" }, { "name": "PluginRegistry" - }, - { - "name": "Delegate" } ] } diff --git a/programs/mpl-asset/src/plugins/delegate.rs b/programs/mpl-asset/src/plugins/delegate.rs index 0dc05bb2..d475bdaa 100644 --- a/programs/mpl-asset/src/plugins/delegate.rs +++ b/programs/mpl-asset/src/plugins/delegate.rs @@ -1,23 +1,16 @@ use borsh::{BorshDeserialize, BorshSerialize}; -use crate::{ - state::Key, - state::{DataBlob, SolanaAccount}, -}; +use crate::state::DataBlob; #[repr(C)] -#[derive(Clone, BorshSerialize, BorshDeserialize, Debug, PartialEq, Eq)] +#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, Debug, PartialEq, Eq)] pub struct Delegate { - pub key: Key, // 1 pub frozen: bool, // 1 } impl Delegate { pub fn new() -> Self { - Self { - key: Key::Delegate, - frozen: false, - } + Self { frozen: false } } } @@ -29,16 +22,10 @@ impl Default for Delegate { impl DataBlob for Delegate { fn get_initial_size() -> usize { - 2 + 1 } fn get_size(&self) -> usize { - 2 - } -} - -impl SolanaAccount for Delegate { - fn key() -> crate::state::Key { - Key::Delegate + 1 } } diff --git a/programs/mpl-asset/src/plugins/mod.rs b/programs/mpl-asset/src/plugins/mod.rs index 2f476a07..83caa55d 100644 --- a/programs/mpl-asset/src/plugins/mod.rs +++ b/programs/mpl-asset/src/plugins/mod.rs @@ -8,20 +8,51 @@ pub use delegate::*; pub use royalties::*; use shank::ShankAccount; +use solana_program::{ + account_info::AccountInfo, entrypoint::ProgramResult, msg, program_error::ProgramError, +}; pub use utils::*; use borsh::{BorshDeserialize, BorshSerialize}; -use crate::state::{Authority, DataBlob, Key, SolanaAccount}; +use crate::{ + error::MplAssetError, + state::{Authority, DataBlob, Key, SolanaAccount}, +}; #[repr(u16)] #[derive(Clone, Debug, BorshSerialize, BorshDeserialize, Eq, PartialEq)] pub enum Plugin { Reserved, - Royalties, + Royalties(Royalties), Delegate(Delegate), } +#[repr(u16)] +#[derive(Clone, Copy, Debug, BorshSerialize, BorshDeserialize, Eq, PartialEq)] +pub enum PluginType { + Reserved, + Royalties, + Delegate, +} + +impl Plugin { + pub fn load(account: &AccountInfo, offset: usize) -> Result { + let mut bytes: &[u8] = &(*account.data).borrow()[offset..]; + Self::deserialize(&mut bytes).map_err(|error| { + msg!("Error: {}", error); + MplAssetError::DeserializationError.into() + }) + } + + pub fn save(&self, account: &AccountInfo, offset: usize) -> ProgramResult { + borsh::to_writer(&mut account.data.borrow_mut()[offset..], self).map_err(|error| { + msg!("Error: {}", error); + MplAssetError::SerializationError.into() + }) + } +} + #[repr(C)] #[derive(Clone, BorshSerialize, BorshDeserialize, Debug)] pub struct RegistryData { @@ -32,7 +63,7 @@ pub struct RegistryData { #[repr(C)] #[derive(Clone, BorshSerialize, BorshDeserialize, Debug)] pub struct RegistryRecord { - pub key: Key, + pub plugin_type: PluginType, pub data: RegistryData, } diff --git a/programs/mpl-asset/src/plugins/royalties.rs b/programs/mpl-asset/src/plugins/royalties.rs index b94375f9..10e5d90b 100644 --- a/programs/mpl-asset/src/plugins/royalties.rs +++ b/programs/mpl-asset/src/plugins/royalties.rs @@ -1,13 +1,13 @@ use borsh::{BorshDeserialize, BorshSerialize}; use solana_program::pubkey::Pubkey; -#[derive(Clone, BorshSerialize, BorshDeserialize, Debug)] +#[derive(Clone, BorshSerialize, BorshDeserialize, Debug, PartialEq, Eq)] pub struct Creator { address: Pubkey, verified: bool, } -#[derive(Clone, BorshSerialize, BorshDeserialize, Debug)] +#[derive(Clone, BorshSerialize, BorshDeserialize, Debug, Eq, PartialEq)] pub struct Royalties { creators: Vec, auth_rules: Pubkey, diff --git a/programs/mpl-asset/src/plugins/utils.rs b/programs/mpl-asset/src/plugins/utils.rs index d4a45ef7..685a0b7e 100644 --- a/programs/mpl-asset/src/plugins/utils.rs +++ b/programs/mpl-asset/src/plugins/utils.rs @@ -2,6 +2,7 @@ use borsh::{BorshDeserialize, BorshSerialize}; use mpl_utils::resize_or_reallocate_account_raw; use solana_program::{ account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError, + program_memory::sol_memcpy, }; use crate::{ @@ -9,7 +10,7 @@ use crate::{ state::{Asset, Authority, DataBlob, Key, PluginHeader, SolanaAccount}, }; -use super::{Plugin, PluginRegistry, RegistryData, RegistryRecord}; +use super::{Plugin, PluginRegistry, PluginType, RegistryData, RegistryRecord}; /// Create plugin header and registry if it doesn't exist pub fn create_meta_idempotent<'a>( @@ -63,7 +64,7 @@ pub fn assert_plugins_initialized(account: &AccountInfo) -> ProgramResult { /// Fetch the plugin from the registry. pub fn fetch_plugin( account: &AccountInfo, - key: Key, + plugin_type: PluginType, ) -> Result<(Vec, Plugin, usize), ProgramError> { let mut bytes: &[u8] = &(*account.data).borrow(); let asset = Asset::deserialize(&mut bytes)?; @@ -72,27 +73,36 @@ pub fn fetch_plugin( let PluginRegistry { registry, .. } = PluginRegistry::load(account, header.plugin_registry_offset)?; + solana_program::msg!("{:?}", registry); + // Find the plugin in the registry. let plugin_data = registry .iter() .find( |RegistryRecord { - key: plugin_key, + plugin_type: plugin_type_iter, data: _, - }| *plugin_key == key, + }| *plugin_type_iter == plugin_type, + ) + .map( + |RegistryRecord { + plugin_type: _, + data, + }| data, ) - .map(|RegistryRecord { key: _, data }| data) .ok_or(MplAssetError::PluginNotFound)?; + solana_program::msg!("Deserialize plugin at offset"); // Deserialize the plugin. let plugin = Plugin::deserialize(&mut &(*account.data).borrow()[plugin_data.offset..])?; + solana_program::msg!("Return plugin"); // Return the plugin and its authorities. Ok((plugin_data.authorities.clone(), plugin, plugin_data.offset)) } /// Create plugin header and registry if it doesn't exist -pub fn list_plugins(account: &AccountInfo) -> Result, ProgramError> { +pub fn list_plugins(account: &AccountInfo) -> Result, ProgramError> { let mut bytes: &[u8] = &(*account.data).borrow(); let asset = Asset::deserialize(&mut bytes)?; @@ -102,7 +112,7 @@ pub fn list_plugins(account: &AccountInfo) -> Result, ProgramError> { Ok(registry .iter() - .map(|registry_record| registry_record.key) + .map(|registry_record| registry_record.plugin_type) .collect()) } @@ -123,21 +133,23 @@ pub fn add_plugin_or_authority<'a>( let mut header = PluginHeader::load(account, asset.get_size())?; let mut plugin_registry = PluginRegistry::load(account, header.plugin_registry_offset)?; - let (plugin_size, key) = match plugin { + let plugin_type = match plugin { Plugin::Reserved => return Err(MplAssetError::InvalidPlugin.into()), - Plugin::Royalties => todo!(), - Plugin::Delegate(delegate) => (delegate.get_size(), Key::Delegate), + Plugin::Royalties(_) => PluginType::Royalties, + Plugin::Delegate(_) => PluginType::Delegate, }; + let plugin_data = plugin.try_to_vec()?; + let plugin_size = plugin_data.len(); let authority_bytes = authority.try_to_vec()?; if let Some(RegistryRecord { - key: _, + plugin_type: _, data: registry_data, }) = plugin_registry.registry.iter_mut().find( |RegistryRecord { - key: search_key, + plugin_type: type_iter, data: _, - }| search_key == &key, + }| type_iter == &plugin_type, ) { registry_data.authorities.push(authority.clone()); @@ -170,7 +182,7 @@ pub fn add_plugin_or_authority<'a>( header.plugin_registry_offset = new_registry_offset; plugin_registry.registry.push(RegistryRecord { - key, + plugin_type, data: registry_data.clone(), }); @@ -182,12 +194,7 @@ pub fn add_plugin_or_authority<'a>( resize_or_reallocate_account_raw(account, payer, system_program, new_size)?; header.save(account, asset.get_size())?; - match plugin { - Plugin::Reserved => return Err(MplAssetError::InvalidPlugin.into()), - Plugin::Royalties => todo!(), - Plugin::Delegate(delegate) => delegate.save(account, old_registry_offset)?, - }; - + plugin.save(account, old_registry_offset)?; plugin_registry.save(account, new_registry_offset)?; } diff --git a/programs/mpl-asset/src/processor/freeze.rs b/programs/mpl-asset/src/processor/freeze.rs index f868a591..872c8eee 100644 --- a/programs/mpl-asset/src/processor/freeze.rs +++ b/programs/mpl-asset/src/processor/freeze.rs @@ -7,8 +7,7 @@ use solana_program::{ use crate::{ error::MplAssetError, instruction::accounts::FreezeAccounts, - plugins::{fetch_plugin, Delegate, Plugin}, - state::{Key, SolanaAccount}, + plugins::{fetch_plugin, Delegate, Plugin, PluginType}, utils::assert_authority, }; @@ -22,7 +21,7 @@ pub(crate) fn freeze<'a>(accounts: &'a [AccountInfo<'a>], _args: FreezeArgs) -> assert_signer(ctx.accounts.delegate)?; let (authorities, mut plugin, offset) = - fetch_plugin(ctx.accounts.asset_address, Key::Delegate)?; + fetch_plugin(ctx.accounts.asset_address, PluginType::Delegate)?; assert_authority( ctx.accounts.asset_address, @@ -38,7 +37,7 @@ pub(crate) fn freeze<'a>(accounts: &'a [AccountInfo<'a>], _args: FreezeArgs) -> _ => Err(MplAssetError::InvalidPlugin.into()), }?; - delegate.save(ctx.accounts.asset_address, offset)?; + Plugin::Delegate(*delegate).save(ctx.accounts.asset_address, offset)?; Ok(()) } diff --git a/programs/mpl-asset/src/processor/thaw.rs b/programs/mpl-asset/src/processor/thaw.rs index a39f76ea..3ca6ffd0 100644 --- a/programs/mpl-asset/src/processor/thaw.rs +++ b/programs/mpl-asset/src/processor/thaw.rs @@ -7,8 +7,7 @@ use solana_program::{ use crate::{ error::MplAssetError, instruction::accounts::ThawAccounts, - plugins::{fetch_plugin, Delegate, Plugin}, - state::{Key, SolanaAccount}, + plugins::{fetch_plugin, Delegate, Plugin, PluginType}, utils::assert_authority, }; @@ -22,7 +21,7 @@ pub(crate) fn thaw<'a>(accounts: &'a [AccountInfo<'a>], _args: ThawArgs) -> Prog assert_signer(ctx.accounts.delegate)?; let (authorities, mut plugin, offset) = - fetch_plugin(ctx.accounts.asset_address, Key::Delegate)?; + fetch_plugin(ctx.accounts.asset_address, PluginType::Delegate)?; assert_authority( ctx.accounts.asset_address, @@ -38,7 +37,7 @@ pub(crate) fn thaw<'a>(accounts: &'a [AccountInfo<'a>], _args: ThawArgs) -> Prog _ => Err(MplAssetError::InvalidPlugin.into()), }?; - delegate.save(ctx.accounts.asset_address, offset)?; + Plugin::Delegate(*delegate).save(ctx.accounts.asset_address, offset)?; Ok(()) } diff --git a/programs/mpl-asset/src/processor/transfer.rs b/programs/mpl-asset/src/processor/transfer.rs index 0b8bb62d..b90af136 100644 --- a/programs/mpl-asset/src/processor/transfer.rs +++ b/programs/mpl-asset/src/processor/transfer.rs @@ -7,7 +7,7 @@ use solana_program::{ use crate::{ error::MplAssetError, instruction::accounts::TransferAccounts, - plugins::{fetch_plugin, Plugin}, + plugins::{fetch_plugin, Plugin, PluginType}, state::{Asset, Compressible, CompressionProof, DataBlob, HashedAsset, Key, SolanaAccount}, utils::{assert_authority, load_key}, }; @@ -48,9 +48,11 @@ pub(crate) fn transfer<'a>(accounts: &'a [AccountInfo<'a>], args: TransferArgs) let mut authority_check: Result<(), ProgramError> = Err(MplAssetError::InvalidAuthority.into()); if asset.get_size() != ctx.accounts.asset_address.data_len() { + solana_program::msg!("Fetch Plugin"); let (authorities, plugin, _) = - fetch_plugin(ctx.accounts.asset_address, Key::Delegate)?; + fetch_plugin(ctx.accounts.asset_address, PluginType::Delegate)?; + solana_program::msg!("Assert authority"); authority_check = assert_authority( ctx.accounts.asset_address, ctx.accounts.authority, diff --git a/programs/mpl-asset/src/state/mod.rs b/programs/mpl-asset/src/state/mod.rs index 756f67ad..c93af589 100644 --- a/programs/mpl-asset/src/state/mod.rs +++ b/programs/mpl-asset/src/state/mod.rs @@ -12,7 +12,6 @@ mod traits; pub use traits::*; use borsh::{BorshDeserialize, BorshSerialize}; -use solana_program::program_error::ProgramError; use solana_program::pubkey::Pubkey; use crate::plugins::Plugin; @@ -52,11 +51,8 @@ pub enum Key { Uninitialized, Asset, HashedAsset, - Collection, - HashedCollection, PluginHeader, PluginRegistry, - Delegate, } impl Key {