From 245f184feca0df293f4ed35cf9d5e7d990d89d1a Mon Sep 17 00:00:00 2001 From: Michael Danenberg <56533526+danenbm@users.noreply.github.com> Date: Fri, 16 Feb 2024 20:30:54 -0800 Subject: [PATCH] Rename AssetHeader to PluginHeader --- programs/mpl-asset/src/state/mod.rs | 27 ++-------------- programs/mpl-asset/src/state/plugin_header.rs | 31 +++++++++++++++++++ 2 files changed, 34 insertions(+), 24 deletions(-) create mode 100644 programs/mpl-asset/src/state/plugin_header.rs 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() + }) + } +}