ballot-will-a-major-gpo-CWIEj

SP1ADQ42BRGAEXHHHW77C53Q1KXFAYSNN8R87DQWK

Source Code


    ;; ballot
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;; Constants
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (define-constant CONTRACT-OWNER tx-sender)
    ;; Errors
    (define-constant ERR-NOT-STARTED (err u1001))
    (define-constant ERR-ENDED (err u1002))
    (define-constant ERR-ALREADY-VOTED (err u1003))
    (define-constant ERR-FAILED-STRATEGY (err u1004))
    (define-constant ERR-NOT-VOTED (err u1005))
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;; data maps and vars
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (define-data-var title (string-utf8 512) u"")
    (define-data-var description (string-utf8 512) u"")
    (define-data-var voting-system (string-ascii 512) "")
    (define-data-var start uint u0)
    (define-data-var end uint u0)
    (define-map token-ids-map {token-id: uint} {user: principal, vote-id: uint})
    (define-map btc-holder-map {domain: (buff 20), namespace: (buff 48)} {user: principal, vote-id: uint})
    (define-map results {id: (string-ascii 36)} {count: uint, name: (string-utf8 256), locked-stx: uint, unlocked-stx: uint} )
    (define-map users {id: principal} {id: uint, vote: (list 6 (string-ascii 36)), volume: (list 6 uint), voting-power: uint, locked-stx: uint, unlocked-stx: uint})
    (define-map register {id: uint} {user: principal, vote: (list 6 (string-ascii 36)), volume: (list 6 uint), voting-power: uint, locked-stx: uint, unlocked-stx: uint})
    (define-data-var total uint u0)
    (define-data-var total-votes uint u0)
    (define-data-var options (list 6 (string-ascii 36)) (list))
    (define-data-var temp-voting-power uint u0)
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;; private functions
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    (define-private (validate-nft-ownership (token-id uint))
        (let
            (
                (vote-id (+ u1 (var-get total)))
                (nft-owner-optional (unwrap-panic (contract-call? 'SP1ADQ42BRGAEXHHHW77C53Q1KXFAYSNN8R87DQWK.guessors get-owner token-id)))
            )

            (match nft-owner-optional
                nft-owner 
                    (if (is-eq tx-sender nft-owner)
                        (match (map-get? token-ids-map {token-id: token-id})
                            result
                                u0
                            (if (map-set token-ids-map {token-id: token-id} {user: tx-sender, vote-id: vote-id})                        
                                u1
                                u0
                            )
                        )
                        u0
                    )
                u0
            )
        )
    )

    (define-private (get-voting-power-by-nft-holdings (token-ids (list 60000 uint)))
        (fold + (map validate-nft-ownership token-ids) u0)
    )
    
    (define-private (have-i-voted)
        (match (map-get? users {id: tx-sender})
            success true
            false
        )
    )
    
    (define-private (fold-boolean (left bool) (right bool))
        (and (is-eq left true) (is-eq right true))
    )

    (define-private (check-volume (each-volume uint))
        (> each-volume u0)
    )

    (define-private (validate-vote-volume (volume (list 6 uint)))
        (begin
            (fold fold-boolean (map check-volume volume) true)
        )
    )

    (define-private (get-volume-by-voting-power (volume uint))
        (var-get temp-voting-power)
    )

    (define-private (get-pow-value (volume uint))
        (pow volume u2)
    )
    
    (define-private (process-my-vote (option-id (string-ascii 36)) (volume uint))
        (match (map-get? results {id: option-id})
            result (let
                    (
                        (new-count-tuple {count: (+ volume (get count result))})
                    )

                    ;; Capture the vote
                    (map-set results {id: option-id} (merge result new-count-tuple))

                    ;; Return
                    true
                )
            false
        )
    )
    
    (define-private (get-single-result (option-id (string-ascii 36)))
        (let 
            (
                (volume (default-to u0 (get count (map-get? results {id: option-id}))))
            )
    
            ;; Return volume
            volume
        )
    )

    (define-private (get-single-result-with-locked-and-unlocked-stx (option-id (string-ascii 36)))
        (let 
            (
                (locked-stx (default-to u0 (get locked-stx (map-get? results {id: option-id}))))
                (unlocked-stx (default-to u0 (get unlocked-stx (map-get? results {id: option-id}))))
            )

            ;; Return locked-stx and unlocked-stx
            {locked-stx: locked-stx, unlocked-stx: unlocked-stx}
        )
    )

    
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;; public functions for all
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (define-public (cast-my-vote (vote (list 6 (string-ascii 36))) (volume (list 6 uint))
        (bns (string-ascii 256)) (domain (buff 20)) (namespace (buff 48)) (token-ids (list 60000 uint))
        )
        (let
            (
                (vote-id (+ u1 (var-get total)))
                (voting-power (get-voting-power-by-nft-holdings token-ids))
                
                ;; FPTP and Block voting
                (temp (var-set temp-voting-power voting-power))
                (volume-by-voting-power (map get-volume-by-voting-power volume))
            
                
                ;; FPTP and Block voting - Number of votes
                (my-votes voting-power)

                ;; Get the stx balance with locked and unlocked
                
            )
            ;; Validation
            (asserts! (and (> (len vote) u0) (is-eq (len vote) (len volume-by-voting-power)) (validate-vote-volume volume-by-voting-power)) ERR-NOT-VOTED)
            (asserts! (>= burn-block-height (var-get start)) ERR-NOT-STARTED)
            (asserts! (<= burn-block-height (var-get end)) ERR-ENDED)        
            (asserts! (not (have-i-voted)) ERR-ALREADY-VOTED)
            
                ;; FPTP and Block voting
                (asserts! (> voting-power u0) ERR-FAILED-STRATEGY)
            
            ;; Business logic
            ;; Process my vote
            (map process-my-vote vote volume-by-voting-power)

            
            
            ;; Register for reference
            (map-set users {id: tx-sender} {id: vote-id, vote: vote, volume: volume-by-voting-power, voting-power: voting-power , locked-stx: u0, unlocked-stx: u0})
            (map-set register {id: vote-id} {user: tx-sender, vote: vote, volume: volume-by-voting-power, voting-power: voting-power , locked-stx: u0, unlocked-stx: u0})

            ;; Increase the total votes
            (var-set total-votes (+ my-votes (var-get total-votes)))

            ;; Increase the total
            (var-set total vote-id)
    
            ;; Return
            (ok true)
        )
    )
    
    (define-read-only (get-results)
        (begin
            (ok {
                    total: (var-get total), 
                    total-votes: (var-get total-votes),
                    options: (var-get options), 
                    results: (map get-single-result (var-get options)),
                    results-with-locked-and-unlocked-stx: (map get-single-result-with-locked-and-unlocked-stx (var-get options))
                })
        )
    )
    
    (define-read-only (get-result-at-position (position uint))
        (ok (map-get? register {id: position}))
    )
        
    (define-read-only (get-result-by-user (user principal))
        (ok (map-get? users {id: user}))
    )
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;; Default assignments
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (var-set title u"Will%20a%20major%20GPO%20add%20an%20AI%20documentation%20or%20AI%20clinical%20workflow%20vendor%20to%20its%20preferred%20vendor%20list%20this%20month%3F")
    (var-set description u"%3Cp%3EA%20strong%20signal%20of%20accelerated%20institutional%20purchasing%20of%20AI%20solutions%20is%20the%20addition%20of%20AI%20vendors%20to%20a%20major%20GPO%20preferred%20vendor%20list.%20This%20can%20also%20signal%20future%20provider%20cost%20containment%20and%20workforce%20needs.%3C%2Fp%3E%3Cp%3EResolution%3A%20Official%20announcement%20by%20GPO%20(e.g.%2C%20Vizient%2C%20Premier)%20in%20current%20month%20that%20details%20the%20addition%20of%20a%20new%20AI%20vendor%20to%20GPO%20preferred%20vendor%20li")
    (var-set voting-system "fptp")
    (var-set options (list "babd7183-37c3-454a-9a64-4812cd2c021a" "dfc1d70b-2d27-4b51-9c6f-cd444087949b" "5588c31f-b33c-45df-be3d-ff470cb3b7b9" "88ba7e5f-72c0-48d6-9e26-ed1707a6f663" "2ea909da-0c8e-4961-9ae0-c7e9a67fc6dc" "3d35d6b5-bc15-414b-b212-a00492784699"))
    (var-set start u938899)
    (var-set end u943280)
    (map-set results {id: "babd7183-37c3-454a-9a64-4812cd2c021a"} {count: u0, name: u"0%25%20(Definitely%20No)", locked-stx: u0, unlocked-stx: u0}) (map-set results {id: "dfc1d70b-2d27-4b51-9c6f-cd444087949b"} {count: u0, name: u"20%25", locked-stx: u0, unlocked-stx: u0}) (map-set results {id: "5588c31f-b33c-45df-be3d-ff470cb3b7b9"} {count: u0, name: u"40%25", locked-stx: u0, unlocked-stx: u0}) (map-set results {id: "88ba7e5f-72c0-48d6-9e26-ed1707a6f663"} {count: u0, name: u"60%25", locked-stx: u0, unlocked-stx: u0}) (map-set results {id: "2ea909da-0c8e-4961-9ae0-c7e9a67fc6dc"} {count: u0, name: u"80%25", locked-stx: u0, unlocked-stx: u0}) (map-set results {id: "3d35d6b5-bc15-414b-b212-a00492784699"} {count: u0, name: u"100%25%20(Certainly%20Yes)", locked-stx: u0, unlocked-stx: u0})

Functions (15)

FunctionAccessArgs
validate-nft-ownershipprivatetoken-id: uint
get-voting-power-by-nft-holdingsprivatetoken-ids: (list 60000 uint
have-i-votedprivate
fold-booleanprivateleft: bool, right: bool
check-volumeprivateeach-volume: uint
validate-vote-volumeprivatevolume: (list 6 uint
get-volume-by-voting-powerprivatevolume: uint
get-pow-valueprivatevolume: uint
process-my-voteprivateoption-id: (string-ascii 36
get-single-resultprivateoption-id: (string-ascii 36
get-single-result-with-locked-and-unlocked-stxprivateoption-id: (string-ascii 36
cast-my-votepublicvote: (list 6 (string-ascii 36
get-resultsread-only
get-result-at-positionread-onlyposition: uint
get-result-by-userread-onlyuser: principal