Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spl: adding metadata account type #2014

Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)).
armaniferrante marked this conversation as resolved.
Show resolved Hide resolved
* 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)).
Expand Down
30 changes: 30 additions & 0 deletions spl/src/metadata.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anchor_lang::context::CpiContext;
use anchor_lang::{Accounts, Result, ToAccountInfos};
use mpl_token_metadata::deser::meta_deser;
kevinrodriguez-io marked this conversation as resolved.
Show resolved Hide resolved
use mpl_token_metadata::state::DataV2;
use mpl_token_metadata::ID;
use solana_program::account_info::AccountInfo;
Expand Down Expand Up @@ -183,3 +184,32 @@ pub struct MintNewEditionFromMasterEditionViaToken<'info> {
//
pub metadata_mint: AccountInfo<'info>,
}

#[derive(Clone, Debug, PartialEq)]
pub struct MetadataAccount(mpl_token_metadata::state::Metadata);
kevinrodriguez-io marked this conversation as resolved.
Show resolved Hide resolved

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::deserialize(buf)?;
return 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
}
}