This commit is contained in:
Jimii 2024-04-15 01:11:22 +02:00 committed by GitHub
commit fe11f6710b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 87 additions and 0 deletions

View File

@ -25,6 +25,7 @@ stake = ["borsh"]
token = ["spl-token"]
token_2022 = ["spl-token-2022"]
token_2022_extensions = ["spl-token-2022", "spl-token-group-interface", "spl-token-metadata-interface", "spl-pod"]
mpl_core = ["mpl-core"]
[dependencies]
anchor-lang = { path = "../lang", version = "0.29.0", features = ["derive"] }
@ -38,3 +39,4 @@ spl-token-2022 = { version = "3", features = ["no-entrypoint"], optional = true
spl-token-group-interface = { version = "0.2.3", optional = true }
spl-token-metadata-interface = { version = "0.3.3", optional = true }
spl-pod = { version = "0.2.2", optional = true }
mpl-core = { version = "0.4.4", optional = true}

View File

@ -37,3 +37,6 @@ pub mod memo;
#[cfg(feature = "idl-build")]
mod idl_build;
#[cfg(feature = "mpl_core")]
mod mpl_core;

82
spl/src/mpl_core.rs Normal file
View File

@ -0,0 +1,82 @@
use anchor_lang::error::ErrorCode;
use std::ops::Deref;
pub use mpl_core;
pub use mpl_core::ID;
#[derive(Clone, Debug, PartialEq)]
pub struct AssetAccount(mpl_core::Asset);
impl anchor_lang::AccountDeserialize for AssetAccount {
fn try_deserialize(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
let asset = Self::try_deserialize_unchecked(buf)?;
if asset.base.key == mpl_core::types::Key::Uninitialized {
return Err(ErrorCode::AccountNotInitialized.into());
}
Ok(asset)
}
fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
let asset = mpl_core::Asset::deserialize(buf)?;
Ok(Self(asset))
}
}
impl anchor_lang::AccountSerialize for AssetAccount {}
impl anchor_lang::Owner for AssetAccount {
fn owner() -> Pubkey {
ID
}
}
impl Deref for AssetAccount {
type Target = mpl_core::Asset;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct BaseAssetV1Account(mpl_core::accounts::BaseAssetV1);
impl anchor_lang::AccountDeserialize for BaseAssetV1Account {
fn try_deserialize(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
let base_asset = Self::try_deserialize_unchecked(buf)?;
if base_asset.key == mpl_core::types::Key::Uninitialized {
return Err(ErrorCode::AccountNotInitialized.into());
}
Ok(base_asset)
}
fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
let base_asset = mpl_core::accounts::BaseAssetV1::deserialize(buf)?;
Ok(Self(base_asset))
}
}
impl anchor_lang::AccountSerialize for BaseAssetV1Account {}
impl anchor_lang::Owner for BaseAssetV1Account {
fn owner() -> Pubkey {
ID
}
}
impl Deref for BaseAssetV1Account {
type Target = mpl_core::accounts::BaseAssetV1;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[derive(Clone)]
pub struct MplCore;
impl anchor_lang::Id for MplCore {
fn id() -> Pubkey {
mpl_core::ID
}
}