Skip to content

Commit

Permalink
Migrate WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
blockiosaurus committed Feb 20, 2024
1 parent e8c0c3d commit 1a3891d
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 27 deletions.
9 changes: 0 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions clients/js/src/generated/errors/mplAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,19 @@ export class CannotMigratePrintsError extends ProgramError {
codeToErrorMap.set(0xd, CannotMigratePrintsError);
nameToErrorMap.set('CannotMigratePrints', CannotMigratePrintsError);

/** CannotBurnCollection: Cannot burn a collection NFT */
export class CannotBurnCollectionError extends ProgramError {
readonly name: string = 'CannotBurnCollection';

readonly code: number = 0xe; // 14

constructor(program: Program, cause?: Error) {
super('Cannot burn a collection NFT', program, cause);
}
}
codeToErrorMap.set(0xe, CannotBurnCollectionError);
nameToErrorMap.set('CannotBurnCollection', CannotBurnCollectionError);

/**
* Attempts to resolve a custom program error from the provided error code.
* @category Errors
Expand Down
6 changes: 3 additions & 3 deletions clients/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ num-derive = "^0.3"
num-traits = "^0.2"
serde = { version = "^1.0", features = ["derive"], optional = true }
serde_with = { version = "^3.0", optional = true }
solana-program = "~1.16"
solana-program = "> 1.14, <= 1.18"
thiserror = "^1.0"

[dev-dependencies]
assert_matches = "1.5.0"
solana-program-test = "~1.16"
solana-sdk = "~1.16"
solana-program-test = "> 1.14, <= 1.18"
solana-sdk = "> 1.14, <= 1.18"
3 changes: 3 additions & 0 deletions clients/rust/src/generated/errors/mpl_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ pub enum MplAssetError {
/// 13 (0xD) - Cannot migrate a print edition
#[error("Cannot migrate a print edition")]
CannotMigratePrints,
/// 14 (0xE) - Cannot burn a collection NFT
#[error("Cannot burn a collection NFT")]
CannotBurnCollection,
}

impl solana_program::program_error::PrintProgramError for MplAssetError {
Expand Down
5 changes: 5 additions & 0 deletions idls/mpl_asset_program.json
Original file line number Diff line number Diff line change
Expand Up @@ -1394,6 +1394,11 @@
"code": 13,
"name": "CannotMigratePrints",
"msg": "Cannot migrate a print edition"
},
{
"code": 14,
"name": "CannotBurnCollection",
"msg": "Cannot burn a collection NFT"
}
],
"metadata": {
Expand Down
2 changes: 1 addition & 1 deletion programs/mpl-asset/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ borsh = "^0.10"
shank = "0.3.0"
num-derive = "^0.3"
num-traits = "^0.2"
solana-program = "~1.16"
solana-program = "^1.16"
thiserror = "^1.0"
bytemuck = "1.14.1"
mpl-utils = "0.3.3"
Expand Down
4 changes: 4 additions & 0 deletions programs/mpl-asset/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ pub enum MplAssetError {
/// 13 - Cannot migrate a print edition
#[error("Cannot migrate a print edition")]
CannotMigratePrints,

/// 14 - Cannot burn a collection NFT
#[error("Cannot burn a collection NFT")]
CannotBurnCollection,
}

impl PrintProgramError for MplAssetError {
Expand Down
25 changes: 13 additions & 12 deletions programs/mpl-asset/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,19 @@ pub enum MplAssetInstruction {
#[account(1, optional, signer, name="owner", desc = "The authority of the new asset")]
#[account(2, writable, signer, name="payer", desc = "The account paying for the storage fees")]
// Dependent on how migration is handled
#[account(3, optional, writable, name="collection", desc="mpl-token-metadata collection metadata or mpl-asset collection")]
#[account(4, writable, name="token", desc="Token account")]
#[account(5, writable, name="mint", desc="Mint of token asset")]
#[account(6, writable, name="metadata", desc="Metadata (pda of ['metadata', program id, mint id])")]
#[account(7, writable, name="edition", desc="Edition of token asset")]
#[account(8, optional, writable, name="owner_token_record", desc="Owner token record account")]
#[account(9, name="spl_token_program", desc="SPL Token Program")]
#[account(10, name="spl_ata_program", desc="SPL Associated Token Account program")]
#[account(11, name="system_program", desc = "The system program")]
#[account(12, optional, name="log_wrapper", desc = "The SPL Noop Program")]
#[account(13, optional, name="authorization_rules_program", desc="Token Authorization Rules Program")]
#[account(14, optional, name="authorization_rules", desc="Token Authorization Rules account")]
#[account(3, optional, name="collection_metadata", desc="mpl-token-metadata collection metadata")]
#[account(4, optional, writable, name="collection", desc="mpl-asset collection")]
#[account(5, writable, name="token", desc="Token account")]
#[account(6, writable, name="mint", desc="Mint of token asset")]
#[account(7, writable, name="metadata", desc="Metadata (pda of ['metadata', program id, mint id])")]
#[account(8, writable, name="edition", desc="Edition of token asset")]
#[account(9, optional, writable, name="owner_token_record", desc="Owner token record account")]
#[account(10, name="spl_token_program", desc="SPL Token Program")]
#[account(11, name="spl_ata_program", desc="SPL Associated Token Account program")]
#[account(12, name="system_program", desc = "The system program")]
#[account(13, optional, name="log_wrapper", desc = "The SPL Noop Program")]
#[account(14, optional, name="authorization_rules_program", desc="Token Authorization Rules Program")]
#[account(15, optional, name="authorization_rules", desc="Token Authorization Rules account")]
Migrate(MigrateArgs),

/// Delegate an mpl-asset.
Expand Down
12 changes: 10 additions & 2 deletions programs/mpl-asset/src/processor/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,18 @@ pub(crate) fn migrate<'a>(accounts: &'a [AccountInfo<'a>], args: MigrateArgs) ->
};

let metadata = Metadata::safe_deserialize(&ctx.accounts.metadata.data.borrow())?;

match metadata.collection_details {
// If this is a collection NFT then we need to initialize migration for the whole collection.
Some(_) => {}
Some(_) => {
// We don't want to burn the collection NFT if we are migrating the whole collection.
if args.level != MigrationLevel::MigrateOnly {
return Err(MplAssetError::CannotBurnCollection.into());
}

// If the mpl-asset collection doesn't already exist, then create it.


}
// Otherwise, we need to migrate the NFT
None => {
// Assert that the NFT is not a print edition.
Expand Down
31 changes: 31 additions & 0 deletions programs/mpl-asset/src/state/asset_signer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use borsh::{BorshDeserialize, BorshSerialize};
use solana_program::pubkey::Pubkey;

#[derive(Clone, BorshSerialize, BorshDeserialize, Debug, ShankAccount)]
pub struct AssetSigner {
pub key: Key, //1
}

impl DataBlob for AssetSigner {
fn get_initial_size() -> usize {
1
}

fn get_size(&self) -> usize {
1
}
}

impl SolanaAccount for AssetSigner {
fn key() -> Key {
Key::AssetSigner
}
}

impl Default for AssetSigner {
fn default() -> Self {
AssetSigner {
key: Key::AssetSigner,
}
}
}

0 comments on commit 1a3891d

Please sign in to comment.