Skip to content

fix: change contract_label from optional to required in CampaignParams#25

Merged
BigtoMantraDev merged 1 commit intomainfrom
fix/no-fallback-contract-label
Sep 18, 2025
Merged

fix: change contract_label from optional to required in CampaignParams#25
BigtoMantraDev merged 1 commit intomainfrom
fix/no-fallback-contract-label

Conversation

@BigtoMantraDev
Copy link
Collaborator

@BigtoMantraDev BigtoMantraDev commented Sep 18, 2025

Description and Motivation

Related Issues


Checklist:

  • I have read MANTRA's contribution guidelines.
  • My pull request has a sound title and description (not something vague like Update index.md)
  • All existing and new tests are passing.
  • I updated/added relevant documentation.
  • The code is formatted properly just fmt.
  • Clippy doesn't report any issues just lint.

Summary by CodeRabbit

  • New Features

    • Campaign setup now enforces a required contract label, ensuring every campaign includes a clear, consistent identifier.
  • Refactor

    • Updated campaign parameters to make the contract label mandatory instead of optional. Integrations and forms must provide this value when creating or updating campaigns to avoid validation errors.
  • Chores

    • Version bumped to 1.2.1 for the claimdrop standard package.

@coderabbitai
Copy link

coderabbitai bot commented Sep 18, 2025

Walkthrough

Version bumped mantra-claimdrop-std to 1.2.1 and changed CampaignParams.contract_label type from Option to String, making it required.

Changes

Cohort / File(s) Summary of Changes
Version bump
packages/mantra-claimdrop-std/Cargo.toml
Updated package version from 1.2.0 to 1.2.1.
API struct field update
packages/mantra-claimdrop-std/src/msg.rs
In CampaignParams, changed pub contract_label from Option<String> to String.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A hop and a bump to one-two-one,
Labels no longer hide or run.
Optional fields? We made them bold—
Strings required, neat and told.
Carrots aligned, code snug and tight,
Ship it swift, through moonlit byte. 🥕✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly and accurately describes the primary change—making contract_label non-optional in CampaignParams—and matches the src/msg.rs diff and the PR objectives. It is concise, specific, and readable, giving a reviewer immediate context without unnecessary detail. The Cargo.toml version bump is a minor follow-up and does not contradict the title's focus.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/no-fallback-contract-label

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@BigtoMantraDev BigtoMantraDev merged commit e30ecd6 into main Sep 18, 2025
4 of 5 checks passed
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 794fe40 and 627feb4.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is 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"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

🧩 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.

Suggested change
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.

Comment on lines 291 to 293
/// An optional label to be used for the instantiated claimdrop contract
pub contract_label: Option<String>,
pub contract_label: String,
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant