Compare commits
3 Commits
e81fed79d0
...
3cfdab75f1
Author | SHA1 | Date |
---|---|---|
Jimii | 3cfdab75f1 | |
Syed Aabis Akhtar | 8e8df76eda | |
Jimii | 037a618fd7 |
|
@ -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).
|
||||
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -37,3 +37,6 @@ pub mod memo;
|
|||
|
||||
#[cfg(feature = "idl-build")]
|
||||
mod idl_build;
|
||||
|
||||
#[cfg(feature = "mpl_core")]
|
||||
mod mpl_core;
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue