Skip to content

Implement logic for campaign creation #8

@0xdevcollins

Description

@0xdevcollins

Overview

This issue is to implement the core logic for campaign creation in our smart contract. The function create_campaign in contracts/boundless/src/logic/campaign.rs currently has a placeholder and needs a complete implementation according to the provided requirements.

Background

Our platform, as described in the README, relies on a robust and secure implementation of smart contracts to manage key functionalities, including campaign management. The Campaign struct in contracts/boundless/src/datatypes.rs and the CampaignManagement trait in contracts/boundless/src/interface.rs have already been defined. The logic needs to:

  • Generate a unique campaign ID
  • Create a new Campaign struct with a status of Status::Active
  • Store the campaign in persistent storage
  • Return the campaign ID

Requirements

  • Location: Implementation should be done in contracts/boundless/src/logic/campaign.rs within the create_campaign function.

  • Steps to Implement:

    1. Ensure the user (campaign owner) is authenticated by using owner.require_auth().
    2. Generate a unique campaign ID. Consider ways to ensure uniqueness (e.g., based on a counter or timestamp).
    3. Instantiate a Campaign struct with the following fields:
      • id: the newly generated unique ID
      • owner: provided owner address
      • title: provided title
      • description: provided description
      • funding_goal: provided funding goal (goal)
      • escrow_contract_id: provided escrow contract ID
      • milestones: provided milestones
      • backers: should be empty upon creation
      • status: set to Status::Active
    4. Store the campaign object in persistent storage.
    5. Return the campaign ID as the result

Technical Considerations

  • Ensure error handling aligns with the project standards. If any step fails, return a proper BoundlessError.
  • Verify the uniqueness of campaign IDs to avoid conflicts.
  • Maintain code readability and adhere to the coding style outlined in the repository.

Acceptance Criteria

  • The create_campaign function generates a unique campaign ID.
  • A new campaign is instantiated with all provided and required attributes, especially with the status set to Active.
  • The campaign is successfully stored in persistent storage.
  • The function returns the correct campaign ID upon successful execution.
  • Proper error handling is implemented for failure scenarios.

- [ ] - All new functionality is covered by tests.

Metadata

Metadata

Assignees

Labels

contractgood first issueGood for newcomersonlydust-waveContribute to awesome OSS repos during OnlyDust's open source week

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions