Compare commits

...

3 Commits

Author SHA1 Message Date
Jimii 46b0cbfe78
Merge 037a618fd7 into f74ea64ca6 2024-04-15 16:33:06 +03:00
acheron f74ea64ca6
idl: Rename crate name to `anchor-lang-idl` (#2908) 2024-04-15 13:56:53 +02:00
Jimii 037a618fd7
feat: support for MPL Core Account 2024-04-13 21:17:17 +03:00
22 changed files with 123 additions and 36 deletions

28
Cargo.lock generated
View File

@ -170,7 +170,7 @@ dependencies = [
name = "anchor-attribute-program"
version = "0.29.0"
dependencies = [
"anchor-idl",
"anchor-lang-idl",
"anchor-syn",
"anyhow",
"bs58 0.5.0",
@ -186,8 +186,8 @@ name = "anchor-cli"
version = "0.29.0"
dependencies = [
"anchor-client",
"anchor-idl",
"anchor-lang",
"anchor-lang-idl",
"anyhow",
"base64 0.21.7",
"bincode",
@ -263,17 +263,6 @@ dependencies = [
"syn 1.0.109",
]
[[package]]
name = "anchor-idl"
version = "0.1.0"
dependencies = [
"anchor-syn",
"anyhow",
"regex",
"serde",
"serde_json",
]
[[package]]
name = "anchor-lang"
version = "0.29.0"
@ -287,7 +276,7 @@ dependencies = [
"anchor-derive-accounts",
"anchor-derive-serde",
"anchor-derive-space",
"anchor-idl",
"anchor-lang-idl",
"arrayref",
"base64 0.21.7",
"bincode",
@ -298,6 +287,17 @@ dependencies = [
"thiserror",
]
[[package]]
name = "anchor-lang-idl"
version = "0.1.0"
dependencies = [
"anchor-syn",
"anyhow",
"regex",
"serde",
"serde_json",
]
[[package]]
name = "anchor-spl"
version = "0.29.0"

View File

@ -17,7 +17,7 @@ dev = []
[dependencies]
anchor-client = { path = "../client", version = "0.29.0" }
anchor-idl = { path = "../idl", features = ["build"], version = "0.1.0" }
anchor-lang-idl = { path = "../idl", features = ["build"], version = "0.1.0" }
anchor-lang = { path = "../lang", version = "0.29.0" }
anyhow = "1.0.32"
base64 = "0.21"

View File

@ -1,6 +1,6 @@
use crate::is_hidden;
use anchor_client::Cluster;
use anchor_idl::types::Idl;
use anchor_lang_idl::types::Idl;
use anyhow::{anyhow, bail, Context, Error, Result};
use clap::{Parser, ValueEnum};
use dirs::home_dir;

View File

@ -6,9 +6,9 @@ use crate::config::{
DEFAULT_LEDGER_PATH, SHUTDOWN_WAIT, STARTUP_WAIT,
};
use anchor_client::Cluster;
use anchor_idl::types::{Idl, IdlArrayLen, IdlDefinedFields, IdlType, IdlTypeDefTy};
use anchor_lang::idl::{IdlAccount, IdlInstruction, ERASED_AUTHORITY};
use anchor_lang::{AccountDeserialize, AnchorDeserialize, AnchorSerialize};
use anchor_lang_idl::types::{Idl, IdlArrayLen, IdlDefinedFields, IdlType, IdlTypeDefTy};
use anyhow::{anyhow, Context, Result};
use checks::{check_anchor_version, check_overflow};
use clap::Parser;
@ -2609,7 +2609,7 @@ fn idl_build(
.path
}
};
let idl = anchor_idl::build::build_idl(
let idl = anchor_lang_idl::build::build_idl(
program_path,
cfg.features.resolution,
cfg.features.skip_lint || skip_lint,
@ -2655,7 +2655,7 @@ in `{path}`."#
));
}
anchor_idl::build::build_idl(
anchor_lang_idl::build::build_idl(
std::env::current_dir()?,
cfg.features.resolution,
cfg.features.skip_lint || skip_lint,

View File

@ -2,7 +2,7 @@ use crate::{
config::ProgramWorkspace, create_files, override_or_create_files, solidity_template, Files,
VERSION,
};
use anchor_idl::types::Idl;
use anchor_lang_idl::types::Idl;
use anyhow::Result;
use clap::{Parser, ValueEnum};
use heck::{ToLowerCamelCase, ToPascalCase, ToSnakeCase};

View File

@ -1,5 +1,5 @@
[package]
name = "anchor-idl"
name = "anchor-lang-idl"
version = "0.1.0"
authors = ["Anchor Maintainers <accounts@200ms.io>"]
repository = "https://github.com/coral-xyz/anchor"

View File

@ -33,7 +33,7 @@ idl-build = [
"anchor-attribute-program/idl-build",
"anchor-derive-accounts/idl-build",
"anchor-derive-serde/idl-build",
"anchor-idl/build",
"anchor-lang-idl/build",
]
init-if-needed = ["anchor-derive-accounts/init-if-needed"]
interface-instructions = ["anchor-attribute-program/interface-instructions"]
@ -49,8 +49,8 @@ anchor-derive-accounts = { path = "./derive/accounts", version = "0.29.0" }
anchor-derive-serde = { path = "./derive/serde", version = "0.29.0" }
anchor-derive-space = { path = "./derive/space", version = "0.29.0" }
# `anchor-idl` should only be included with `idl-build` feature
anchor-idl = { path = "../idl", version = "0.1.0", optional = true }
# `anchor-lang-idl` should only be included with `idl-build` feature
anchor-lang-idl = { path = "../idl", version = "0.1.0", optional = true }
arrayref = "0.3"
base64 = "0.21"

View File

@ -17,7 +17,7 @@ idl-build = ["anchor-syn/idl-build"]
interface-instructions = ["anchor-syn/interface-instructions"]
[dependencies]
anchor-idl = { path = "../../../idl", version = "0.1.0" }
anchor-lang-idl = { path = "../../../idl", version = "0.1.0" }
anchor-syn = { path = "../../syn", version = "0.29.0" }
anyhow = "1"
bs58 = "0.5"

View File

@ -1,4 +1,4 @@
use anchor_idl::types::{
use anchor_lang_idl::types::{
Idl, IdlArrayLen, IdlDefinedFields, IdlField, IdlGenericArg, IdlRepr, IdlSerialization,
IdlType, IdlTypeDef, IdlTypeDefGeneric, IdlTypeDefTy,
};

View File

@ -1,7 +1,7 @@
mod common;
mod mods;
use anchor_idl::types::Idl;
use anchor_lang_idl::types::Idl;
use anyhow::anyhow;
use quote::{quote, ToTokens};
use syn::parse::{Parse, ParseStream};

View File

@ -1,4 +1,4 @@
use anchor_idl::types::{Idl, IdlSerialization};
use anchor_lang_idl::types::{Idl, IdlSerialization};
use quote::{format_ident, quote};
use super::common::{convert_idl_type_def_to_ts, gen_discriminator, get_canonical_program_id};

View File

@ -1,4 +1,4 @@
use anchor_idl::types::Idl;
use anchor_lang_idl::types::Idl;
use quote::quote;
use super::common::gen_accounts_common;

View File

@ -1,4 +1,4 @@
use anchor_idl::types::{Idl, IdlType};
use anchor_lang_idl::types::{Idl, IdlType};
use quote::{format_ident, quote, ToTokens};
use super::common::convert_idl_type_to_str;

View File

@ -1,4 +1,4 @@
use anchor_idl::types::Idl;
use anchor_lang_idl::types::Idl;
use heck::CamelCase;
use quote::{format_ident, quote};

View File

@ -1,4 +1,4 @@
use anchor_idl::types::Idl;
use anchor_lang_idl::types::Idl;
use quote::{format_ident, quote};
use super::common::{convert_idl_type_def_to_ts, gen_discriminator};

View File

@ -1,4 +1,4 @@
use anchor_idl::types::{Idl, IdlInstructionAccountItem};
use anchor_lang_idl::types::{Idl, IdlInstructionAccountItem};
use anchor_syn::{
codegen::accounts::{__client_accounts, __cpi_client_accounts},
parser::accounts,

View File

@ -1,4 +1,4 @@
use anchor_idl::types::Idl;
use anchor_lang_idl::types::Idl;
use quote::quote;
use super::common::convert_idl_type_def_to_ts;

View File

@ -1,4 +1,4 @@
use anchor_idl::types::Idl;
use anchor_lang_idl::types::Idl;
use quote::{format_ident, quote};
use super::common::gen_discriminator;

View File

@ -80,4 +80,4 @@ impl IdlAccount {
}
#[cfg(feature = "idl-build")]
pub use anchor_idl::{build::IdlBuild, *};
pub use anchor_lang_idl::{build::IdlBuild, *};

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