Source Code

;; hajj-guide -- Hajj travel guide and tips registry
(define-constant CONTRACT-OWNER tx-sender)
(define-constant ERR-AUTH (err u401))
(define-constant ERR-NONE (err u404))
(define-data-var guide-count uint u0)
(define-data-var tip-count uint u0)
(define-map guides uint { author: principal, title: (string-utf8 100), category: (string-ascii 20), upvotes: uint, block: uint })
(define-map tips uint { guide-id: uint, author: principal, content: (string-utf8 200), block: uint })

(define-public (create-guide (title (string-utf8 100)) (category (string-ascii 20)))
  (let ((id (+ (var-get guide-count) u1)))
    (var-set guide-count id)
    (map-set guides id { author: tx-sender, title: title, category: category, upvotes: u0, block: stacks-block-height })
    (ok id)))

(define-public (upvote-guide (id uint))
  (let ((g (unwrap! (map-get? guides id) ERR-NONE)))
    (map-set guides id (merge g { upvotes: (+ (get upvotes g) u1) })) (ok true)))

(define-public (add-tip (guide-id uint) (content (string-utf8 200)))
  (let ((id (+ (var-get tip-count) u1)))
    (var-set tip-count id)
    (map-set tips id { guide-id: guide-id, author: tx-sender, content: content, block: stacks-block-height })
    (ok id)))

(define-read-only (get-guide (id uint)) (map-get? guides id))
(define-read-only (get-tip (id uint)) (map-get? tips id))
(define-read-only (get-guide-count) (var-get guide-count))

Functions (6)

FunctionAccessArgs
create-guidepublictitle: (string-utf8 100
upvote-guidepublicid: uint
add-tippublicguide-id: uint, content: (string-utf8 200
get-guideread-onlyid: uint
get-tipread-onlyid: uint
get-guide-countread-only