Skip to content

Commit

Permalink
feat(set): add set immutable commands; update to mpl-token-metadata v…
Browse files Browse the repository at this point in the history
…1.1.0
  • Loading branch information
samuelvanderwaal committed Feb 1, 2022
1 parent 648b3a1 commit e5026d8
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 45 deletions.
32 changes: 1 addition & 31 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ glob = "0.3.0"
indicatif = { version = "0.16.2", features = ["rayon"] }
lazy_static = "1.4.0"
log = "0.4.14"
metaplex-token-metadata = "0.0.1"
mpl-token-metadata = "1.1.0"
mpl-candy-machine = { version = "2.0.1", features = ["no-entrypoint"] }
num_cpus = "1.13.0"
ratelimit = "0.4.4"
Expand Down
5 changes: 5 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
v0.4.0
* Change decode default format to data struct to match input required from `update-metadata` command
* Add `set immutable` and `set immutable` all commands
* Updated to use `mpl-token-metadata v1.1.0`

TODO:
* Set primary sale and set immutable, fix progress bar by not writing to log within par_iter loop

v0.3.6
* Add withdraw command for candy machine v2
Expand Down
2 changes: 1 addition & 1 deletion src/burn.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use metaplex_token_metadata::{
use mpl_token_metadata::{
id,
instruction::update_metadata_accounts,
state::{Data, Metadata},
Expand Down
4 changes: 3 additions & 1 deletion src/decode.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::{anyhow, Result as AnyResult};
use indicatif::ParallelProgressIterator;
use log::{debug, error, info};
use metaplex_token_metadata::state::{Key, Metadata};
use mpl_token_metadata::state::{Key, Metadata};
use rayon::prelude::*;
use retry::{delay::Exponential, retry};
use serde::Serialize;
Expand Down Expand Up @@ -231,5 +231,7 @@ fn parse_key(key: Key) -> String {
Key::ReservationListV2 => String::from("ReservationListV2"),
Key::MasterEditionV2 => String::from("MasterEditionV2"),
Key::EditionMarker => String::from("EditionMarker"),
Key::UseAuthorityRecord => String::from("UseAuthorityRecord"),
Key::CollectionAuthorityRecord => String::from("CollectionAuthorityRecord"),
}
}
2 changes: 1 addition & 1 deletion src/derive.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use metaplex_token_metadata::id;
use mpl_token_metadata::id;
use solana_sdk::pubkey::Pubkey;
use std::{convert::AsRef, str::FromStr};

Expand Down
2 changes: 1 addition & 1 deletion src/mint.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::{anyhow, Result};
use glob::glob;
use log::{error, info};
use metaplex_token_metadata::instruction::{
use mpl_token_metadata::instruction::{
create_master_edition, create_metadata_accounts, update_metadata_accounts,
};
use rayon::prelude::*;
Expand Down
20 changes: 20 additions & 0 deletions src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,26 @@ pub enum SetSubcommands {
#[structopt(short = "u", long)]
new_update_authority: String,
},
/// Set is-mutable to false, preventing any future updates to the NFT
#[structopt(name = "immutable")]
Immutable {
/// Path to the creator's keypair file
#[structopt(short, long)]
keypair: String,

/// Mint account of corresponding metadata to update
#[structopt(short, long)]
mint_account: String,
},
ImmutableAll {
/// Path to the creator's keypair file
#[structopt(short, long)]
keypair: String,

/// Path to JSON mint accounts file
#[structopt(short, long)]
mint_accounts_file: String,
},
}

#[derive(Debug, StructOpt)]
Expand Down
2 changes: 1 addition & 1 deletion src/parse.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::{anyhow, Context, Result};
use metaplex_token_metadata::state::{Creator, Data};
use mpl_token_metadata::state::{Creator, Data};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use solana_sdk::pubkey::Pubkey;
Expand Down
8 changes: 8 additions & 0 deletions src/process_subcommands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ pub fn process_set(client: &RpcClient, commands: SetSubcommands) -> Result<()> {
&mint_accounts_file,
&new_update_authority,
),
SetSubcommands::Immutable {
keypair,
mint_account,
} => set_immutable(&client, &keypair, &mint_account),
SetSubcommands::ImmutableAll {
keypair,
mint_accounts_file,
} => set_immutable_all(&client, &keypair, &mint_accounts_file),
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/sign.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use anyhow::{anyhow, Result};
use indicatif::ParallelProgressIterator;
use log::{error, info};
use metaplex_token_metadata::{
instruction::sign_metadata, state::Metadata, ID as METAPLEX_PROGRAM_ID,
};
use mpl_token_metadata::{instruction::sign_metadata, state::Metadata, ID as METAPLEX_PROGRAM_ID};
use rayon::prelude::*;
use retry::{delay::Exponential, retry};
use solana_client::rpc_client::RpcClient;
Expand Down
4 changes: 2 additions & 2 deletions src/snapshot.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use anyhow::{anyhow, Result};
use indicatif::ParallelProgressIterator;
use log::{error, info};
use metaplex_token_metadata::state::Metadata;
use metaplex_token_metadata::ID as TOKEN_METADATA_PROGRAM_ID;
use mpl_token_metadata::state::Metadata;
use mpl_token_metadata::ID as TOKEN_METADATA_PROGRAM_ID;
use rayon::prelude::*;
use retry::{delay::Exponential, retry};
use serde::Serialize;
Expand Down
59 changes: 56 additions & 3 deletions src/update_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use anyhow::{anyhow, Result};
use glob::glob;
use indicatif::ParallelProgressIterator;
use log::{error, info};
use metaplex_token_metadata::{instruction::update_metadata_accounts, state::Data};
use mpl_token_metadata::{
instruction::{update_metadata_accounts, update_metadata_accounts_v2},
state::Data,
};
use rayon::prelude::*;
use retry::{delay::Exponential, retry};
use solana_client::rpc_client::RpcClient;
Expand Down Expand Up @@ -315,8 +318,6 @@ pub fn set_update_authority_all(

info!("Setting update_authority...");
items.par_iter().progress().for_each(|item| {
info!("Updating metadata for mint account: {}", item);

// If someone uses a json list that contains a mint account that has already
// been updated this will throw an error. We print that error and continue
let _ = match set_update_authority(client, keypair, &item, &new_update_authority) {
Expand All @@ -329,3 +330,55 @@ pub fn set_update_authority_all(

Ok(())
}

pub fn set_immutable(client: &RpcClient, keypair: &String, account: &String) -> Result<()> {
let keypair = parse_keypair(keypair)?;
let program_id = Pubkey::from_str(METAPLEX_PROGRAM_ID)?;
let mint_account = Pubkey::from_str(account)?;

let update_authority = keypair.pubkey();

let metadata_account = get_metadata_pda(mint_account);

let ix = update_metadata_accounts_v2(
program_id,
metadata_account,
update_authority,
None,
None,
None,
Some(false),
);
let recent_blockhash = client.get_latest_blockhash()?;
let tx = Transaction::new_signed_with_payer(
&[ix],
Some(&update_authority),
&[&keypair],
recent_blockhash,
);

let sig = client.send_and_confirm_transaction(&tx)?;
info!("Tx sig: {:?}", sig);
println!("Tx sig: {:?}", sig);

Ok(())
}

pub fn set_immutable_all(client: &RpcClient, keypair: &String, json_file: &String) -> Result<()> {
let file = File::open(json_file)?;
let items: Vec<String> = serde_json::from_reader(file)?;

info!("Setting immutable...");
items.par_iter().progress().for_each(|item| {
// If someone uses a json list that contains a mint account that has already
// been updated this will throw an error. We print that error and continue
let _ = match set_immutable(client, keypair, &item) {
Ok(_) => {}
Err(error) => {
error!("Error occurred! {}", error)
}
};
});

Ok(())
}

0 comments on commit e5026d8

Please sign in to comment.