Source Code

;; SatGuard Notifier - on-chain announcements
(define-constant err-owner (err u1130))
(define-data-var admin principal tx-sender)
(define-data-var n-nonce uint u0)
(define-map notifications {id: uint} {title: (string-ascii 50),body: (string-utf8 200),by: principal,ca: uint,priority: uint})
(define-read-only (get-notification (id uint)) (map-get? notifications {id: id}))
(define-read-only (get-notif-count) (var-get n-nonce))
(define-public (notify (title (string-ascii 50)) (body (string-utf8 200)) (priority uint))
  (let ((nid (+ (var-get n-nonce) u1)))
    (asserts! (is-eq tx-sender (var-get admin)) err-owner)
    (map-set notifications {id: nid} {title: title,body: body,by: tx-sender,ca: block-height,priority: priority})
    (var-set n-nonce nid)
    (print {e: "notification",id: nid,title: title,priority: priority})
    (ok nid)))
(define-read-only (get-latest)
  (let ((n (var-get n-nonce)))
    (if (> n u0) (map-get? notifications {id: n}) none)))

Functions (4)

FunctionAccessArgs
get-notificationread-onlyid: uint
get-notif-countread-only
notifypublictitle: (string-ascii 50
get-latestread-only