Skip to content

Issue #1 — Contract Scaffold, Storage Keys & Internal Helpers #598

@yusuftomilola

Description

@yusuftomilola

The workspace_booking contract manages coworking-space reservations on the Stellar network using Soroban smart contracts. Before any public functions can be implemented, we need the contract's foundational skeleton: the crate-level attributes, module wiring, storage key definitions, and the private helper functions that every other function will rely on.

Task

Inside contracts/workspace_booking/src/lib.rs, implement the following:

  1. Crate attributes#![no_std] and #![allow(deprecated)] (the deprecated allow is needed because env.events().publish() is used for cross-contract consistency across the ManageHub suite).
  2. Module declarations — declare mod errors, mod types, and #[cfg(test)] mod test (leave the test module declaration commented out for now — it will be uncommented in Issue folder #6).
  3. Re-exportspub use errors::Error and pub use types::{Booking, BookingStatus, Workspace, WorkspaceType}.
  4. Importsuse soroban_sdk::{contract, contractimpl, contracttype, symbol_short, token, Address, Env, String, Vec}.
  5. DataKey enum — tagged with #[contracttype], with the following variants:
    • Admin — stores the admin Address in instance storage.
    • PaymentToken — stores the payment token Address in instance storage.
    • Workspace(String) — persistent record keyed by workspace ID.
    • WorkspaceList — instance-level ordered list of all workspace IDs.
    • Booking(String) — persistent record keyed by booking ID.
    • MemberBookings(Address) — persistent list of booking IDs per member.
    • WorkspaceBookings(String) — persistent list of booking IDs per workspace.
  6. WorkspaceBookingContract struct — tagged with #[contract].
  7. #[contractimpl] block — implement the following private helper functions only (no public functions yet):
    • fn get_admin(env: &Env) -> Result<Address, Error> — reads DataKey::Admin from instance storage, returns Error::AdminNotSet if missing.
    • fn require_admin(env: &Env, caller: &Address) -> Result<(), Error> — calls get_admin, compares with caller, calls caller.require_auth(), returns Error::Unauthorized if caller is not the admin.
    • fn get_payment_token(env: &Env) -> Result<Address, Error> — reads DataKey::PaymentToken from instance storage, returns Error::PaymentTokenNotSet if missing.
    • fn is_slot_available(env: &Env, workspace_id: &String, start_time: u64, end_time: u64) -> bool — loads the WorkspaceBookings list for the workspace, iterates each booking, skips non-Active bookings, returns false if any active booking overlaps the requested slot using the half-open interval rule: existing.start_time < end_time && existing.end_time > start_time.

Files to modify

  • contracts/workspace_booking/src/lib.rscreate / replace entirely

Acceptance criteria

  • cargo check -p workspace_booking passes with zero errors.
  • cargo clippy -p workspace_booking -- -D warnings passes with zero warnings.
  • All 7 DataKey variants are present and correctly typed.
  • get_admin returns Error::AdminNotSet when storage is empty.
  • require_admin returns Error::Unauthorized for a non-admin caller.
  • is_slot_available correctly detects overlapping active bookings and ignores cancelled/completed ones.
  • No public functions are defined yet.

Technical notes

  • Use env.storage().instance() for Admin, PaymentToken, and WorkspaceList.
  • Use env.storage().persistent() for per-record data (Workspace, Booking, MemberBookings, WorkspaceBookings).
  • The overlap check is: existing.start_time < end_time && existing.end_time > start_time.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions