Source Code

;; ummah-help -- community mutual aid requests
(define-data-var req-count uint u0)
(define-map requests uint { author: principal, need: (string-ascii 50), amount: uint, filled: bool, block: uint })
(define-map helpers { req-id: uint, helper: principal } uint)
(define-public (post-request (need (string-ascii 50)) (amount uint))
  (let ((id (+ (var-get req-count) u1)))
    (var-set req-count id)
    (map-set requests id { author: tx-sender, need: need, amount: amount, filled: false, block: stacks-block-height }) (ok id)))
(define-public (help-request (req-id uint) (amount uint))
  (begin (map-set helpers { req-id: req-id, helper: tx-sender } amount) (ok amount)))
(define-public (mark-filled (id uint))
  (let ((r (unwrap! (map-get? requests id) (err u404))))
    (map-set requests id (merge r { filled: true })) (ok true)))
(define-read-only (get-request (id uint)) (map-get? requests id))

Functions (4)

FunctionAccessArgs
post-requestpublicneed: (string-ascii 50
help-requestpublicreq-id: uint, amount: uint
mark-filledpublicid: uint
get-requestread-onlyid: uint