;; burial-fund -- community janazah/burial assistance fund
(define-constant CONTRACT-OWNER tx-sender)
(define-constant ERR-AUTH (err u401))
(define-constant ERR-NONE (err u404))
(define-data-var total-pool uint u0)
(define-data-var claim-count uint u0)
(define-map contributors principal uint)
(define-map claims uint { family: (string-utf8 100), amount: uint, approved: bool, block: uint })
(define-public (contribute (amount uint))
(let ((prev (default-to u0 (map-get? contributors tx-sender))))
(map-set contributors tx-sender (+ prev amount))
(var-set total-pool (+ (var-get total-pool) amount)) (ok amount)))
(define-public (submit-claim (family (string-utf8 100)) (amount uint))
(let ((id (+ (var-get claim-count) u1)))
(var-set claim-count id)
(map-set claims id { family: family, amount: amount, approved: false, block: stacks-block-height })
(ok id)))
(define-public (approve-claim (id uint))
(let ((c (unwrap! (map-get? claims id) ERR-NONE)))
(asserts! (is-eq tx-sender CONTRACT-OWNER) ERR-AUTH)
(map-set claims id (merge c { approved: true }))
(var-set total-pool (- (var-get total-pool) (get amount c))) (ok true)))
(define-read-only (get-claim (id uint)) (map-get? claims id))
(define-read-only (get-pool) (var-get total-pool))