Source Code

;; SatGuard Governance Proposals
(define-constant err-owner (err u200))
(define-constant err-nf (err u201))
(define-constant err-dup (err u202))
(define-constant err-amt (err u203))
(define-constant PR-ACT u1)
(define-constant PR-EXE u2)
(define-constant PR-CAN u3)
(define-data-var p-nonce uint u0)
(define-map proposals {id: uint} {cr: principal,t: (string-ascii 50),d: (string-utf8 200),st: uint,ca: uint,vf: uint,va: uint})
(define-read-only (get-proposal (id uint)) (map-get? proposals {id: id}))
(define-read-only (get-proposal-count) (var-get p-nonce))
(define-public (create-proposal (t (string-ascii 50)) (d (string-utf8 200)))
  (let ((nid (+ (var-get p-nonce) u1))
        (pool (unwrap! (contract-call? .insurance-pool get-pool u1) err-amt)))
    (map-set proposals {id: nid} {cr: tx-sender,t: t,d: d,st: PR-ACT,ca: block-height,vf: u0,va: u0})
    (var-set p-nonce nid)
    (print {e: "proposal-created",id: nid,cr: tx-sender})
    (ok nid)))
(define-public (cancel-proposal (id uint))
  (let ((prop (unwrap! (get-proposal id) err-nf)))
    (asserts! (is-eq tx-sender (get cr prop)) err-owner)
    (asserts! (is-eq (get st prop) PR-ACT) err-dup)
    (map-set proposals {id: id} (merge prop {st: PR-CAN}))
    (print {e: "proposal-cancelled",id: id})
    (ok true)))
(define-public (mark-executed (id uint))
  (let ((prop (unwrap! (get-proposal id) err-nf)))
    (asserts! (is-eq tx-sender (get cr prop)) err-owner)
    (asserts! (is-eq (get st prop) PR-ACT) err-dup)
    (map-set proposals {id: id} (merge prop {st: PR-EXE}))
    (print {e: "proposal-executed",id: id})
    (ok true)))

Functions (5)

FunctionAccessArgs
get-proposalread-onlyid: uint
get-proposal-countread-only
create-proposalpublict: (string-ascii 50
cancel-proposalpublicid: uint
mark-executedpublicid: uint