From 4ab54041b0f5b9f067935741300b438da9580a80 Mon Sep 17 00:00:00 2001 From: MarkSackerberg <93528482+MarkSackerberg@users.noreply.github.com> Date: Tue, 17 Sep 2024 16:52:34 +0200 Subject: [PATCH] Allow hiddenSettings with incomplete cache (#488) * initial * add test --- script/sugar-cli-test.sh | 30 +++++++++++++++++++++++++++--- src/deploy/process.rs | 21 +++++++++++++++++---- src/reveal/process.rs | 28 +++++++++++++++++++++++++++- 3 files changed, 71 insertions(+), 8 deletions(-) diff --git a/script/sugar-cli-test.sh b/script/sugar-cli-test.sh index 85ca5ecc..31b99dd1 100755 --- a/script/sugar-cli-test.sh +++ b/script/sugar-cli-test.sh @@ -43,6 +43,7 @@ function default_settings() { ITEMS=10 MULTIPLE=1 TOKEN_STANDARD="nft" + LIMITED_FILES="n" # creates only one filepair to test hiddenSettings warning RESET="Y" EXT="png" @@ -122,12 +123,13 @@ echo "5. hidden settings" echo "6. animation" echo "7. sugar launch" echo "8. programmable NFT" +echo "9. hidden settings with limited upload" if [ -f "$RESUME_FILE" ]; then - echo "9. previous run ($(RED "resume"))" - echo -n "$(CYN "Select test template [1-9]") (default 3): " + echo "10. previous run ($(RED "resume"))" + echo -n "$(CYN "Select test template [1-10]") (default 3): " else - echo -n "$(CYN "Select test template [1-8]") (default 3): " + echo -n "$(CYN "Select test template [1-9]") (default 3): " fi read Template @@ -168,6 +170,12 @@ case "$Template" in TOKEN_STANDARD="pnft" ;; 9) + devnet_env + max_settings + HIDDEN="Y" + LIMITED_FILES="Y" + ;; + 10) source $RESUME_FILE RESUME=1 RESET="n" @@ -617,6 +625,13 @@ if [ $RESUME -eq 0 ]; then # initialises the assets - this will be multiple copies of the same # image/json pair with a new index INDEX="image" + TEMP_ITEMS=$ITEMS + if [ "$LIMITED_FILES" = "Y" ]; then + TEMP_ITEMS=$ITEMS + ITEMS=1 + printf "TEMP_ITEMS updated to $TEMP_ITEMS" + fi + for ((i = 0; i < $ITEMS; i++)); do if [ ! "$TEST_IMAGE" = "Y" ]; then INDEX=$i @@ -636,6 +651,8 @@ if [ $RESUME -eq 0 ]; then fi printf "$METADATA" "$NAME" "$NAME" "$MEDIA_NAME" "$ANIMATION_URL" "$MEDIA_NAME" "$MEDIA_TYPE" "$ANIMATION_FILE" "$CATEGORY" > "$ASSETS_DIR/$i.json" done + + ITEMS=$TEMP_ITEMS rm "$ASSETS_DIR/template_image.$EXT" # quietly removes the animation template (it might not exist) rm -f "$ASSETS_DIR/template_animation.mp4" @@ -658,6 +675,12 @@ if [ $RESUME -eq 0 ]; then METADATA_HASH=`sha256sum "$ASSETS_DIR/collection.json" | cut -d ' ' -f 1` echo "\"-1\":{\"name\":\"[$TIMESTAMP] $NAME\",\"image_hash\":\"$COLLECTION_HASH\",\"image_link\":\"$COLLECTION_PNG\",\"metadata_hash\":\"$METADATA_HASH\",\"metadata_link\":\"$COLLECTION_URL\",\"onChain\":false}," >> $CACHE_FILE + TEMP_ITEMS=$ITEMS + if [ "$LIMITED_FILES" = "Y" ]; then + TEMP_ITEMS=$ITEMS + ITEMS=1 + printf "TEMP_ITEMS updated to $TEMP_ITEMS" + fi for ((i = 0; i < $ITEMS; i++)); do if [ "$i" -gt "0" ]; then echo -n "," >> $CACHE_FILE @@ -673,6 +696,7 @@ if [ $RESUME -eq 0 ]; then METADATA_HASH=`sha256sum "$ASSETS_DIR/$i.json" | cut -d ' ' -f 1` echo -n "\"$i\":{\"name\":\"$NAME\",\"image_hash\":\"$MEDIA_HASH\",\"image_link\":\"$PNG\",\"metadata_hash\":\"$METADATA_HASH\",\"metadata_link\":\"$METADATA_URL\",\"onChain\":false}" >> $CACHE_FILE done + ITEMS=$TEMP_ITEMS echo -n "}}" >> $CACHE_FILE fi diff --git a/src/deploy/process.rs b/src/deploy/process.rs index a336bf53..955ae0fa 100644 --- a/src/deploy/process.rs +++ b/src/deploy/process.rs @@ -92,18 +92,31 @@ pub async fn process_deploy(args: DeployArgs) -> Result<()> { let cache_items_sans_collection = (cache.items.len() - collection_in_cache as usize) as u64; - if num_items != cache_items_sans_collection { + if !hidden && num_items != cache_items_sans_collection { return Err(anyhow!( "Number of items ({}) do not match cache items ({}). Item number in the config should only include asset files, not the collection file.", num_items, cache_items_sans_collection )); - } else { - check_symbol(&config_data.symbol)?; - check_seller_fee_basis_points(config_data.seller_fee_basis_points)?; + } else if hidden && num_items != cache_items_sans_collection { + println!( + "{}", + style(format!( + "Warning: Number of items ({}) do not match cache items ({}). + {} items are missing. Revealing will not work correctly.", + num_items, + cache_items_sans_collection, + num_items.saturating_sub(cache_items_sans_collection) + )) + .yellow() + .bold() + ); } + check_symbol(&config_data.symbol)?; + check_seller_fee_basis_points(config_data.seller_fee_basis_points)?; + let total_steps = 2 + if candy_machine_address.is_empty() { collection_in_cache as u8 } else { diff --git a/src/reveal/process.rs b/src/reveal/process.rs index ae02993f..b42bd00a 100644 --- a/src/reveal/process.rs +++ b/src/reveal/process.rs @@ -73,13 +73,39 @@ pub async fn process_reveal(args: RevealArgs) -> Result<()> { let config = get_config_data(&args.config)?; // If it's not a Hidden Settings mint, return an error. - let hidden_settings = if let Some(settings) = config.hidden_settings { + let hidden_settings = if let Some(ref settings) = config.hidden_settings { settings } else { return Err(anyhow!("Candy machine is not a Hidden Settings mint.")); }; let cache = load_cache(&args.cache, false)?; + + // Check if the cache file is incomplete + let num_items = config.number; + let hidden = config.hidden_settings.is_some(); + let collection_in_cache = cache.items.get("-1").is_some(); + let cache_items_sans_collection = (cache.items.len() - collection_in_cache as usize) as u64; + + if hidden && num_items != cache_items_sans_collection { + let warning = format!( + "+---------------------------------+\n\ + {} {} ITEMS MISSING IN CACHE FILE! \n\ + +---------------------------------+", + WARNING_EMOJI, + num_items.saturating_sub(cache_items_sans_collection) + ); + println!( + "\n{}\n{}\n", + style(warning).bold().yellow(), + style( + " Revealing might fail. \ + It is recommended to run 'sugar upload' again.", + ) + .italic() + .yellow() + ) + } let sugar_config = sugar_setup(args.keypair, args.rpc_url.clone())?; let anchor_client = setup_client(&sugar_config)?; let program = anchor_client.program(CANDY_MACHINE_ID);