From 501678447ae3c97533fad5bcaaa9a799cedb67cb Mon Sep 17 00:00:00 2001 From: Kyle Espinola Date: Wed, 8 Feb 2023 15:20:13 +0100 Subject: [PATCH] feat: add master edition account deserialization to spl metadata --- CHANGELOG.md | 1 + spl/src/metadata.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18a2928e2d..35386a0209 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ The minor version will be incremented upon a breaking change and the patch versi ### Features +- spl: Add `MasterEditionAccount` account deserialization to spl metadata ([#2393](https://github.com/coral-xyz/anchor/pull/2393)). - lang: Add the `InitSpace` derive macro to automatically calculate the space at the initialization of an account ([#2346](https://github.com/coral-xyz/anchor/pull/2346)). - cli: Add `env` option to verifiable builds ([#2325](https://github.com/coral-xyz/anchor/pull/2325)). - cli: Add `idl close` command to close a program's IDL account ([#2329](https://github.com/coral-xyz/anchor/pull/2329)). diff --git a/spl/src/metadata.rs b/spl/src/metadata.rs index c0d660409b..3f52ac0caf 100644 --- a/spl/src/metadata.rs +++ b/spl/src/metadata.rs @@ -543,6 +543,35 @@ impl Deref for MetadataAccount { } } +#[derive(Clone, Debug, PartialEq)] +pub struct MasterEditionAccount(mpl_token_metadata::state::MasterEditionV2); + +impl MasterEditionAccount { + pub const LEN: usize = mpl_token_metadata::state::MAX_MASTER_EDITION_LEN; +} + +impl anchor_lang::AccountDeserialize for MasterEditionAccount { + fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result { + let result = mpl_token_metadata::state::MasterEditionV2::safe_deserialize(buf)?; + Ok(MasterEditionAccount(result)) + } +} + +impl Deref for MasterEditionAccount { + type Target = mpl_token_metadata::state::MasterEditionV2; + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl anchor_lang::AccountSerialize for MasterEditionAccount {} + +impl anchor_lang::Owner for MasterEditionAccount { + fn owner() -> Pubkey { + ID + } +} + #[derive(Clone)] pub struct Metadata;