Skip to content

Commit

Permalink
Fix compress when there are no plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
danenbm committed Feb 22, 2024
1 parent e19d598 commit 9f6d2d2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
46 changes: 23 additions & 23 deletions programs/mpl-asset/src/processor/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ pub(crate) fn compress<'a>(accounts: &'a [AccountInfo<'a>], _args: CompressArgs)

// TODO: Delegated compress/decompress authority.

let mut plugin_hashes = vec![];
if asset.get_size() != ctx.accounts.asset_address.data_len() {
let registry_records = fetch_plugins(ctx.accounts.asset_address)?;

let mut plugin_hashes = Vec::with_capacity(registry_records.len());
for record in registry_records {
let authorities: AuthorityVec = record.data.authorities;
let plugin_authorities_hash = authorities.hash()?;
Expand All @@ -61,29 +61,29 @@ pub(crate) fn compress<'a>(accounts: &'a [AccountInfo<'a>], _args: CompressArgs)
plugin_hash,
});
}

let asset_hash = asset.hash()?;
let hashed_asset_schema = HashedAssetSchema {
asset_hash,
plugin_hashes,
};

let hashed_asset = HashedAsset::new(hashed_asset_schema.hash()?);
let serialized_data = hashed_asset.try_to_vec()?;

resize_or_reallocate_account_raw(
ctx.accounts.asset_address,
payer,
ctx.accounts.system_program,
serialized_data.len(),
)?;

sol_memcpy(
&mut ctx.accounts.asset_address.try_borrow_mut_data()?,
&serialized_data,
serialized_data.len(),
);
}

let asset_hash = asset.hash()?;
let hashed_asset_schema = HashedAssetSchema {
asset_hash,
plugin_hashes,
};

let hashed_asset = HashedAsset::new(hashed_asset_schema.hash()?);
let serialized_data = hashed_asset.try_to_vec()?;

resize_or_reallocate_account_raw(
ctx.accounts.asset_address,
payer,
ctx.accounts.system_program,
serialized_data.len(),
)?;

sol_memcpy(
&mut ctx.accounts.asset_address.try_borrow_mut_data()?,
&serialized_data,
serialized_data.len(),
);
}
Key::HashedAsset => return Err(MplAssetError::AlreadyCompressed.into()),
_ => return Err(MplAssetError::IncorrectAccount.into()),
Expand Down
6 changes: 2 additions & 4 deletions programs/mpl-asset/src/state/hashed_asset_schema.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use borsh::{BorshDeserialize, BorshSerialize};
use shank::ShankAccount;

use crate::state::Compressible;
use borsh::{BorshDeserialize, BorshSerialize};

#[derive(Clone, BorshSerialize, BorshDeserialize, Debug, PartialEq, Eq)]
pub struct PluginHash {
pub plugin_authorities_hash: [u8; 32],
pub plugin_hash: [u8; 32],
}

#[derive(Clone, BorshSerialize, BorshDeserialize, Debug, ShankAccount, PartialEq, Eq)]
#[derive(Clone, BorshSerialize, BorshDeserialize, Debug, PartialEq, Eq)]
pub struct HashedAssetSchema {
pub asset_hash: [u8; 32],
pub plugin_hashes: Vec<PluginHash>,
Expand Down
1 change: 0 additions & 1 deletion programs/mpl-asset/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub use hashed_asset_schema::*;
mod traits;
pub use traits::*;

use crate::plugins::Plugin;
use borsh::{BorshDeserialize, BorshSerialize};
use num_derive::{FromPrimitive, ToPrimitive};
use solana_program::pubkey::Pubkey;
Expand Down

0 comments on commit 9f6d2d2

Please sign in to comment.