diff --git a/programs/mpl-asset/src/state/mod.rs b/programs/mpl-asset/src/state/mod.rs index 1de949ad..6919c76e 100644 --- a/programs/mpl-asset/src/state/mod.rs +++ b/programs/mpl-asset/src/state/mod.rs @@ -1,6 +1,9 @@ mod asset; pub use asset::*; +mod plugin_header; +pub use plugin_header::*; + use borsh::{BorshDeserialize, BorshSerialize}; use solana_program::account_info::AccountInfo; use solana_program::entrypoint::ProgramResult; @@ -11,30 +14,6 @@ use solana_program::pubkey::Pubkey; use crate::error::MplAssetError; use crate::plugins::Plugin; -#[repr(C)] -#[derive(Clone, BorshSerialize, BorshDeserialize, Debug)] -pub struct AssetHeader { - pub version: u8, - pub plugin_map_offset: usize, -} - -impl AssetHeader { - pub fn load(account: &AccountInfo) -> Result { - let mut bytes: &[u8] = &(*account.data).borrow(); - AssetHeader::deserialize(&mut bytes).map_err(|error| { - msg!("Error: {}", error); - MplAssetError::DeserializationError.into() - }) - } - - pub fn save(&self, account: &AccountInfo) -> ProgramResult { - borsh::to_writer(&mut account.data.borrow_mut()[..], self).map_err(|error| { - msg!("Error: {}", error); - MplAssetError::SerializationError.into() - }) - } -} - #[repr(C)] #[derive(Clone, BorshSerialize, BorshDeserialize, Debug, Eq, PartialEq)] pub enum DataState { diff --git a/programs/mpl-asset/src/state/plugin_header.rs b/programs/mpl-asset/src/state/plugin_header.rs new file mode 100644 index 00000000..559ab856 --- /dev/null +++ b/programs/mpl-asset/src/state/plugin_header.rs @@ -0,0 +1,31 @@ +use borsh::{BorshDeserialize, BorshSerialize}; +use solana_program::account_info::AccountInfo; +use solana_program::entrypoint::ProgramResult; +use solana_program::msg; +use solana_program::program_error::ProgramError; + +use crate::error::MplAssetError; + +#[repr(C)] +#[derive(Clone, BorshSerialize, BorshDeserialize, Debug)] +pub struct PluginHeader { + pub version: u8, + pub plugin_map_offset: usize, +} + +impl PluginHeader { + pub fn load(account: &AccountInfo) -> Result { + let mut bytes: &[u8] = &(*account.data).borrow(); + PluginHeader::deserialize(&mut bytes).map_err(|error| { + msg!("Error: {}", error); + MplAssetError::DeserializationError.into() + }) + } + + pub fn save(&self, account: &AccountInfo) -> ProgramResult { + borsh::to_writer(&mut account.data.borrow_mut()[..], self).map_err(|error| { + msg!("Error: {}", error); + MplAssetError::SerializationError.into() + }) + } +}