Browse Source

spl: adding metadata account type (#2014)

Kevin Rodríguez 3 years ago
parent
commit
d3ee9b529a
2 changed files with 30 additions and 0 deletions
  1. 1 0
      CHANGELOG.md
  2. 29 0
      spl/src/metadata.rs

+ 1 - 0
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
 

+ 29 - 0
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<Self> {
+        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
+    }
+}