From d3ee9b529ab886a0da02bf44872eef2d998f029a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Rodr=C3=ADguez?= <_@kevinrodriguez.io> Date: Sat, 13 Aug 2022 12:44:38 -0600 Subject: [PATCH] spl: adding metadata account type (#2014) --- CHANGELOG.md | 1 + spl/src/metadata.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95f543542..d057f8511 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ The minor version will be incremented upon a breaking change and the patch versi * client: Add `transaction` functions to RequestBuilder ([#1958](https://github.com/coral-xyz/anchor/pull/1958)). * spl: Add `create_metadata_accounts_v3` and `set_collection_size` wrappers ([#2119](https://github.com/coral-xyz/anchor/pull/2119)) +* spl: Add `MetadataAccount` account deserialization. ([#2014](https://github.com/coral-xyz/anchor/pull/2014)). ## [0.25.0] - 2022-07-05 diff --git a/spl/src/metadata.rs b/spl/src/metadata.rs index 971d88515..cef9504e5 100644 --- a/spl/src/metadata.rs +++ b/spl/src/metadata.rs @@ -266,3 +266,32 @@ pub struct SetCollectionSize<'info> { pub update_authority: AccountInfo<'info>, pub system_program: AccountInfo<'info>, } + +#[derive(Clone, Debug, PartialEq)] +pub struct MetadataAccount(mpl_token_metadata::state::Metadata); + +impl MetadataAccount { + pub const LEN: usize = mpl_token_metadata::state::MAX_METADATA_LEN; +} + +impl anchor_lang::AccountDeserialize for MetadataAccount { + fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result { + let result = mpl_token_metadata::state::Metadata::safe_deserialize(buf)?; + Ok(MetadataAccount(result)) + } +} + +impl anchor_lang::AccountSerialize for MetadataAccount {} + +impl anchor_lang::Owner for MetadataAccount { + fn owner() -> Pubkey { + ID + } +} + +impl Deref for MetadataAccount { + type Target = mpl_token_metadata::state::Metadata; + fn deref(&self) -> &Self::Target { + &self.0 + } +}