Skip to content

Commit

Permalink
spl: Add TokenRecordAccount for pNFTs (#2597)
Browse files Browse the repository at this point in the history
  • Loading branch information
jim4067 authored Aug 12, 2023
1 parent 58428f8 commit b5cf67f
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions spl/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,42 @@ impl anchor_lang::Owner for MasterEditionAccount {
}
}

#[derive(Clone, Debug, PartialEq)]
pub struct TokenRecordAccount(mpl_token_metadata::state::TokenRecord);

impl TokenRecordAccount {
pub const LEN: usize = mpl_token_metadata::state::TOKEN_RECORD_SIZE;
}
impl anchor_lang::AccountDeserialize for TokenRecordAccount {
fn try_deserialize(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
let tr = Self::try_deserialize_unchecked(buf)?;
if tr.key != mpl_token_metadata::state::TokenRecord::key() {
return Err(ErrorCode::AccountNotInitialized.into());
}
Ok(tr)
}

fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
let tr = mpl_token_metadata::state::TokenRecord::safe_deserialize(buf)?;
Ok(Self(tr))
}
}

impl anchor_lang::AccountSerialize for TokenRecordAccount {}

impl anchor_lang::Owner for TokenRecordAccount {
fn owner() -> Pubkey {
ID
}
}

impl Deref for TokenRecordAccount {
type Target = mpl_token_metadata::state::TokenRecord;
fn deref(&self) -> &Self::Target {
&self.0
}
}

#[derive(Clone)]
pub struct Metadata;

Expand Down

1 comment on commit b5cf67f

@vercel
Copy link

@vercel vercel bot commented on b5cf67f Aug 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

anchor-docs – ./

anchor-docs-200ms.vercel.app
www.anchor-lang.com
anchor-lang.com
anchor-docs-git-master-200ms.vercel.app

Please sign in to comment.