Skip to content

Commit

Permalink
spl: Add TokenRecordAccount for pNFTs (coral-xyz#2597)
Browse files Browse the repository at this point in the history
  • Loading branch information
jim4067 committed 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

0 comments on commit b5cf67f

Please sign in to comment.