Skip to content

feat: implement common types module (#212) - #318

Merged
truthixify merged 3 commits into
DistinctCodes:mainfrom
Sendi0011:feature/common-types-module-212
Oct 2, 2025
Merged

feat: implement common types module (#212)#318
truthixify merged 3 commits into
DistinctCodes:mainfrom
Sendi0011:feature/common-types-module-212

Conversation

@Sendi0011

Copy link
Copy Markdown
Contributor

Implement Common Types Module (#212)

🎯 Overview

This PR implements a shared common_types crate to provide consistent type definitions across all ManageHub contracts, enabling code reuse and maintaining type consistency throughout the system.

📦 Changes

New Crate: common_types

Created a standalone library crate at contracts/common_types/ containing shared types.

Types Implemented

1. SubscriptionPlan Enum

  • Daily - Daily subscription billing
  • Monthly - Monthly subscription billing
  • PayPerUse - Pay-as-you-go billing model

2. AttendanceAction Enum

  • ClockIn - User arrival action
  • ClockOut - User departure action

3. UserRole Enum

  • Member - Regular member with standard access
  • Staff - Staff member with elevated privileges
  • Admin - Administrator with full access
  • Visitor - Temporary visitor with limited access

4. MembershipStatus Enum

  • Active - Currently active membership
  • Expired - Expired membership
  • Revoked - Revoked membership
  • Inactive - Inactive membership

📁 Files Modified

Added

  • contracts/common_types/Cargo.toml
  • contracts/common_types/src/lib.rs
  • contracts/common_types/src/types.rs
  • contracts/common_types/src/test_contract.rs

Modified

  • 🔧 contracts/Cargo.toml - Added common_types to workspace
  • 🔧 contracts/manage_hub/Cargo.toml - Added common_types dependency
  • 🔧 contracts/manage_hub/src/types.rs - Refactored to use shared MembershipStatus

✅ Acceptance Criteria

All acceptance criteria from issue #212 have been met:

  • Created types.rs with all required enums
  • Applied #[contracttype] for Soroban serialization on all types
  • Added comprehensive documentation for each type
  • Exported types module in lib.rs
  • Module compiles successfully
  • Included unit tests for all enums
  • Created test contract demonstrating type usage
  • Types are usable in contracts (integrated with manage_hub)

🧪 Testing

Unit Tests

cd contracts/common_types
cargo test

All type variants tested for:

  • Creation and equality
  • Clone trait functionality
  • Soroban serialization compatibility

Integration Tests

Test contract (test_contract.rs) verifies:

  • ✓ Each type works in contract context
  • ✓ Types can be passed as parameters
  • ✓ Types can be returned from functions
  • ✓ Multiple types work together

Workspace Tests

cd contracts
cargo test --workspace

📚 Documentation

Each type includes:

  • Module-level documentation
  • Detailed variant descriptions
  • Usage context
  • Proper rustdoc formatting

🔄 Usage Example

use common_types::{SubscriptionPlan, UserRole, MembershipStatus};

#[contractimpl]
impl MyContract {
    pub fn subscribe(
        env: Env,
        user: Address,
        plan: SubscriptionPlan,
    ) -> Result<(), Error> {
        match plan {
            SubscriptionPlan::Monthly => {
                // Handle monthly subscription
            }
            SubscriptionPlan::Daily => {
                // Handle daily subscription
            }
            SubscriptionPlan::PayPerUse => {
                // Handle pay-per-use
            }
        }
        Ok(())
    }
}

🏗️ Architecture

Benefits

  • ✅ Single source of truth for common types
  • ✅ Consistent naming and behavior across contracts
  • ✅ Easy to maintain and extend
  • ✅ Compile-time type safety
  • ✅ Reduced code duplication

Integration

  • manage_hub now uses shared MembershipStatus from common_types
  • Ready for integration with membership_token and access_control contracts
  • Can be easily added to new contracts

🔗 Related Issues

Closes #212

🎉 Next Steps

This foundation enables:

  • Additional shared types (PaymentStatus, EventType, etc.)
  • Common utility functions
  • Shared validation logic
  • Cross-contract type safety guarantees

Ready for review! 🚀

- Create shared common_types crate with reusable types
- Add SubscriptionPlan enum (Daily, Monthly, PayPerUse)
- Add AttendanceAction enum (ClockIn, ClockOut)
- Add UserRole enum (Member, Staff, Admin, Visitor)
- Add MembershipStatus enum (Active, Expired, Revoked, Inactive)
- Apply #[contracttype] for Soroban serialization
- Add comprehensive documentation and unit tests
- Create test contract demonstrating type usage
- Integrate common_types into manage_hub contract
- Update workspace to include common_types crate
- Refactor manage_hub to use shared MembershipStatus

Resolves DistinctCodes#212
@vercel

vercel Bot commented Oct 2, 2025

Copy link
Copy Markdown

@Sendi0011 is attempting to deploy a commit to the naijabuz's projects Team on Vercel.

A member of the Team first needs to authorize it.

@truthixify

truthixify commented Oct 2, 2025

Copy link
Copy Markdown
Contributor

Thank you @Sendi0011

LGTM 🚀

@truthixify
truthixify merged commit 771c4b9 into DistinctCodes:main Oct 2, 2025
4 of 5 checks passed
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.

[CONTRACT] Implement Common Types Module

2 participants