Skip to content

Commit 4ab5404

Browse files
Allow hiddenSettings with incomplete cache (#488)
* initial * add test
1 parent 28648e6 commit 4ab5404

3 files changed

Lines changed: 71 additions & 8 deletions

File tree

script/sugar-cli-test.sh

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ function default_settings() {
4343
ITEMS=10
4444
MULTIPLE=1
4545
TOKEN_STANDARD="nft"
46+
LIMITED_FILES="n" # creates only one filepair to test hiddenSettings warning
4647

4748
RESET="Y"
4849
EXT="png"
@@ -122,12 +123,13 @@ echo "5. hidden settings"
122123
echo "6. animation"
123124
echo "7. sugar launch"
124125
echo "8. programmable NFT"
126+
echo "9. hidden settings with limited upload"
125127

126128
if [ -f "$RESUME_FILE" ]; then
127-
echo "9. previous run ($(RED "resume"))"
128-
echo -n "$(CYN "Select test template [1-9]") (default 3): "
129+
echo "10. previous run ($(RED "resume"))"
130+
echo -n "$(CYN "Select test template [1-10]") (default 3): "
129131
else
130-
echo -n "$(CYN "Select test template [1-8]") (default 3): "
132+
echo -n "$(CYN "Select test template [1-9]") (default 3): "
131133
fi
132134

133135
read Template
@@ -168,6 +170,12 @@ case "$Template" in
168170
TOKEN_STANDARD="pnft"
169171
;;
170172
9)
173+
devnet_env
174+
max_settings
175+
HIDDEN="Y"
176+
LIMITED_FILES="Y"
177+
;;
178+
10)
171179
source $RESUME_FILE
172180
RESUME=1
173181
RESET="n"
@@ -617,6 +625,13 @@ if [ $RESUME -eq 0 ]; then
617625
# initialises the assets - this will be multiple copies of the same
618626
# image/json pair with a new index
619627
INDEX="image"
628+
TEMP_ITEMS=$ITEMS
629+
if [ "$LIMITED_FILES" = "Y" ]; then
630+
TEMP_ITEMS=$ITEMS
631+
ITEMS=1
632+
printf "TEMP_ITEMS updated to $TEMP_ITEMS"
633+
fi
634+
620635
for ((i = 0; i < $ITEMS; i++)); do
621636
if [ ! "$TEST_IMAGE" = "Y" ]; then
622637
INDEX=$i
@@ -636,6 +651,8 @@ if [ $RESUME -eq 0 ]; then
636651
fi
637652
printf "$METADATA" "$NAME" "$NAME" "$MEDIA_NAME" "$ANIMATION_URL" "$MEDIA_NAME" "$MEDIA_TYPE" "$ANIMATION_FILE" "$CATEGORY" > "$ASSETS_DIR/$i.json"
638653
done
654+
655+
ITEMS=$TEMP_ITEMS
639656
rm "$ASSETS_DIR/template_image.$EXT"
640657
# quietly removes the animation template (it might not exist)
641658
rm -f "$ASSETS_DIR/template_animation.mp4"
@@ -658,6 +675,12 @@ if [ $RESUME -eq 0 ]; then
658675
METADATA_HASH=`sha256sum "$ASSETS_DIR/collection.json" | cut -d ' ' -f 1`
659676
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
660677

678+
TEMP_ITEMS=$ITEMS
679+
if [ "$LIMITED_FILES" = "Y" ]; then
680+
TEMP_ITEMS=$ITEMS
681+
ITEMS=1
682+
printf "TEMP_ITEMS updated to $TEMP_ITEMS"
683+
fi
661684
for ((i = 0; i < $ITEMS; i++)); do
662685
if [ "$i" -gt "0" ]; then
663686
echo -n "," >> $CACHE_FILE
@@ -673,6 +696,7 @@ if [ $RESUME -eq 0 ]; then
673696
METADATA_HASH=`sha256sum "$ASSETS_DIR/$i.json" | cut -d ' ' -f 1`
674697
echo -n "\"$i\":{\"name\":\"$NAME\",\"image_hash\":\"$MEDIA_HASH\",\"image_link\":\"$PNG\",\"metadata_hash\":\"$METADATA_HASH\",\"metadata_link\":\"$METADATA_URL\",\"onChain\":false}" >> $CACHE_FILE
675698
done
699+
ITEMS=$TEMP_ITEMS
676700

677701
echo -n "}}" >> $CACHE_FILE
678702
fi

src/deploy/process.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,31 @@ pub async fn process_deploy(args: DeployArgs) -> Result<()> {
9292

9393
let cache_items_sans_collection = (cache.items.len() - collection_in_cache as usize) as u64;
9494

95-
if num_items != cache_items_sans_collection {
95+
if !hidden && num_items != cache_items_sans_collection {
9696
return Err(anyhow!(
9797
"Number of items ({}) do not match cache items ({}).
9898
Item number in the config should only include asset files, not the collection file.",
9999
num_items,
100100
cache_items_sans_collection
101101
));
102-
} else {
103-
check_symbol(&config_data.symbol)?;
104-
check_seller_fee_basis_points(config_data.seller_fee_basis_points)?;
102+
} else if hidden && num_items != cache_items_sans_collection {
103+
println!(
104+
"{}",
105+
style(format!(
106+
"Warning: Number of items ({}) do not match cache items ({}).
107+
{} items are missing. Revealing will not work correctly.",
108+
num_items,
109+
cache_items_sans_collection,
110+
num_items.saturating_sub(cache_items_sans_collection)
111+
))
112+
.yellow()
113+
.bold()
114+
);
105115
}
106116

117+
check_symbol(&config_data.symbol)?;
118+
check_seller_fee_basis_points(config_data.seller_fee_basis_points)?;
119+
107120
let total_steps = 2 + if candy_machine_address.is_empty() {
108121
collection_in_cache as u8
109122
} else {

src/reveal/process.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,39 @@ pub async fn process_reveal(args: RevealArgs) -> Result<()> {
7373
let config = get_config_data(&args.config)?;
7474

7575
// If it's not a Hidden Settings mint, return an error.
76-
let hidden_settings = if let Some(settings) = config.hidden_settings {
76+
let hidden_settings = if let Some(ref settings) = config.hidden_settings {
7777
settings
7878
} else {
7979
return Err(anyhow!("Candy machine is not a Hidden Settings mint."));
8080
};
8181

8282
let cache = load_cache(&args.cache, false)?;
83+
84+
// Check if the cache file is incomplete
85+
let num_items = config.number;
86+
let hidden = config.hidden_settings.is_some();
87+
let collection_in_cache = cache.items.get("-1").is_some();
88+
let cache_items_sans_collection = (cache.items.len() - collection_in_cache as usize) as u64;
89+
90+
if hidden && num_items != cache_items_sans_collection {
91+
let warning = format!(
92+
"+---------------------------------+\n\
93+
{} {} ITEMS MISSING IN CACHE FILE! \n\
94+
+---------------------------------+",
95+
WARNING_EMOJI,
96+
num_items.saturating_sub(cache_items_sans_collection)
97+
);
98+
println!(
99+
"\n{}\n{}\n",
100+
style(warning).bold().yellow(),
101+
style(
102+
" Revealing might fail. \
103+
It is recommended to run 'sugar upload' again.",
104+
)
105+
.italic()
106+
.yellow()
107+
)
108+
}
83109
let sugar_config = sugar_setup(args.keypair, args.rpc_url.clone())?;
84110
let anchor_client = setup_client(&sugar_config)?;
85111
let program = anchor_client.program(CANDY_MACHINE_ID);

0 commit comments

Comments
 (0)