;; zakat-pool -- zakat collection and distribution pool
(define-constant CONTRACT-OWNER tx-sender)
(define-data-var pool uint u0)
(define-data-var dist-count uint u0)
(define-map payers principal uint)
(define-map distributions uint { recipient: (string-ascii 30), amount: uint, block: uint })
(define-public (pay-zakat (amount uint))
(let ((prev (default-to u0 (map-get? payers tx-sender))))
(var-set pool (+ (var-get pool) amount))
(map-set payers tx-sender (+ prev amount)) (ok amount)))
(define-public (distribute (recipient (string-ascii 30)) (amount uint))
(let ((id (+ (var-get dist-count) u1)))
(asserts! (is-eq tx-sender CONTRACT-OWNER) (err u401))
(var-set dist-count id)
(var-set pool (- (var-get pool) amount))
(map-set distributions id { recipient: recipient, amount: amount, block: stacks-block-height }) (ok id)))
(define-read-only (get-pool) (var-get pool))
(define-read-only (get-dist (id uint)) (map-get? distributions id))