-
Notifications
You must be signed in to change notification settings - Fork 134
Closed
Labels
Beta-CampaignCampaign: Beta-CampaignCampaign: Beta-Campaigngood first issueGood for newcomersGood for newcomerssoroban-contract
Description
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:
- Crate attributes —
#![no_std]and#.publish()is used for cross-contract consistency across the ManageHub suite). - 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). - Re-exports —
pub use errors::Errorandpub use types::{Booking, BookingStatus, Workspace, WorkspaceType}. - Imports —
use soroban_sdk::{contract, contractimpl, contracttype, symbol_short, token, Address, Env, String, Vec}. DataKeyenum — tagged with#[contracttype], with the following variants:Admin— stores the adminAddressin instance storage.PaymentToken— stores the payment tokenAddressin 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.
WorkspaceBookingContractstruct — tagged with#[contract].#[contractimpl]block — implement the following private helper functions only (no public functions yet):fn get_admin(env: &Env) -> Result<Address, Error>— readsDataKey::Adminfrom instance storage, returnsError::AdminNotSetif missing.fn require_admin(env: &Env, caller: &Address) -> Result<(), Error>— callsget_admin, compares withcaller, callscaller.require_auth(), returnsError::Unauthorizedif caller is not the admin.fn get_payment_token(env: &Env) -> Result<Address, Error>— readsDataKey::PaymentTokenfrom instance storage, returnsError::PaymentTokenNotSetif missing.fn is_slot_available(env: &Env, workspace_id: &String, start_time: u64, end_time: u64) -> bool— loads theWorkspaceBookingslist for the workspace, iterates each booking, skips non-Activebookings, returnsfalseif 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.rs← create / replace entirely
Acceptance criteria
-
cargo check -p workspace_bookingpasses with zero errors. -
cargo clippy -p workspace_booking -- -D warningspasses with zero warnings. - All 7
DataKeyvariants are present and correctly typed. -
get_adminreturnsError::AdminNotSetwhen storage is empty. -
require_adminreturnsError::Unauthorizedfor a non-admin caller. -
is_slot_availablecorrectly detects overlapping active bookings and ignores cancelled/completed ones. - No public functions are defined yet.
Technical notes
- Use
env.storage().instance()forAdmin,PaymentToken, andWorkspaceList. - 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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Beta-CampaignCampaign: Beta-CampaignCampaign: Beta-Campaigngood first issueGood for newcomersGood for newcomerssoroban-contract