diff --git a/spl/src/metadata.rs b/spl/src/metadata.rs index 76f7c4ec1a..9172b86dab 100644 --- a/spl/src/metadata.rs +++ b/spl/src/metadata.rs @@ -819,6 +819,42 @@ impl anchor_lang::Owner for MasterEditionAccount { } } +#[derive(Clone, Debug, PartialEq)] +pub struct TokenRecordAccount(mpl_token_metadata::state::TokenRecord); + +impl TokenRecordAccount { + pub const LEN: usize = mpl_token_metadata::state::TOKEN_RECORD_SIZE; +} +impl anchor_lang::AccountDeserialize for TokenRecordAccount { + fn try_deserialize(buf: &mut &[u8]) -> anchor_lang::Result { + let tr = Self::try_deserialize_unchecked(buf)?; + if tr.key != mpl_token_metadata::state::TokenRecord::key() { + return Err(ErrorCode::AccountNotInitialized.into()); + } + Ok(tr) + } + + fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result { + let tr = mpl_token_metadata::state::TokenRecord::safe_deserialize(buf)?; + Ok(Self(tr)) + } +} + +impl anchor_lang::AccountSerialize for TokenRecordAccount {} + +impl anchor_lang::Owner for TokenRecordAccount { + fn owner() -> Pubkey { + ID + } +} + +impl Deref for TokenRecordAccount { + type Target = mpl_token_metadata::state::TokenRecord; + fn deref(&self) -> &Self::Target { + &self.0 + } +} + #[derive(Clone)] pub struct Metadata;