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

feat: add TokenRecordAccount for pNFTs #2597

Merged
merged 1 commit into from
Aug 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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