Skip to content

Feat/asset#190

Merged
ayshadogo merged 9 commits into
Dfunder:mainfrom
nafsonig:feat/asset
May 29, 2026
Merged

Feat/asset#190
ayshadogo merged 9 commits into
Dfunder:mainfrom
nafsonig:feat/asset

Conversation

@nafsonig
Copy link
Copy Markdown
Contributor

Implementation Complete ✅

I've successfully implemented comprehensive campaign initialization with all acceptance criteria. Here's what was added:

1. Creator Authorization & Initialization Guard (lib.rs)

// Authorization check: creator must authorize this call
creator.require_auth();

// Check if already initialized - can only initialize once
if get_campaign(&env).is_some() {
    panic_with_error(&env, Error::AlreadyInitialized);
}

Creator authorization required - Uses creator.require_auth() to ensure only the creator can initialize
Single initialization only - Panics with AlreadyInitialized if called twice

2. Enhanced Validation

All validations enforced in order:

  • goal_amount > 0
  • end_time > current ledger timestamp
  • at least 1 asset
  • 1-5 milestones ✓ (NEW)
  • Milestone amounts ascending
  • Final milestone.target_amount == goal_amount
// Validation 4: milestone count must be 1-5
let milestone_count = milestones.len() as u32;
if milestone_count == 0 || milestone_count > types::MAX_MILESTONES {
    panic_with_error(&env, Error::InvalidMilestoneCount);
}

3. Event Emission

Added CampaignEvent enum with Initialized variant:

let event = CampaignEvent::Initialized {
    creator,
    goal_amount,
    end_time,
    asset_count: accepted_assets.len() as u32,
    milestone_count,
};
env.events().publish(("campaign", "initialized"), event);

✅ Emits ("campaign", "initialized") event with all campaign details

4. New Error Types (types.rs)

  • InvalidMilestoneCount - Milestone count not 1-5
  • AlreadyInitialized - Campaign already exists
  • UnauthorizedCreator - For future authorization checks

5. Updated Error Handling

All error codes (including new ones) mapped in panic_with_error() for descriptive on-chain errors.

Complete Acceptance Criteria Met:

  • ✅ Function signature: fn initialize(env, creator, goal_amount, end_time, accepted_assets, milestones)
  • ✅ Creator authorization via creator.require_auth()
  • ✅ All validations: goal > 0, end_time in future, ≥1 asset, 1-5 milestones, ascending, final = goal
  • ✅ Single initialization check
  • campaign_initialized event emission

Made changes.

closes #170
closes #172

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 28, 2026

@nafsonig Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Copy link
Copy Markdown
Contributor

@ayshadogo ayshadogo left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution

@ayshadogo ayshadogo merged commit 880200b into Dfunder:main May 29, 2026
1 check failed
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.

Implement initialize function Define AssetInfo struct

2 participants