fix: change contract_label from optional to required in CampaignParams#25
Conversation
WalkthroughVersion bumped mantra-claimdrop-std to 1.2.1 and changed CampaignParams.contract_label type from Option to String, making it required. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (2)
packages/mantra-claimdrop-std/Cargo.toml(1 hunks)packages/mantra-claimdrop-std/src/msg.rs(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Lints
| name = "mantra-claimdrop-std" | ||
| repository.workspace = true | ||
| version = "1.2.0" | ||
| version = "1.2.1" |
There was a problem hiding this comment.
🧩 Analysis chain
Breaking API change → bump major version (not patch).
Changing a public field type in a public struct (Option → String) is semver-breaking. Patch bump to 1.2.1 is insufficient; bump to 2.0.0 (or reconsider the change).
Apply:
-version = "1.2.1"
+version = "2.0.0"Then verify dependents and call sites:
🏁 Script executed:
#!/bin/bash
# List crates depending on mantra-claimdrop-std
rg -nP -C3 '\bmantra-claimdrop-std\b' -g 'Cargo.toml'
# Find CampaignParams initializations likely needing `contract_label`
rg -nP --type=rust -C3 '\bCampaignParams\s*\{'Length of output: 1571
Bump major version to 2.0.0 — breaking API change
Changing CampaignParams.contract_label from Option → String is semver‑breaking; patch 1.2.1 is insufficient.
Apply:
-version = "1.2.1"
+version = "2.0.0"Locations: packages/mantra-claimdrop-std/Cargo.toml:10; packages/mantra-claimdrop-std/src/msg.rs (CampaignParams → pub contract_label: String). rg checks show no other Cargo.toml in this repo references mantra-claimdrop-std and no external CampaignParams initializations found — still require major bump before publishing.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| version = "1.2.1" | |
| version = "2.0.0" |
🤖 Prompt for AI Agents
In packages/mantra-claimdrop-std/Cargo.toml around line 10, the crate version
must be bumped to 2.0.0 because changing CampaignParams.contract_label from
Option<String> to String is a breaking API change; update version = "2.0.0".
Also update packages/mantra-claimdrop-std/src/msg.rs where CampaignParams
defines pub contract_label: Option<String> — change the field type to pub
contract_label: String, and adjust any constructors, Default/From
implementations, serde Deserialize/Serialize expectations, and places building
CampaignParams so they supply a String (or enforce non-empty) instead of Option.
Ensure tests and any module-level docs/types reflect the new non-optional
contract_label before publishing.
| /// An optional label to be used for the instantiated claimdrop contract | ||
| pub contract_label: Option<String>, | ||
| pub contract_label: String, | ||
| } |
There was a problem hiding this comment.
🛠️ Refactor suggestion
🧩 Analysis chain
Doc says “optional” but field is now required; also add validation for non-empty label.
Fix the comment and enforce at runtime to prevent empty/whitespace labels slipping through.
Change the doc:
- /// An optional label to be used for the instantiated claimdrop contract
+ /// Label to be used for the instantiated claimdrop contract (required)
pub contract_label: String,Add validation (and call it wherever params are validated):
impl CampaignParams {
pub fn validate_contract_label(&self) -> Result<(), ContractError> {
ensure!(
!self.contract_label.trim().is_empty(),
ContractError::InvalidCampaignParam {
param: "contract_label".to_string(),
reason: "cannot be empty".to_string(),
}
);
Ok(())
}
}Optional: align a MAX_LABEL_LENGTH constant with chain constraints and check length.
Verification:
- Regenerate and commit JSON schema so downstream clients see contract_label as required.
- Ensure all CreateCampaign payloads include contract_label.
🏁 Script executed:
#!/bin/bash
# Check for schema artifacts referencing `contract_label` (if schema dir exists)
fd schema | xargs -r rg -n 'contract_label' -n -C2
# Find call sites that might miss the new required field
rg -nP --type=rust -C3 '\bCampaignParams\s*\{(.*?)\}' | rg -nPv 'contract_label\s*:'Length of output: 0
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "=== repo root ==="
pwd
echo
echo "=== Find files mentioning contract_label ==="
rg -n --hidden --ignore-file .gitignore 'contract_label' || true
echo
echo "=== Show package file if exists ==="
if [ -f packages/mantra-claimdrop-std/src/msg.rs ]; then
echo "=== packages/mantra-claimdrop-std/src/msg.rs (around lines 250-320) ==="
sed -n '1,220p' packages/mantra-claimdrop-std/src/msg.rs || true
echo "----"
sed -n '220,360p' packages/mantra-claimdrop-std/src/msg.rs || true
else
echo "packages/mantra-claimdrop-std/src/msg.rs not found"
fi
echo
echo "=== Find CampaignParams definition and impl ==="
rg -n --hidden --ignore-file .gitignore 'struct\s+CampaignParams' || true
rg -n --hidden --ignore-file .gitignore 'impl\s+CampaignParams' || true
rg -n --hidden --ignore-file .gitignore '\bCampaignParams\b' -S -C3 || true
echo
echo "=== Search for .schema, schema.json, or schema dir ==="
rg -n --hidden --ignore-file .gitignore 'schema|schema.json|schema.rs' || true
fd --hidden schema || true
fd --hidden -I -t f '*.json' | xargs -r rg -n 'contract_label' || true
echo
echo "=== Search for struct literal initializers of CampaignParams (approx) ==="
rg -nP --hidden --ignore-file .gitignore '\bCampaignParams\s*{\s*' -S -C3 || true
# Search for patterns that create CampaignParams via Default or .. shorthand
rg -nP --hidden --ignore-file .gitignore 'CampaignParams::new|CampaignParams::default|CampaignParams\s*{[^}]*}' -S -C3 || true
echo "=== Search for CreateCampaign or related messages needing contract_label ==="
rg -n --hidden --ignore-file .gitignore 'CreateCampaign|create_campaign|createCampaign' -S -C3 || true
echo "=== End ==="Length of output: 109751
Fix contract_label doc and add runtime validation
Doc says "optional" but the field is a required String and there's no runtime check — update docs/examples and reject empty/whitespace labels.
- Change the doc on CampaignParams.contract_label:
- /// An optional label to be used for the instantiated claimdrop contract
+ /// Label to be used for the instantiated claimdrop contract (required)
pub contract_label: String,- Add validation in impl CampaignParams and call it from the existing params validation pipeline:
pub fn validate_contract_label(&self) -> Result<(), ContractError> {
ensure!(
!self.contract_label.trim().is_empty(),
ContractError::InvalidCampaignParam {
param: "contract_label".to_string(),
reason: "cannot be empty".to_string(),
}
);
Ok(())
}- Optional: add MAX_LABEL_LENGTH constant and check length to match chain limits.
- Update packages/mantra-claimdrop-std/README.md example (and any CreateCampaign payload sites) to include contract_label.
- Regenerate and commit JSON schema so downstream clients see contract_label as required.
packages/mantra-claimdrop-std/src/msg.rs: change doc and add validation; call validate_contract_label where other validate_* methods are invoked.
Description and Motivation
Related Issues
Checklist:
Update index.md)just fmt.just lint.Summary by CodeRabbit
New Features
Refactor
Chores