Skip to content

Commit

Permalink
Add anchor trait implementations for BaseCollectionV1
Browse files Browse the repository at this point in the history
  • Loading branch information
danenbm committed Jun 28, 2024
1 parent 22b5730 commit c55b0e4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clients/rust/src/hooked/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ mod anchor_impl {
}
}

// Not used as an Anchor program using Account<BaseAssetV1> would not have permission to
// reserialize the account as it's owned by mpl-core.
impl AccountSerialize for BaseAssetV1 {}

// Not used but needed for Anchor.
impl Discriminator for BaseAssetV1 {
const DISCRIMINATOR: [u8; 8] = [0; 8];
}
Expand Down
31 changes: 31 additions & 0 deletions clients/rust/src/hooked/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,34 @@ impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for Collection
Self::deserialize(data)
}
}

#[cfg(feature = "anchor")]
mod anchor_impl {
use super::*;
use anchor_lang::{
prelude::{Owner, Pubkey},
AccountDeserialize, AccountSerialize, Discriminator,
};

impl AccountDeserialize for BaseCollectionV1 {
fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
let base_asset = Self::from_bytes(buf)?;
Ok(base_asset)
}
}

// Not used as an Anchor program using Account<BaseCollectionV1> would not have permission to
// reserialize the account as it's owned by mpl-core.
impl AccountSerialize for BaseCollectionV1 {}

// Not used but needed for Anchor.
impl Discriminator for BaseCollectionV1 {
const DISCRIMINATOR: [u8; 8] = [0; 8];
}

impl Owner for BaseCollectionV1 {
fn owner() -> Pubkey {
crate::ID
}
}
}

0 comments on commit c55b0e4

Please sign in to comment.