Source Code

;; SatGuard Reputation
(define-constant err-owner (err u900))
(define-constant err-amt (err u901))
(define-data-var admin principal tx-sender)
(define-map rep-scores {who: principal} {score: uint,level: uint,last: uint})
(define-read-only (get-rep (who principal)) (default-to {score: u0,level: u0,last: u0} (map-get? rep-scores {who: who})))
(define-read-only (get-level (who principal)) (get level (get-rep who)))
(define-public (update-rep (who principal) (pts uint))
  (let ((ex (get-rep who))
        (ns (+ (get score ex) pts))
        (nl (if (>= ns u10000) u5 (if (>= ns u5000) u4 (if (>= ns u2000) u3 (if (>= ns u500) u2 (if (>= ns u100) u1 u0)))))))
    (asserts! (is-eq tx-sender (var-get admin)) err-owner)
    (asserts! (> pts u0) err-amt)
    (map-set rep-scores {who: who} {score: ns,level: nl,last: block-height})
    (print {e: "rep-updated",who: who,score: ns,level: nl})
    (ok nl)))
(define-public (slash-rep (who principal) (pts uint))
  (let ((ex (get-rep who))
        (ns (if (>= (get score ex) pts) (- (get score ex) pts) u0)))
    (asserts! (is-eq tx-sender (var-get admin)) err-owner)
    (map-set rep-scores {who: who} {score: ns,level: (if (>= ns u100) (get level ex) u0),last: block-height})
    (print {e: "rep-slashed",who: who,pts: pts})
    (ok true)))

Functions (4)

FunctionAccessArgs
get-repread-onlywho: principal
get-levelread-onlywho: principal
update-reppublicwho: principal, pts: uint
slash-reppublicwho: principal, pts: uint