Source Code

;; dawah-tracker -- Islamic outreach activity tracker
(define-constant CONTRACT-OWNER tx-sender)
(define-constant ERR-AUTH (err u401))
(define-constant ERR-NONE (err u404))
(define-data-var activity-count uint u0)
(define-data-var total-reached uint u0)
(define-map activities uint { volunteer: principal, area: (string-utf8 100), method: (string-ascii 30), people-reached: uint, block: uint })
(define-map volunteer-stats principal { total-activities: uint, total-reached: uint })

(define-public (log-activity (area (string-utf8 100)) (method (string-ascii 30)) (people-reached uint))
  (let ((id (+ (var-get activity-count) u1))
        (prev (default-to { total-activities: u0, total-reached: u0 } (map-get? volunteer-stats tx-sender))))
    (var-set activity-count id)
    (var-set total-reached (+ (var-get total-reached) people-reached))
    (map-set activities id { volunteer: tx-sender, area: area, method: method, people-reached: people-reached, block: stacks-block-height })
    (map-set volunteer-stats tx-sender { total-activities: (+ (get total-activities prev) u1), total-reached: (+ (get total-reached prev) people-reached) })
    (ok id)))

(define-read-only (get-activity (id uint)) (map-get? activities id))
(define-read-only (get-volunteer (addr principal)) (map-get? volunteer-stats addr))
(define-read-only (get-total-reached) (var-get total-reached))

Functions (4)

FunctionAccessArgs
log-activitypublicarea: (string-utf8 100
get-activityread-onlyid: uint
get-volunteerread-onlyaddr: principal
get-total-reachedread-only