Skip to content

Commit

Permalink
allow unverified snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelvanderwaal committed Sep 19, 2022
1 parent d8ad996 commit e97d0d2
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/collections/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ pub async fn migrate_collection(args: MigrateArgs) -> AnyResult<()> {

let mut mint_accounts = if let Some(candy_machine_id) = args.candy_machine_id {
println!("Using candy machine id to fetch mint list. . .");
get_mint_accounts(&args.client, &Some(candy_machine_id), 0, None, true)?
get_mint_accounts(&args.client, &Some(candy_machine_id), 0, None, false, true)?
} else if let Some(mint_list) = args.mint_list {
let f = File::open(mint_list)?;
serde_json::from_reader(f)?
Expand Down
8 changes: 8 additions & 0 deletions src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,10 @@ pub enum SnapshotSubcommands {
#[structopt(short, long)]
mint_accounts_file: Option<String>,

/// Allow fetching items with unverified creator or update authority.
#[structopt(long)]
allow_unverified: bool,

/// Path to directory to save output files.
#[structopt(short, long, default_value = ".")]
output: String,
Expand Down Expand Up @@ -805,6 +809,10 @@ pub enum SnapshotSubcommands {
#[structopt(long = "v2")]
v2: bool,

/// Allow fetching items with unverified creator or update authority.
#[structopt(long)]
allow_unverified: bool,

/// Path to directory to save output file
#[structopt(short, long, default_value = ".")]
output: String,
Expand Down
20 changes: 13 additions & 7 deletions src/process_subcommands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::parse::{parse_errors_code, parse_errors_file};
use crate::sign::{sign_all, sign_one};
use crate::snapshot::{
snapshot_cm_accounts, snapshot_holders, snapshot_indexed_holders, snapshot_indexed_mints,
snapshot_mints, SnapshotMintsArgs,
snapshot_mints, SnapshotHoldersArgs, SnapshotMintsArgs,
};
use crate::update::*;
use crate::uses::{approve_use_delegate, revoke_use_delegate, utilize_nft};
Expand Down Expand Up @@ -389,15 +389,19 @@ pub async fn process_snapshot(client: &RpcClient, commands: SnapshotSubcommands)
position,
mint_accounts_file,
v2,
allow_unverified,
output,
} => snapshot_holders(
client,
&update_authority,
&creator,
position,
&mint_accounts_file,
v2,
&output,
SnapshotHoldersArgs {
update_authority,
creator,
position,
mint_accounts_file,
v2,
allow_unverified,
output,
},
),
SnapshotSubcommands::IndexedHolders {
indexer,
Expand All @@ -414,6 +418,7 @@ pub async fn process_snapshot(client: &RpcClient, commands: SnapshotSubcommands)
position,
update_authority,
v2,
allow_unverified,
output,
} => snapshot_mints(
client,
Expand All @@ -422,6 +427,7 @@ pub async fn process_snapshot(client: &RpcClient, commands: SnapshotSubcommands)
position,
update_authority,
v2,
allow_unverified,
output,
},
),
Expand Down
11 changes: 11 additions & 0 deletions src/snapshot/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,16 @@ pub struct SnapshotMintsArgs {
pub position: usize,
pub update_authority: Option<String>,
pub v2: bool,
pub allow_unverified: bool,
pub output: String,
}

pub struct SnapshotHoldersArgs {
pub creator: Option<String>,
pub position: usize,
pub update_authority: Option<String>,
pub mint_accounts_file: Option<String>,
pub v2: bool,
pub allow_unverified: bool,
pub output: String,
}
42 changes: 19 additions & 23 deletions src/snapshot/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub fn snapshot_mints(client: &RpcClient, args: SnapshotMintsArgs) -> Result<()>
&args.creator,
args.position,
args.update_authority,
args.allow_unverified,
args.v2,
)?;

Expand Down Expand Up @@ -80,6 +81,7 @@ pub fn get_mint_accounts(
creator: &Option<String>,
position: usize,
update_authority: Option<String>,
allow_unverified: bool,
v2: bool,
) -> Result<Vec<String>> {
let spinner = create_spinner("Getting accounts...");
Expand Down Expand Up @@ -116,40 +118,32 @@ pub fn get_mint_accounts(
}
};

if creator_is_verified(&metadata.data.creators, position) {
if creator_is_verified(&metadata.data.creators, position) || allow_unverified {
mint_accounts.push(metadata.mint.to_string());
}
}

Ok(mint_accounts)
}

pub fn snapshot_holders(
client: &RpcClient,
update_authority: &Option<String>,
creator: &Option<String>,
position: usize,
mint_accounts_file: &Option<String>,
v2: bool,
output: &str,
) -> Result<()> {
pub fn snapshot_holders(client: &RpcClient, args: SnapshotHoldersArgs) -> Result<()> {
let use_rate_limit = *USE_RATE_LIMIT.read().unwrap();
let handle = create_default_rate_limiter();

let spinner = create_spinner("Getting accounts...");
let accounts = if let Some(update_authority) = update_authority {
let accounts = if let Some(ref update_authority) = args.update_authority {
get_mints_by_update_authority(client, update_authority)?
} else if let Some(creator) = creator {
} else if let Some(ref creator) = args.creator {
// Support v2 cm ids
if v2 {
if args.v2 {
let creator_pubkey =
Pubkey::from_str(creator).expect("Failed to parse pubkey from creator!");
let cmv2_creator = derive_cmv2_pda(&creator_pubkey);
get_cm_creator_accounts(client, &cmv2_creator.to_string(), position)?
get_cm_creator_accounts(client, &cmv2_creator.to_string(), args.position)?
} else {
get_cm_creator_accounts(client, creator, position)?
get_cm_creator_accounts(client, creator, args.position)?
}
} else if let Some(mint_accounts_file) = mint_accounts_file {
} else if let Some(ref mint_accounts_file) = args.mint_accounts_file {
let file = File::open(mint_accounts_file)?;
let mint_accounts: Vec<String> = serde_json::from_reader(&file)?;
get_mint_account_infos(client, mint_accounts)?
Expand Down Expand Up @@ -184,7 +178,9 @@ pub fn snapshot_holders(
};

// Check that first creator is verified
if !creator_is_verified(&metadata.data.creators, position) {
if !creator_is_verified(&metadata.data.creators, args.position)
&& !args.allow_unverified
{
return;
}

Expand Down Expand Up @@ -247,20 +243,20 @@ pub fn snapshot_holders(
}
});

let prefix = if let Some(update_authority) = update_authority {
let prefix = if let Some(ref update_authority) = &args.update_authority {
update_authority.clone()
} else if let Some(creator) = creator {
creator.clone()
} else if let Some(mint_accounts_file) = mint_accounts_file {
str::replace(mint_accounts_file, ".json", "")
} else if let Some(creator) = args.creator {
creator
} else if let Some(mint_accounts_file) = args.mint_accounts_file {
str::replace(&mint_accounts_file, ".json", "")
} else {
return Err(anyhow!(
"Must specify either --update-authority or --candy-machine-id or --mint-accounts-file"
));
};

nft_holders.lock().unwrap().sort_unstable();
let mut file = File::create(format!("{}/{}_holders.json", output, prefix))?;
let mut file = File::create(format!("{}/{}_holders.json", args.output, prefix))?;
serde_json::to_writer_pretty(&mut file, &nft_holders)?;

Ok(())
Expand Down

0 comments on commit e97d0d2

Please sign in to comment.