From 8377321cca848069341a1e26adfea1fc8b29d6ba Mon Sep 17 00:00:00 2001 From: blockiosaurus Date: Wed, 28 Feb 2024 09:39:24 -0500 Subject: [PATCH] Dropping size to a u32. --- .../js/src/generated/accounts/pluginHeader.ts | 14 +++--- .../generated/types/externalPluginRecord.ts | 8 +-- .../js/src/generated/types/registryRecord.ts | 8 +-- clients/js/test/addAuthority.test.ts | 4 +- clients/js/test/addPlugin.test.ts | 4 +- .../js/test/collectionUpdateDelegate.test.ts | 10 ++-- clients/js/test/create.test.ts | 4 +- clients/js/test/createCollection.test.ts | 12 ++--- clients/js/test/delegate.test.ts | 8 +-- clients/js/test/delegateTransfer.test.ts | 4 +- clients/js/test/removeAuthority.test.ts | 12 ++--- clients/js/test/removePlugin.test.ts | 6 +-- clients/js/test/update.test.ts | 8 +-- .../src/generated/accounts/plugin_header.rs | 4 +- .../generated/types/external_plugin_record.rs | 2 +- .../src/generated/types/registry_record.rs | 2 +- idls/mpl_core_program.json | 6 +-- programs/mpl-core/src/plugins/mod.rs | 16 +++--- .../mpl-core/src/plugins/plugin_header.rs | 6 +-- .../mpl-core/src/plugins/plugin_registry.rs | 4 +- programs/mpl-core/src/plugins/utils.rs | 49 ++++++++++--------- programs/mpl-core/src/processor/compress.rs | 3 +- programs/mpl-core/src/processor/update.rs | 10 ++-- programs/mpl-core/src/state/traits.rs | 18 ++++--- programs/mpl-core/src/utils.rs | 2 +- 25 files changed, 115 insertions(+), 109 deletions(-) diff --git a/clients/js/src/generated/accounts/pluginHeader.ts b/clients/js/src/generated/accounts/pluginHeader.ts index 97814bc5..eabab666 100644 --- a/clients/js/src/generated/accounts/pluginHeader.ts +++ b/clients/js/src/generated/accounts/pluginHeader.ts @@ -19,19 +19,19 @@ import { gpaBuilder, publicKey as toPublicKey, } from '@metaplex-foundation/umi'; -import { Serializer, struct, u64 } from '@metaplex-foundation/umi/serializers'; +import { Serializer, struct, u32 } from '@metaplex-foundation/umi/serializers'; import { Key, KeyArgs, getKeySerializer } from '../types'; export type PluginHeader = Account; export type PluginHeaderAccountData = { key: Key; - pluginRegistryOffset: bigint; + pluginRegistryOffset: number; }; export type PluginHeaderAccountDataArgs = { key: KeyArgs; - pluginRegistryOffset: number | bigint; + pluginRegistryOffset: number; }; export function getPluginHeaderAccountDataSerializer(): Serializer< @@ -41,7 +41,7 @@ export function getPluginHeaderAccountDataSerializer(): Serializer< return struct( [ ['key', getKeySerializer()], - ['pluginRegistryOffset', u64()], + ['pluginRegistryOffset', u32()], ], { description: 'PluginHeaderAccountData' } ) as Serializer; @@ -113,9 +113,9 @@ export function getPluginHeaderGpaBuilder( 'CoREzp6dAdLVRKf3EM5tWrsXM2jQwRFeu5uhzsAyjYXL' ); return gpaBuilder(context, programId) - .registerFields<{ key: KeyArgs; pluginRegistryOffset: number | bigint }>({ + .registerFields<{ key: KeyArgs; pluginRegistryOffset: number }>({ key: [0, getKeySerializer()], - pluginRegistryOffset: [1, u64()], + pluginRegistryOffset: [1, u32()], }) .deserializeUsing((account) => deserializePluginHeader(account) @@ -123,5 +123,5 @@ export function getPluginHeaderGpaBuilder( } export function getPluginHeaderSize(): number { - return 9; + return 5; } diff --git a/clients/js/src/generated/types/externalPluginRecord.ts b/clients/js/src/generated/types/externalPluginRecord.ts index cf4101c5..f7d5f6fa 100644 --- a/clients/js/src/generated/types/externalPluginRecord.ts +++ b/clients/js/src/generated/types/externalPluginRecord.ts @@ -6,14 +6,14 @@ * @see https://github.com/metaplex-foundation/kinobi */ -import { Serializer, struct, u64 } from '@metaplex-foundation/umi/serializers'; +import { Serializer, struct, u32 } from '@metaplex-foundation/umi/serializers'; import { Authority, AuthorityArgs, getAuthoritySerializer } from '.'; -export type ExternalPluginRecord = { authority: Authority; offset: bigint }; +export type ExternalPluginRecord = { authority: Authority; offset: number }; export type ExternalPluginRecordArgs = { authority: AuthorityArgs; - offset: number | bigint; + offset: number; }; export function getExternalPluginRecordSerializer(): Serializer< @@ -23,7 +23,7 @@ export function getExternalPluginRecordSerializer(): Serializer< return struct( [ ['authority', getAuthoritySerializer()], - ['offset', u64()], + ['offset', u32()], ], { description: 'ExternalPluginRecord' } ) as Serializer; diff --git a/clients/js/src/generated/types/registryRecord.ts b/clients/js/src/generated/types/registryRecord.ts index fbeafafa..e8d1dc35 100644 --- a/clients/js/src/generated/types/registryRecord.ts +++ b/clients/js/src/generated/types/registryRecord.ts @@ -10,7 +10,7 @@ import { Serializer, array, struct, - u64, + u32, } from '@metaplex-foundation/umi/serializers'; import { Authority, @@ -24,13 +24,13 @@ import { export type RegistryRecord = { pluginType: PluginType; authorities: Array; - offset: bigint; + offset: number; }; export type RegistryRecordArgs = { pluginType: PluginTypeArgs; authorities: Array; - offset: number | bigint; + offset: number; }; export function getRegistryRecordSerializer(): Serializer< @@ -41,7 +41,7 @@ export function getRegistryRecordSerializer(): Serializer< [ ['pluginType', getPluginTypeSerializer()], ['authorities', array(getAuthoritySerializer())], - ['offset', u64()], + ['offset', u32()], ], { description: 'RegistryRecord' } ) as Serializer; diff --git a/clients/js/test/addAuthority.test.ts b/clients/js/test/addAuthority.test.ts index 16fc03c9..e9921a43 100644 --- a/clients/js/test/addAuthority.test.ts +++ b/clients/js/test/addAuthority.test.ts @@ -69,14 +69,14 @@ test('it can add an authority to a plugin', async (t) => { uri: 'https://example.com/bread', pluginHeader: { key: 3, - pluginRegistryOffset: BigInt(119), + pluginRegistryOffset: 115, }, pluginRegistry: { key: 4, registry: [ { pluginType: 2, - offset: BigInt(117), + offset: 113, authorities: [ { __kind: 'Owner' }, { __kind: 'Pubkey', address: delegateAddress.publicKey }, diff --git a/clients/js/test/addPlugin.test.ts b/clients/js/test/addPlugin.test.ts index d458044f..d667455e 100644 --- a/clients/js/test/addPlugin.test.ts +++ b/clients/js/test/addPlugin.test.ts @@ -55,14 +55,14 @@ test('it can add a plugin to an asset', async (t) => { uri: 'https://example.com/bread', pluginHeader: { key: 3, - pluginRegistryOffset: BigInt(119), + pluginRegistryOffset: 115, }, pluginRegistry: { key: 4, registry: [ { pluginType: 2, - offset: BigInt(117), + offset: 113, authorities: [{ __kind: 'Owner' }], }, ], diff --git a/clients/js/test/collectionUpdateDelegate.test.ts b/clients/js/test/collectionUpdateDelegate.test.ts index 1ea68ccf..d1f04efe 100644 --- a/clients/js/test/collectionUpdateDelegate.test.ts +++ b/clients/js/test/collectionUpdateDelegate.test.ts @@ -57,14 +57,14 @@ test('it can create a new asset with a collection if it is the collection update uri: 'https://example.com/bread', pluginHeader: { key: 3, - pluginRegistryOffset: BigInt(105), + pluginRegistryOffset: 101, }, pluginRegistry: { key: 4, registry: [ { pluginType: PluginType.UpdateDelegate, - offset: BigInt(104), + offset: 100, authorities: [ { __kind: 'UpdateAuthority' }, { __kind: 'Pubkey', address: updateDelegate.publicKey } @@ -102,7 +102,7 @@ test('it can create a new asset with a collection if it is the collection update }).sendAndConfirm(umi); const asset = await fetchAssetWithPlugins(umi, assetAddress.publicKey); - console.log("Asset State:", asset); + // console.log("Asset State:", asset); t.like(asset, { publicKey: assetAddress.publicKey, updateAuthority: umi.identity.publicKey, @@ -111,14 +111,14 @@ test('it can create a new asset with a collection if it is the collection update uri: 'https://example.com/bread', pluginHeader: { key: 3, - pluginRegistryOffset: BigInt(151), + pluginRegistryOffset: 147, }, pluginRegistry: { key: 4, registry: [ { pluginType: PluginType.Collection, - offset: BigInt(117), + offset: 113, authorities: [{ __kind: 'UpdateAuthority' }], }, ], diff --git a/clients/js/test/create.test.ts b/clients/js/test/create.test.ts index 125a5a89..1691af75 100644 --- a/clients/js/test/create.test.ts +++ b/clients/js/test/create.test.ts @@ -102,14 +102,14 @@ test('it can create a new asset with plugins', async (t) => { uri: 'https://example.com/bread', pluginHeader: { key: 3, - pluginRegistryOffset: BigInt(119), + pluginRegistryOffset: 115, }, pluginRegistry: { key: 4, registry: [ { pluginType: 2, - offset: BigInt(117), + offset: 113, authorities: [{ __kind: 'Owner' }], }, ], diff --git a/clients/js/test/createCollection.test.ts b/clients/js/test/createCollection.test.ts index 4a0e6567..d2a136ce 100644 --- a/clients/js/test/createCollection.test.ts +++ b/clients/js/test/createCollection.test.ts @@ -60,14 +60,14 @@ test('it can create a new collection with plugins', async (t) => { uri: 'https://example.com/bread', pluginHeader: { key: 3, - pluginRegistryOffset: BigInt(106), + pluginRegistryOffset: 102, }, pluginRegistry: { key: 4, registry: [ { pluginType: 2, - offset: BigInt(104), + offset: 100, authorities: [{ __kind: 'Owner' }], }, ], @@ -124,14 +124,14 @@ test('it can create a new asset with a collection', async (t) => { uri: 'https://example.com/bread', pluginHeader: { key: 3, - pluginRegistryOffset: BigInt(151), + pluginRegistryOffset: 147, }, pluginRegistry: { key: 4, registry: [ { pluginType: 5, - offset: BigInt(117), + offset: 113, authorities: [{ __kind: 'UpdateAuthority' }], }, ], @@ -173,14 +173,14 @@ test('it cannot create a new asset with a collection if it is not the collection uri: 'https://example.com/bread', pluginHeader: { key: 3, - pluginRegistryOffset: BigInt(106), + pluginRegistryOffset: 102, }, pluginRegistry: { key: 4, registry: [ { pluginType: 2, - offset: BigInt(104), + offset: 100, authorities: [{ __kind: 'Owner' }], }, ], diff --git a/clients/js/test/delegate.test.ts b/clients/js/test/delegate.test.ts index 3a4ac761..43c290b7 100644 --- a/clients/js/test/delegate.test.ts +++ b/clients/js/test/delegate.test.ts @@ -55,14 +55,14 @@ test('it can delegate a new authority', async (t) => { uri: 'https://example.com/bread', pluginHeader: { key: 3, - pluginRegistryOffset: BigInt(119), + pluginRegistryOffset: 115, }, pluginRegistry: { key: 4, registry: [ { pluginType: 2, - offset: BigInt(117), + offset: 113, authorities: [ { __kind: 'Owner' }, { __kind: 'Pubkey', address: delegateAddress.publicKey }, @@ -135,14 +135,14 @@ test('a delegate can freeze the token', async (t) => { uri: 'https://example.com/bread', pluginHeader: { key: 3, - pluginRegistryOffset: BigInt(119), + pluginRegistryOffset: 115, }, pluginRegistry: { key: 4, registry: [ { pluginType: 2, - offset: BigInt(117), + offset: 113, authorities: [ { __kind: 'Owner' }, { __kind: 'Pubkey', address: delegateAddress.publicKey }, diff --git a/clients/js/test/delegateTransfer.test.ts b/clients/js/test/delegateTransfer.test.ts index 38bfe501..167b2d7d 100644 --- a/clients/js/test/delegateTransfer.test.ts +++ b/clients/js/test/delegateTransfer.test.ts @@ -62,14 +62,14 @@ test('a delegate can transfer the asset', async (t) => { uri: 'https://example.com/bread', pluginHeader: { key: 3, - pluginRegistryOffset: BigInt(118), + pluginRegistryOffset: 114, }, pluginRegistry: { key: 4, registry: [ { pluginType: PluginType.Transfer, - offset: BigInt(117), + offset: 113, authorities: [ { __kind: 'Owner' }, { __kind: 'Pubkey', address: delegateAddress.publicKey }, diff --git a/clients/js/test/removeAuthority.test.ts b/clients/js/test/removeAuthority.test.ts index 87d1f47f..f87a0c5f 100644 --- a/clients/js/test/removeAuthority.test.ts +++ b/clients/js/test/removeAuthority.test.ts @@ -70,14 +70,14 @@ test('it can remove an authority from a plugin', async (t) => { uri: 'https://example.com/bread', pluginHeader: { key: 3, - pluginRegistryOffset: BigInt(119), + pluginRegistryOffset: 115, }, pluginRegistry: { key: 4, registry: [ { pluginType: 2, - offset: BigInt(117), + offset: 113, authorities: [ { __kind: 'Owner' }, { __kind: 'Pubkey', address: delegateAddress.publicKey }, @@ -118,14 +118,14 @@ test('it can remove an authority from a plugin', async (t) => { uri: 'https://example.com/bread', pluginHeader: { key: 3, - pluginRegistryOffset: BigInt(119), + pluginRegistryOffset: 115, }, pluginRegistry: { key: 4, registry: [ { pluginType: 2, - offset: BigInt(117), + offset: 113, authorities: [{ __kind: 'Owner' }], }, ], @@ -193,14 +193,14 @@ test('it can remove the default authority from a plugin to make it immutable', a uri: 'https://example.com/bread', pluginHeader: { key: 3, - pluginRegistryOffset: BigInt(119), + pluginRegistryOffset: 115, }, pluginRegistry: { key: 4, registry: [ { pluginType: 2, - offset: BigInt(117), + offset: 113, authorities: [{ __kind: 'None' }], }, ], diff --git a/clients/js/test/removePlugin.test.ts b/clients/js/test/removePlugin.test.ts index 16da4e39..ea190653 100644 --- a/clients/js/test/removePlugin.test.ts +++ b/clients/js/test/removePlugin.test.ts @@ -57,14 +57,14 @@ test('it can remove a plugin from an asset', async (t) => { uri: 'https://example.com/bread', pluginHeader: { key: 3, - pluginRegistryOffset: BigInt(119), + pluginRegistryOffset: 115, }, pluginRegistry: { key: 4, registry: [ { pluginType: 2, - offset: BigInt(117), + offset: 113, authorities: [{ __kind: 'Owner' }], }, ], @@ -95,7 +95,7 @@ test('it can remove a plugin from an asset', async (t) => { uri: 'https://example.com/bread', pluginHeader: { key: 3, - pluginRegistryOffset: BigInt(117), + pluginRegistryOffset: 113, }, pluginRegistry: { key: 4, diff --git a/clients/js/test/update.test.ts b/clients/js/test/update.test.ts index 831f563f..2002fd27 100644 --- a/clients/js/test/update.test.ts +++ b/clients/js/test/update.test.ts @@ -113,14 +113,14 @@ test('it can update an asset with plugins to be larger', async (t) => { uri: 'https://example.com/bread2', pluginHeader: { key: 3, - pluginRegistryOffset: BigInt(122), + pluginRegistryOffset: 118, }, pluginRegistry: { key: 4, registry: [ { pluginType: 2, - offset: BigInt(120), + offset: 116, authorities: [{ __kind: 'Owner' }], }, ], @@ -175,14 +175,14 @@ test('it can update an asset with plugins to be smaller', async (t) => { uri: '', pluginHeader: { key: 3, - pluginRegistryOffset: BigInt(84), + pluginRegistryOffset: 80, }, pluginRegistry: { key: 4, registry: [ { pluginType: 2, - offset: BigInt(82), + offset: 78, authorities: [{ __kind: 'Owner' }], }, ], diff --git a/clients/rust/src/generated/accounts/plugin_header.rs b/clients/rust/src/generated/accounts/plugin_header.rs index f8bdd5aa..99f03cdb 100644 --- a/clients/rust/src/generated/accounts/plugin_header.rs +++ b/clients/rust/src/generated/accounts/plugin_header.rs @@ -13,11 +13,11 @@ use borsh::BorshSerialize; #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct PluginHeader { pub key: Key, - pub plugin_registry_offset: u64, + pub plugin_registry_offset: u32, } impl PluginHeader { - pub const LEN: usize = 9; + pub const LEN: usize = 5; #[inline(always)] pub fn from_bytes(data: &[u8]) -> Result { diff --git a/clients/rust/src/generated/types/external_plugin_record.rs b/clients/rust/src/generated/types/external_plugin_record.rs index c1734804..38082e6b 100644 --- a/clients/rust/src/generated/types/external_plugin_record.rs +++ b/clients/rust/src/generated/types/external_plugin_record.rs @@ -13,5 +13,5 @@ use borsh::BorshSerialize; #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ExternalPluginRecord { pub authority: Authority, - pub offset: u64, + pub offset: u32, } diff --git a/clients/rust/src/generated/types/registry_record.rs b/clients/rust/src/generated/types/registry_record.rs index 5aff06b9..ded20d35 100644 --- a/clients/rust/src/generated/types/registry_record.rs +++ b/clients/rust/src/generated/types/registry_record.rs @@ -15,5 +15,5 @@ use borsh::BorshSerialize; pub struct RegistryRecord { pub plugin_type: PluginType, pub authorities: Vec, - pub offset: u64, + pub offset: u32, } diff --git a/idls/mpl_core_program.json b/idls/mpl_core_program.json index 713a2052..a218bcf5 100644 --- a/idls/mpl_core_program.json +++ b/idls/mpl_core_program.json @@ -807,7 +807,7 @@ }, { "name": "pluginRegistryOffset", - "type": "u64" + "type": "u32" } ] } @@ -987,7 +987,7 @@ }, { "name": "offset", - "type": "u64" + "type": "u32" } ] } @@ -1005,7 +1005,7 @@ }, { "name": "offset", - "type": "u64" + "type": "u32" } ] } diff --git a/programs/mpl-core/src/plugins/mod.rs b/programs/mpl-core/src/plugins/mod.rs index 2fb92a73..362f1458 100644 --- a/programs/mpl-core/src/plugins/mod.rs +++ b/programs/mpl-core/src/plugins/mod.rs @@ -114,8 +114,8 @@ impl From<&Plugin> for PluginType { impl Plugin { /// Load and deserialize a plugin from an offset in the account. - pub fn load(account: &AccountInfo, offset: usize) -> Result { - let mut bytes: &[u8] = &(*account.data).borrow()[offset..]; + pub fn load(account: &AccountInfo, offset: u32) -> Result { + let mut bytes: &[u8] = &(*account.data).borrow()[(offset as usize)..]; Self::deserialize(&mut bytes).map_err(|error| { msg!("Error: {}", error); MplCoreError::DeserializationError.into() @@ -123,10 +123,12 @@ impl Plugin { } /// Save and serialize a plugin to an offset in the account. - 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); - MplCoreError::SerializationError.into() - }) + pub fn save(&self, account: &AccountInfo, offset: u32) -> ProgramResult { + borsh::to_writer(&mut account.data.borrow_mut()[(offset as usize)..], self).map_err( + |error| { + msg!("Error: {}", error); + MplCoreError::SerializationError.into() + }, + ) } } diff --git a/programs/mpl-core/src/plugins/plugin_header.rs b/programs/mpl-core/src/plugins/plugin_header.rs index b76abeb4..b4c7b40b 100644 --- a/programs/mpl-core/src/plugins/plugin_header.rs +++ b/programs/mpl-core/src/plugins/plugin_header.rs @@ -11,16 +11,16 @@ pub struct PluginHeader { /// The Discriminator of the header which doubles as a Plugin metadata version. pub key: Key, // 1 /// The offset to the plugin registry stored at the end of the account. - pub plugin_registry_offset: usize, // 8 + pub plugin_registry_offset: u32, // 4 } impl DataBlob for PluginHeader { fn get_initial_size() -> usize { - 1 + 8 + 1 + 4 } fn get_size(&self) -> usize { - 1 + 8 + 1 + 4 } } diff --git a/programs/mpl-core/src/plugins/plugin_registry.rs b/programs/mpl-core/src/plugins/plugin_registry.rs index 480ffd3e..a082009d 100644 --- a/programs/mpl-core/src/plugins/plugin_registry.rs +++ b/programs/mpl-core/src/plugins/plugin_registry.rs @@ -42,7 +42,7 @@ pub struct RegistryRecord { /// The authorities who have permission to utilize a plugin. pub authorities: Vec, /// The offset to the plugin in the account. - pub offset: usize, + pub offset: u32, } /// A simple type to store the mapping of external Plugin authority to Plugin data. @@ -52,5 +52,5 @@ pub struct ExternalPluginRecord { /// The authority of the external plugin. pub authority: Authority, /// The offset to the plugin in the account. - pub offset: usize, + pub offset: u32, } diff --git a/programs/mpl-core/src/plugins/utils.rs b/programs/mpl-core/src/plugins/utils.rs index 0fc4634e..22a77a8b 100644 --- a/programs/mpl-core/src/plugins/utils.rs +++ b/programs/mpl-core/src/plugins/utils.rs @@ -26,7 +26,7 @@ pub fn create_meta_idempotent<'a>( Asset::deserialize(&mut bytes)? }; - asset.get_size() + asset.get_size() as u32 } Key::Collection => { let collection = { @@ -34,17 +34,17 @@ pub fn create_meta_idempotent<'a>( CollectionData::deserialize(&mut bytes)? }; - collection.get_size() + collection.get_size() as u32 } _ => return Err(MplCoreError::IncorrectAccount.into()), }; // Check if the plugin header and registry exist. - if header_offset == account.data_len() { + if header_offset == account.data_len() as u32 { // They don't exist, so create them. let header = PluginHeader { key: Key::PluginHeader, - plugin_registry_offset: header_offset + PluginHeader::get_initial_size(), + plugin_registry_offset: header_offset + (PluginHeader::get_initial_size() as u32), }; let registry = PluginRegistry { key: Key::PluginRegistry, @@ -56,7 +56,7 @@ pub fn create_meta_idempotent<'a>( account, payer, system_program, - header.plugin_registry_offset + PluginRegistry::get_initial_size(), + (header.plugin_registry_offset as usize) + PluginRegistry::get_initial_size(), )?; header.save(account, header_offset)?; @@ -82,10 +82,10 @@ pub fn assert_plugins_initialized(account: &AccountInfo) -> ProgramResult { pub fn fetch_plugin( account: &AccountInfo, plugin_type: PluginType, -) -> Result<(Vec, Plugin, usize), ProgramError> { +) -> Result<(Vec, Plugin, u32), ProgramError> { let asset = Asset::load(account, 0)?; - let header = PluginHeader::load(account, asset.get_size())?; + let header = PluginHeader::load(account, asset.get_size() as u32)?; let PluginRegistry { registry, .. } = PluginRegistry::load(account, header.plugin_registry_offset)?; @@ -96,7 +96,8 @@ pub fn fetch_plugin( .ok_or(MplCoreError::PluginNotFound)?; // Deserialize the plugin. - let plugin = Plugin::deserialize(&mut &(*account.data).borrow()[registry_record.offset..])?; + let plugin = + Plugin::deserialize(&mut &(*account.data).borrow()[(registry_record.offset as usize)..])?; // Return the plugin and its authorities. Ok(( @@ -110,7 +111,7 @@ pub fn fetch_plugin( pub fn fetch_plugins(account: &AccountInfo) -> Result, ProgramError> { let asset = Asset::load(account, 0)?; - let header = PluginHeader::load(account, asset.get_size())?; + let header = PluginHeader::load(account, asset.get_size() as u32)?; let PluginRegistry { registry, .. } = PluginRegistry::load(account, header.plugin_registry_offset)?; @@ -121,7 +122,7 @@ pub fn fetch_plugins(account: &AccountInfo) -> Result, Progr pub fn list_plugins(account: &AccountInfo) -> Result, ProgramError> { let asset = Asset::load(account, 0)?; - let header = PluginHeader::load(account, asset.get_size())?; + let header = PluginHeader::load(account, asset.get_size() as u32)?; let PluginRegistry { registry, .. } = PluginRegistry::load(account, header.plugin_registry_offset)?; @@ -146,7 +147,7 @@ pub fn initialize_plugin<'a>( Asset::deserialize(&mut bytes)? }; - asset.get_size() + asset.get_size() as u32 } Key::Collection => { let collection = { @@ -154,18 +155,18 @@ pub fn initialize_plugin<'a>( CollectionData::deserialize(&mut bytes)? }; - collection.get_size() + collection.get_size() as u32 } _ => return Err(MplCoreError::IncorrectAccount.into()), }; //TODO: Bytemuck this. - let mut header = PluginHeader::load(account, header_offset)?; + let mut header = PluginHeader::load(account, header_offset as u32)?; let mut plugin_registry = PluginRegistry::load(account, header.plugin_registry_offset)?; let plugin_type = plugin.into(); let plugin_data = plugin.try_to_vec()?; - let plugin_size = plugin_data.len(); + let plugin_size = plugin_data.len() as u32; if plugin_registry .registry @@ -184,9 +185,9 @@ pub fn initialize_plugin<'a>( }; let size_increase = plugin_size - .checked_add(Key::get_initial_size()) + .checked_add(Key::get_initial_size() as u32) .ok_or(MplCoreError::NumericalOverflow)? - .checked_add(new_registry_record.try_to_vec()?.len()) + .checked_add(new_registry_record.try_to_vec()?.len() as u32) .ok_or(MplCoreError::NumericalOverflow)?; let new_registry_offset = header @@ -200,7 +201,7 @@ pub fn initialize_plugin<'a>( let new_size = account .data_len() - .checked_add(size_increase) + .checked_add(size_increase as usize) .ok_or(MplCoreError::NumericalOverflow)?; resize_or_reallocate_account_raw(account, payer, system_program, new_size)?; @@ -222,7 +223,7 @@ pub fn delete_plugin<'a>( system_program: &AccountInfo<'a>, ) -> ProgramResult { //TODO: Bytemuck this. - let mut header = PluginHeader::load(account, asset.get_size())?; + let mut header = PluginHeader::load(account, asset.get_size() as u32)?; let mut plugin_registry = PluginRegistry::load(account, header.plugin_registry_offset)?; if let Some(index) = plugin_registry @@ -246,7 +247,7 @@ pub fn delete_plugin<'a>( let serialized_plugin = plugin.try_to_vec()?; let next_plugin_offset = plugin_offset - .checked_add(serialized_plugin.len()) + .checked_add(serialized_plugin.len() as u32) .ok_or(MplCoreError::NumericalOverflow)?; let new_size = account @@ -258,24 +259,24 @@ pub fn delete_plugin<'a>( let new_offset = header .plugin_registry_offset - .checked_sub(serialized_plugin.len()) + .checked_sub(serialized_plugin.len() as u32) .ok_or(MplCoreError::NumericalOverflow)?; let data_to_move = header .plugin_registry_offset .checked_sub(new_offset) - .ok_or(MplCoreError::NumericalOverflow)?; + .ok_or(MplCoreError::NumericalOverflow)? as usize; //TODO: This is memory intensive, we should use memmove instead probably. - let src = account.data.borrow()[next_plugin_offset..].to_vec(); + let src = account.data.borrow()[(next_plugin_offset as usize)..].to_vec(); sol_memcpy( - &mut account.data.borrow_mut()[plugin_offset..], + &mut account.data.borrow_mut()[(plugin_offset as usize)..], &src, data_to_move, ); header.plugin_registry_offset = new_offset; - header.save(account, asset.get_size())?; + header.save(account, asset.get_size() as u32)?; plugin_registry.save(account, new_offset)?; diff --git a/programs/mpl-core/src/processor/compress.rs b/programs/mpl-core/src/processor/compress.rs index 9109d6d8..96e6eeb4 100644 --- a/programs/mpl-core/src/processor/compress.rs +++ b/programs/mpl-core/src/processor/compress.rs @@ -52,7 +52,8 @@ pub(crate) fn compress<'a>(accounts: &'a [AccountInfo<'a>], _args: CompressArgs) let plugin_authorities_hash = authorities.hash()?; let plugin = Plugin::deserialize( - &mut &(*ctx.accounts.asset_address.data).borrow()[record.offset..], + &mut &(*ctx.accounts.asset_address.data).borrow() + [(record.offset as usize)..], )?; let plugin_hash = plugin.hash()?; diff --git a/programs/mpl-core/src/processor/update.rs b/programs/mpl-core/src/processor/update.rs index 69d0338e..d08714c7 100644 --- a/programs/mpl-core/src/processor/update.rs +++ b/programs/mpl-core/src/processor/update.rs @@ -97,7 +97,7 @@ pub(crate) fn update<'a>(accounts: &'a [AccountInfo<'a>], args: UpdateArgs) -> P .checked_add(size_diff) .ok_or(MplCoreError::NumericalOverflow)?; let registry_offset = plugin_header.plugin_registry_offset; - plugin_header.plugin_registry_offset = new_registry_offset as usize; + plugin_header.plugin_registry_offset = new_registry_offset as u32; let plugin_offset = asset_size .checked_add(size_diff) @@ -108,7 +108,7 @@ pub(crate) fn update<'a>(accounts: &'a [AccountInfo<'a>], args: UpdateArgs) -> P // //TODO: This is memory intensive, we should use memmove instead probably. let src = ctx.accounts.asset_address.data.borrow() - [(plugin_offset as usize)..registry_offset] + [(plugin_offset as usize)..(registry_offset as usize)] .to_vec(); resize_or_reallocate_account_raw( @@ -124,7 +124,7 @@ pub(crate) fn update<'a>(accounts: &'a [AccountInfo<'a>], args: UpdateArgs) -> P src.len(), ); - plugin_header.save(ctx.accounts.asset_address, new_asset_size as usize)?; + plugin_header.save(ctx.accounts.asset_address, new_asset_size as u32)?; plugin_registry.registry = plugin_registry .registry .iter_mut() @@ -134,12 +134,12 @@ pub(crate) fn update<'a>(accounts: &'a [AccountInfo<'a>], args: UpdateArgs) -> P .ok_or(MplCoreError::NumericalOverflow)?; Ok(RegistryRecord { plugin_type: record.plugin_type, - offset: new_offset as usize, + offset: new_offset as u32, authorities: record.authorities.clone(), }) }) .collect::, MplCoreError>>()?; - plugin_registry.save(ctx.accounts.asset_address, new_registry_offset as usize)?; + plugin_registry.save(ctx.accounts.asset_address, new_registry_offset as u32)?; } else { resize_or_reallocate_account_raw( ctx.accounts.asset_address, diff --git a/programs/mpl-core/src/state/traits.rs b/programs/mpl-core/src/state/traits.rs index 97552db8..b6f6f444 100644 --- a/programs/mpl-core/src/state/traits.rs +++ b/programs/mpl-core/src/state/traits.rs @@ -19,14 +19,14 @@ pub trait SolanaAccount: BorshSerialize + BorshDeserialize { fn key() -> Key; /// Load the account from the given account info starting at the offset. - fn load(account: &AccountInfo, offset: usize) -> Result { - let key = load_key(account, offset)?; + fn load(account: &AccountInfo, offset: u32) -> Result { + let key = load_key(account, offset as usize)?; if key != Self::key() { return Err(MplCoreError::DeserializationError.into()); } - let mut bytes: &[u8] = &(*account.data).borrow()[offset..]; + let mut bytes: &[u8] = &(*account.data).borrow()[(offset as usize)..]; Self::deserialize(&mut bytes).map_err(|error| { msg!("Error: {}", error); MplCoreError::DeserializationError.into() @@ -34,11 +34,13 @@ pub trait SolanaAccount: BorshSerialize + BorshDeserialize { } /// Save the account to the given account info starting at the offset. - fn save(&self, account: &AccountInfo, offset: usize) -> ProgramResult { - borsh::to_writer(&mut account.data.borrow_mut()[offset..], self).map_err(|error| { - msg!("Error: {}", error); - MplCoreError::SerializationError.into() - }) + fn save(&self, account: &AccountInfo, offset: u32) -> ProgramResult { + borsh::to_writer(&mut account.data.borrow_mut()[(offset as usize)..], self).map_err( + |error| { + msg!("Error: {}", error); + MplCoreError::SerializationError.into() + }, + ) } } diff --git a/programs/mpl-core/src/utils.rs b/programs/mpl-core/src/utils.rs index 173ea5ed..af99286b 100644 --- a/programs/mpl-core/src/utils.rs +++ b/programs/mpl-core/src/utils.rs @@ -101,7 +101,7 @@ pub fn fetch_core_data( let asset = T::load(account, 0)?; if asset.get_size() != account.data_len() { - let plugin_header = PluginHeader::load(account, asset.get_size())?; + let plugin_header = PluginHeader::load(account, asset.get_size() as u32)?; let plugin_registry = PluginRegistry::load(account, plugin_header.plugin_registry_offset)?; Ok((asset, Some(plugin_header), Some(plugin_registry)))