Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Campaign Creation #26

Open
5 of 7 tasks
jdnichollsc opened this issue Dec 15, 2024 · 0 comments
Open
5 of 7 tasks

Implement Campaign Creation #26

jdnichollsc opened this issue Dec 15, 2024 · 0 comments
Assignees

Comments

@jdnichollsc
Copy link
Member

jdnichollsc commented Dec 15, 2024

Create Campaign Logic.

Definition of Done:

  • A campaign account can be created by a musical artist (creator).
  • The campaign includes title, description, funding goal, start/end dates, and status.
  • The campaign uses a Program Derived Address (PDA) for unique identification.

Tasks:

  • Define the Campaign struct.
  • Create an instruction to initialize a new campaign account.
  • Use validation for inputs (e.g., end_date > start_date, valid funding goal).
  • Write unit tests to verify campaign creation.

Code Example:

#[account]
pub struct Campaign {
    pub creator: Pubkey,              // Creator's wallet address
    pub title: String,                // Campaign title
    pub description: String,          // Campaign description
    pub goal_amount: u64,             // Funding goal in lamports
    pub current_amount: u64,          // Current amount pledged
    pub start_date: i64,              // Campaign start time
    pub end_date: i64,                // Campaign end time
    pub status: u8,                   // 0 = active, 1 = completed, 2 = cancelled
}

#[derive(Accounts)]
pub struct CreateCampaign<'info> {
    #[account(init, payer = creator, space = 8 + Campaign::MAX_SIZE, seeds = [b"campaign", creator.key().as_ref()], bump)]
    pub campaign: Account<'info, Campaign>,
    #[account(mut)]
    pub creator: Signer<'info>,
    pub system_program: Program<'info, System>,
}

pub fn create_campaign(
    ctx: Context<CreateCampaign>,
    title: String,
    description: String,
    goal_amount: u64,
    start_date: i64,
    end_date: i64,
) -> Result<()> {
    require!(end_date > start_date, ErrorCode::InvalidDates);
    require!(goal_amount > 0, ErrorCode::InvalidGoalAmount);

    let campaign = &mut ctx.accounts.campaign;
    campaign.creator = *ctx.accounts.creator.key;
    campaign.title = title;
    campaign.description = description;
    campaign.goal_amount = goal_amount;
    campaign.current_amount = 0;
    campaign.start_date = start_date;
    campaign.end_date = end_date;
    campaign.status = 0; // Active
    Ok(())
}
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

No branches or pull requests

2 participants