From 27073079ec5f5da60d801ca4c41d9484af13ff8b Mon Sep 17 00:00:00 2001 From: Kevin Rodriguez <_@kevinrodriguez.io> Date: Wed, 29 Jun 2022 12:49:19 -0600 Subject: [PATCH 01/11] spl: adding metadata account type --- spl/src/metadata.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/spl/src/metadata.rs b/spl/src/metadata.rs index 6835a03e47..399c6a2561 100644 --- a/spl/src/metadata.rs +++ b/spl/src/metadata.rs @@ -183,3 +183,31 @@ pub struct MintNewEditionFromMasterEditionViaToken<'info> { // pub metadata_mint: 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 { + meta_deser(buf).map(MetadataAccount).map_err(Into::into) + } +} + +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 + } +} From ec15412804eed2cc11594893f4352e2b140b1208 Mon Sep 17 00:00:00 2001 From: Kevin Rodriguez <_@kevinrodriguez.io> Date: Wed, 29 Jun 2022 13:32:01 -0600 Subject: [PATCH 02/11] adds missing import --- spl/src/metadata.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/spl/src/metadata.rs b/spl/src/metadata.rs index 399c6a2561..26d057e7aa 100644 --- a/spl/src/metadata.rs +++ b/spl/src/metadata.rs @@ -2,6 +2,7 @@ use anchor_lang::context::CpiContext; use anchor_lang::{Accounts, Result, ToAccountInfos}; use mpl_token_metadata::state::DataV2; use mpl_token_metadata::ID; +use mpl_token_metadata::deser::meta_deser; use solana_program::account_info::AccountInfo; use solana_program::pubkey::Pubkey; From c818955f3f4714fb773b51475d5f3901ba8ddce0 Mon Sep 17 00:00:00 2001 From: Kevin Rodriguez <_@kevinrodriguez.io> Date: Wed, 29 Jun 2022 13:41:46 -0600 Subject: [PATCH 03/11] updating changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25be89626a..39ed2fb50c 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 `MetadataAccount` account deserialization. ([#2014](https://github.com/coral-xyz/anchor/pull/2014)). * lang: Add `PartialEq` and `Eq` for `anchor_lang::Error` ([#1544](https://github.com/coral-xyz/anchor/pull/1544)). * cli: Add `--skip-build` to `anchor publish` ([#1786](https://github. com/project-serum/anchor/pull/1841)). From db965e7c5766127b6ac5bf59d19c4199bf0ca311 Mon Sep 17 00:00:00 2001 From: Kevin Rodriguez <_@kevinrodriguez.io> Date: Wed, 29 Jun 2022 13:46:38 -0600 Subject: [PATCH 04/11] chore: formatting --- spl/src/metadata.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spl/src/metadata.rs b/spl/src/metadata.rs index 26d057e7aa..44bcaecb60 100644 --- a/spl/src/metadata.rs +++ b/spl/src/metadata.rs @@ -1,8 +1,8 @@ use anchor_lang::context::CpiContext; use anchor_lang::{Accounts, Result, ToAccountInfos}; +use mpl_token_metadata::deser::meta_deser; use mpl_token_metadata::state::DataV2; use mpl_token_metadata::ID; -use mpl_token_metadata::deser::meta_deser; use solana_program::account_info::AccountInfo; use solana_program::pubkey::Pubkey; From f924917513343a63b0a498aee0fbb8deceffa1a7 Mon Sep 17 00:00:00 2001 From: Kevin Rodriguez <_@kevinrodriguez.io> Date: Fri, 1 Jul 2022 13:43:28 -0600 Subject: [PATCH 05/11] fix: moving to public api with proper checks --- spl/src/metadata.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spl/src/metadata.rs b/spl/src/metadata.rs index 44bcaecb60..bbe7c412c9 100644 --- a/spl/src/metadata.rs +++ b/spl/src/metadata.rs @@ -194,7 +194,8 @@ impl MetadataAccount { impl anchor_lang::AccountDeserialize for MetadataAccount { fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result { - meta_deser(buf).map(MetadataAccount).map_err(Into::into) + let result = mpl_token_metadata::state::Metadata::deserialize(buf)?; + return Ok(MetadataAccount(result)); } } From 8eadfa06e6ea8124bfae09f59b2d2caf39d98027 Mon Sep 17 00:00:00 2001 From: Kevin Rodriguez <_@kevinrodriguez.io> Date: Sat, 16 Jul 2022 13:14:51 -0600 Subject: [PATCH 06/11] feat: adds proper checks --- spl/Cargo.toml | 2 +- spl/src/metadata.rs | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/spl/Cargo.toml b/spl/Cargo.toml index 928309e815..890350ff64 100644 --- a/spl/Cargo.toml +++ b/spl/Cargo.toml @@ -24,4 +24,4 @@ serum_dex = { git = "https://github.com/project-serum/serum-dex", rev = "1be91f2 solana-program = "~1.9.13" spl-token = { version = "~3.2.0", features = ["no-entrypoint"], optional = true } spl-associated-token-account = { version = "~1.0.3", features = ["no-entrypoint"], optional = true } -mpl-token-metadata = { version = "1.2.7", optional = true, features = ["no-entrypoint"] } +mpl-token-metadata = { version = "1.3.2", optional = true, features = ["no-entrypoint"] } diff --git a/spl/src/metadata.rs b/spl/src/metadata.rs index bbe7c412c9..c0e569f1fb 100644 --- a/spl/src/metadata.rs +++ b/spl/src/metadata.rs @@ -1,7 +1,5 @@ use anchor_lang::context::CpiContext; use anchor_lang::{Accounts, Result, ToAccountInfos}; -use mpl_token_metadata::deser::meta_deser; -use mpl_token_metadata::state::DataV2; use mpl_token_metadata::ID; use solana_program::account_info::AccountInfo; use solana_program::pubkey::Pubkey; @@ -194,8 +192,13 @@ impl MetadataAccount { impl anchor_lang::AccountDeserialize for MetadataAccount { fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result { - let result = mpl_token_metadata::state::Metadata::deserialize(buf)?; - return Ok(MetadataAccount(result)); + let result: mpl_token_metadata::state::Metadata = + mpl_token_metadata::utils::try_from_slice_checked( + buf, + mpl_token_metadata::state::Key::MetadataV1, + mpl_token_metadata::state::MAX_METADATA_LEN, + )?; + Ok(MetadataAccount(result)) } } From a201b801e5651fdd7f2c4488cd08031ae516817b Mon Sep 17 00:00:00 2001 From: Kevin Rodriguez <_@kevinrodriguez.io> Date: Mon, 18 Jul 2022 14:13:59 -0600 Subject: [PATCH 07/11] chore: bump --- Cargo.lock | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c7835a17f3..8ed95144e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1966,9 +1966,9 @@ dependencies = [ [[package]] name = "mpl-token-metadata" -version = "1.3.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8b06b6275bd3f6444e22b03de7bdf6145ee6d6fa3e14415ddd317473b9ef807" +checksum = "47f4b577942a9029b33381344f343d6ff96f3212e857db66db8de21bfc58134f" dependencies = [ "arrayref", "borsh", @@ -3117,18 +3117,18 @@ dependencies = [ [[package]] name = "shank" -version = "0.0.2" +version = "0.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9cfd616747d1ce69f15e62ea30589e393115e4b884d7c1cbceb751b8753e95d" +checksum = "85a6c6cad96abd1fd950d1df186ec02e786566161f03adadbb7cf157ae9a82d8" dependencies = [ "shank_macro", ] [[package]] name = "shank_macro" -version = "0.0.2" +version = "0.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a27d3b536acc60a3ff359181d3a912d10b91539f85909447ca7d33ea0a91d56" +checksum = "c0b3bf722b43cea02627c7fd89925f5861f7aa27604c1852720f8eee1a73523d" dependencies = [ "proc-macro2 1.0.40", "quote 1.0.15", @@ -3138,9 +3138,9 @@ dependencies = [ [[package]] name = "shank_macro_impl" -version = "0.0.2" +version = "0.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7466a15559fd11aeb5fe12a700923f75bb4eaa7bc90962f2bd822708698ab5d" +checksum = "90a37f762b0529d64a9e3401ac3829e132f58fa9bc50b1fd6ad7b5a1a414a228" dependencies = [ "anyhow", "proc-macro2 1.0.40", From 4c89423b6da31833ff60137e446cf7342c9cb81f Mon Sep 17 00:00:00 2001 From: Kevin Rodriguez <_@kevinrodriguez.io> Date: Mon, 18 Jul 2022 14:15:06 -0600 Subject: [PATCH 08/11] fix: missing import --- spl/src/metadata.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/spl/src/metadata.rs b/spl/src/metadata.rs index c0e569f1fb..526711cde7 100644 --- a/spl/src/metadata.rs +++ b/spl/src/metadata.rs @@ -1,5 +1,6 @@ use anchor_lang::context::CpiContext; use anchor_lang::{Accounts, Result, ToAccountInfos}; +use mpl_token_metadata::state::DataV2; use mpl_token_metadata::ID; use solana_program::account_info::AccountInfo; use solana_program::pubkey::Pubkey; From 8931c253b47966b5a0979ad09ea6714025e64100 Mon Sep 17 00:00:00 2001 From: Kevin Rodriguez <_@kevinrodriguez.io> Date: Mon, 18 Jul 2022 16:30:01 -0600 Subject: [PATCH 09/11] feat: moving to safe_deserialize --- spl/src/metadata.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/spl/src/metadata.rs b/spl/src/metadata.rs index 526711cde7..749e7fe718 100644 --- a/spl/src/metadata.rs +++ b/spl/src/metadata.rs @@ -193,12 +193,7 @@ impl MetadataAccount { impl anchor_lang::AccountDeserialize for MetadataAccount { fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result { - let result: mpl_token_metadata::state::Metadata = - mpl_token_metadata::utils::try_from_slice_checked( - buf, - mpl_token_metadata::state::Key::MetadataV1, - mpl_token_metadata::state::MAX_METADATA_LEN, - )?; + let result = mpl_token_metadata::state::Metadata::safe_deserialize(buf)?; Ok(MetadataAccount(result)) } } From d0f251bac8016e08c201d76c706239159ff462e8 Mon Sep 17 00:00:00 2001 From: Armani Ferrante Date: Sat, 13 Aug 2022 14:43:44 -0400 Subject: [PATCH 10/11] Update CHANGELOG.md --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 471016948a..95f5435421 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,6 @@ The minor version will be incremented upon a breaking change and the patch versi ### Features -* spl: Add `MetadataAccount` account deserialization. ([#2014](https://github.com/coral-xyz/anchor/pull/2014)). * lang: Add `realloc`, `realloc::payer`, and `realloc::zero` as a new constraint group for program accounts ([#1986](https://github.com/coral-xyz/anchor/pull/1986)). * lang: Add `PartialEq` and `Eq` for `anchor_lang::Error` ([#1544](https://github.com/coral-xyz/anchor/pull/1544)). * cli: Add `--skip-build` to `anchor publish` ([#1786](https://github.com/coral-xyz/anchor/pull/1841)). From 66d49d478a4c1c8e8f2673a9ab1bf747e8f5bce1 Mon Sep 17 00:00:00 2001 From: Armani Ferrante Date: Sat, 13 Aug 2022 14:44:08 -0400 Subject: [PATCH 11/11] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95f5435421..d057f85114 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