From e97d0d2893ca3d220fed1b9ff8d9b773528816b4 Mon Sep 17 00:00:00 2001 From: Samuel J Vanderwaal Date: Sun, 18 Sep 2022 16:52:42 -0800 Subject: [PATCH] allow unverified snapshots --- src/collections/migrate.rs | 2 +- src/opt.rs | 8 ++++++++ src/process_subcommands.rs | 20 +++++++++++------- src/snapshot/data.rs | 11 ++++++++++ src/snapshot/methods.rs | 42 +++++++++++++++++--------------------- 5 files changed, 52 insertions(+), 31 deletions(-) diff --git a/src/collections/migrate.rs b/src/collections/migrate.rs index 3b531be3..9df81eb7 100644 --- a/src/collections/migrate.rs +++ b/src/collections/migrate.rs @@ -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)? diff --git a/src/opt.rs b/src/opt.rs index bf411ae6..4f1e9590 100644 --- a/src/opt.rs +++ b/src/opt.rs @@ -752,6 +752,10 @@ pub enum SnapshotSubcommands { #[structopt(short, long)] mint_accounts_file: Option, + /// 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, @@ -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, diff --git a/src/process_subcommands.rs b/src/process_subcommands.rs index 9c8accfb..960bfee6 100644 --- a/src/process_subcommands.rs +++ b/src/process_subcommands.rs @@ -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}; @@ -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, @@ -414,6 +418,7 @@ pub async fn process_snapshot(client: &RpcClient, commands: SnapshotSubcommands) position, update_authority, v2, + allow_unverified, output, } => snapshot_mints( client, @@ -422,6 +427,7 @@ pub async fn process_snapshot(client: &RpcClient, commands: SnapshotSubcommands) position, update_authority, v2, + allow_unverified, output, }, ), diff --git a/src/snapshot/data.rs b/src/snapshot/data.rs index 52d22ada..d362e2f6 100644 --- a/src/snapshot/data.rs +++ b/src/snapshot/data.rs @@ -34,5 +34,16 @@ pub struct SnapshotMintsArgs { pub position: usize, pub update_authority: Option, pub v2: bool, + pub allow_unverified: bool, + pub output: String, +} + +pub struct SnapshotHoldersArgs { + pub creator: Option, + pub position: usize, + pub update_authority: Option, + pub mint_accounts_file: Option, + pub v2: bool, + pub allow_unverified: bool, pub output: String, } diff --git a/src/snapshot/methods.rs b/src/snapshot/methods.rs index 693dde79..74b2bf5c 100644 --- a/src/snapshot/methods.rs +++ b/src/snapshot/methods.rs @@ -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, )?; @@ -80,6 +81,7 @@ pub fn get_mint_accounts( creator: &Option, position: usize, update_authority: Option, + allow_unverified: bool, v2: bool, ) -> Result> { let spinner = create_spinner("Getting accounts..."); @@ -116,7 +118,7 @@ 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()); } } @@ -124,32 +126,24 @@ pub fn get_mint_accounts( Ok(mint_accounts) } -pub fn snapshot_holders( - client: &RpcClient, - update_authority: &Option, - creator: &Option, - position: usize, - mint_accounts_file: &Option, - 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 = serde_json::from_reader(&file)?; get_mint_account_infos(client, mint_accounts)? @@ -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; } @@ -247,12 +243,12 @@ 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" @@ -260,7 +256,7 @@ pub fn snapshot_holders( }; 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(())