Source Code

;; tent-share -- camping tent sharing for Islamic events
(define-data-var tent-count uint u0)
(define-map tents uint { owner: principal, size: (string-ascii 10), capacity: uint, available: bool })
(define-map bookings { tent-id: uint, user: principal } uint)
(define-public (register-tent (size (string-ascii 10)) (capacity uint))
  (let ((id (+ (var-get tent-count) u1)))
    (var-set tent-count id)
    (map-set tents id { owner: tx-sender, size: size, capacity: capacity, available: true }) (ok id)))
(define-public (book-tent (tent-id uint) (days uint))
  (let ((t (unwrap! (map-get? tents tent-id) (err u404))))
    (map-set tents tent-id (merge t { available: false }))
    (map-set bookings { tent-id: tent-id, user: tx-sender } days) (ok days)))
(define-public (return-tent (tent-id uint))
  (let ((t (unwrap! (map-get? tents tent-id) (err u404))))
    (map-set tents tent-id (merge t { available: true })) (ok true)))
(define-read-only (get-tent (id uint)) (map-get? tents id))

Functions (4)

FunctionAccessArgs
register-tentpublicsize: (string-ascii 10
book-tentpublictent-id: uint, days: uint
return-tentpublictent-id: uint
get-tentread-onlyid: uint