Skip to content

Commit 73a6c62

Browse files
authored
spl: adding metadata account type (otter-sec#2014)
1 parent bc81619 commit 73a6c62

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ The minor version will be incremented upon a breaking change and the patch versi
1414

1515
* client: Add `transaction` functions to RequestBuilder ([#1958](https://github.com/coral-xyz/anchor/pull/1958)).
1616
* spl: Add `create_metadata_accounts_v3` and `set_collection_size` wrappers ([#2119](https://github.com/coral-xyz/anchor/pull/2119))
17+
* spl: Add `MetadataAccount` account deserialization. ([#2014](https://github.com/coral-xyz/anchor/pull/2014)).
1718

1819
## [0.25.0] - 2022-07-05
1920

spl/src/metadata.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,32 @@ pub struct SetCollectionSize<'info> {
266266
pub update_authority: AccountInfo<'info>,
267267
pub system_program: AccountInfo<'info>,
268268
}
269+
270+
#[derive(Clone, Debug, PartialEq)]
271+
pub struct MetadataAccount(mpl_token_metadata::state::Metadata);
272+
273+
impl MetadataAccount {
274+
pub const LEN: usize = mpl_token_metadata::state::MAX_METADATA_LEN;
275+
}
276+
277+
impl anchor_lang::AccountDeserialize for MetadataAccount {
278+
fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
279+
let result = mpl_token_metadata::state::Metadata::safe_deserialize(buf)?;
280+
Ok(MetadataAccount(result))
281+
}
282+
}
283+
284+
impl anchor_lang::AccountSerialize for MetadataAccount {}
285+
286+
impl anchor_lang::Owner for MetadataAccount {
287+
fn owner() -> Pubkey {
288+
ID
289+
}
290+
}
291+
292+
impl Deref for MetadataAccount {
293+
type Target = mpl_token_metadata::state::Metadata;
294+
fn deref(&self) -> &Self::Target {
295+
&self.0
296+
}
297+
}

0 commit comments

Comments
 (0)