-
Notifications
You must be signed in to change notification settings - Fork 13
/
wgmiami.clar
55 lines (44 loc) · 1.64 KB
/
wgmiami.clar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
;; wgmiami
(impl-trait 'SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.nft-trait.nft-trait)
;; Non Fungible Token, using sip-009
(define-non-fungible-token wgmiami uint)
;; Constants
(define-constant err-no-more-nfts u300)
(define-constant err-invalid-user u500)
(define-constant mint-limit u200)
(define-constant commission-address tx-sender)
(define-data-var last-id uint u0)
(define-data-var ipfs-root (string-ascii 80) "ipfs://ipfs/QmcZPP4DnecZUALwS8edvY62duezds55UsojzBXHzquhp4/")
(define-private (mint (new-owner principal) (next-id uint))
(match (nft-mint? wgmiami next-id new-owner)
success
(begin
(var-set last-id next-id)
(ok true))
error (err error)))
(define-public (claim-for (user principal) (id uint))
(if (is-eq tx-sender commission-address)
(mint user id)
(err err-invalid-user))
)
(define-public (set-ipfs-root (new-ipfs-root (string-ascii 80)))
(if (is-eq tx-sender commission-address)
(begin
(var-set ipfs-root new-ipfs-root)
(ok true)
)
(err err-invalid-user)))
(define-public (transfer (token-id uint) (sender principal) (recipient principal))
(if (and
(is-eq tx-sender sender))
(match (nft-transfer? wgmiami token-id sender recipient)
success (ok success)
error (err error))
(err err-invalid-user)))
;; read-only functions
(define-read-only (get-owner (token-id uint))
(ok (nft-get-owner? wgmiami token-id)))
(define-read-only (get-last-token-id)
(ok (var-get last-id)))
(define-read-only (get-token-uri (token-id uint))
(ok (some (concat (concat (var-get ipfs-root) "$TOKEN_ID") ".json"))))