Compare commits

...

3 Commits

Author SHA1 Message Date
Jimii 3cfdab75f1
Merge 037a618fd7 into 8e8df76eda 2024-04-18 12:18:24 -04:00
Syed Aabis Akhtar 8e8df76eda
docs: Fix GitHub example link of `declare_program!` in release notes (#2910)
Co-authored-by: acheron <98934430+acheroncrypto@users.noreply.github.com>
2024-04-18 15:20:53 +02:00
Jimii 037a618fd7
feat: support for MPL Core Account 2024-04-13 21:17:17 +03:00
4 changed files with 88 additions and 1 deletions

View File

@ -68,7 +68,7 @@ declare_program!(program_name);
`program_name` is based on the file name of the IDL in `idls` directory, e.g. `idls/program_name.json` is required to exist in order for the above example to work.
This works for both on-chain (CPI) and off-chain (RPC) usage, allowing program interactions without creating a [dependency hell](https://en.wikipedia.org/wiki/Dependency_hell). Check out [this](https://github.com/coral-xyz/anchor/blob/0.30.0/tests/declare-program/programs/declare-program/src/lib.rs) example for on-chain CPI usage.
This works for both on-chain (CPI) and off-chain (RPC) usage, allowing program interactions without creating a [dependency hell](https://en.wikipedia.org/wiki/Dependency_hell). Check out [this](https://github.com/coral-xyz/anchor/blob/v0.30.0/tests/declare-program/programs/declare-program/src/lib.rs) example for on-chain CPI usage.
For more information, see the macro's [documentation](https://docs.rs/anchor-lang/0.30.0/anchor_lang/macro.declare_program.html).

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.30.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
}
}