Source Code

;; SatGuard User Stats
(define-constant err-owner (err u1020))
(define-data-var admin principal tx-sender)
(define-map user-stats {who: principal,key: (string-ascii 20)} {val: uint})
(define-read-only (get-user-stat (who principal) (key (string-ascii 20))) (default-to {val: u0} (map-get? user-stats {who: who,key: key})))
(define-public (incr-stat (who principal) (key (string-ascii 20)) (amt uint))
  (let ((ex (get val (get-user-stat who key))))
    (asserts! (is-eq tx-sender (var-get admin)) err-owner)
    (map-set user-stats {who: who,key: key} {val: (+ ex amt)})
    (print {e: "stat-incr",who: who,key: key,amt: amt})
    (ok true)))
(define-public (set-stat (who principal) (key (string-ascii 20)) (val uint))
  (begin
    (asserts! (is-eq tx-sender (var-get admin)) err-owner)
    (map-set user-stats {who: who,key: key} {val: val})
    (print {e: "stat-set",who: who,key: key,val: val})
    (ok true)))
(define-read-only (get-pools-joined (who principal)) (get val (get-user-stat who "pools-joined")))
(define-read-only (get-claims-filed (who principal)) (get val (get-user-stat who "claims-filed")))
(define-read-only (get-votes-cast (who principal)) (get val (get-user-stat who "votes-cast")))

Functions (6)

FunctionAccessArgs
get-user-statread-onlywho: principal, key: (string-ascii 20
incr-statpublicwho: principal, key: (string-ascii 20
set-statpublicwho: principal, key: (string-ascii 20
get-pools-joinedread-onlywho: principal
get-claims-filedread-onlywho: principal
get-votes-castread-onlywho: principal