Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
radicleart committed Nov 15, 2021
1 parent ee158cb commit 506c24f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
30 changes: 11 additions & 19 deletions contracts/loopbomb.clar
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

(define-constant percentage-with-twodp u10000000000)

(define-constant err-permission-denied u1)
(define-constant not-allowed (err u10))
(define-constant not-found (err u11))
(define-constant amount-not-set (err u12))
Expand Down Expand Up @@ -104,7 +105,7 @@

;; see nft-tradable-trait
(define-public (set-approval-for (nftIndex uint) (approval principal))
(if (is-owner nftIndex tx-sender)
(if (is-owner nftIndex contract-caller)
(begin
(map-set nft-approvals {nft-index: nftIndex} {approval: approval})
(ok true)
Expand Down Expand Up @@ -175,30 +176,21 @@

;; Transfers tokens to a 'SPecified principal.
(define-public (transfer (nftIndex uint) (owner principal) (recipient principal))
(if (and (is-owner-or-approval nftIndex owner) (is-owner-or-approval nftIndex tx-sender))
(if (and (is-owner-or-approval nftIndex owner) (is-owner-or-approval nftIndex contract-caller))
(match (nft-transfer? loopbomb nftIndex owner recipient)
success (ok true)
error (nft-transfer-err error))
nft-not-owned-err)
success (ok success)
error (err {kind: "nft-transfer-failed", code: error}))
(err {kind: "permission-denied", code: err-permission-denied}))
)

;; Burns tokens
(define-public (burn (nftIndex uint) (owner principal))
(if (and (is-owner-or-approval nftIndex owner) (is-owner-or-approval nftIndex tx-sender))
(if (and (is-owner-or-approval nftIndex owner) (is-owner-or-approval nftIndex contract-caller))
(match (nft-burn? loopbomb nftIndex owner)
success (ok true)
error (nft-transfer-err error))
nft-not-owned-err)
)

(define-private (nft-transfer-err (code uint))
(if (is-eq u1 code)
nft-not-owned-err
(if (is-eq u2 code)
sender-equals-recipient-err
(if (is-eq u3 code)
nft-not-found-err
(err code)))))
success (ok success)
error (err {kind: "nft-transfer-failed", code: error}))
(err {kind: "permission-denied", code: err-permission-denied}))
)

(define-private (is-owner (nftIndex uint) (user principal))
(is-eq user (unwrap! (nft-get-owner? loopbomb nftIndex) false))
Expand Down
4 changes: 2 additions & 2 deletions contracts/nft-trait.clar
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
;; Last token ID, limited to uint range
(get-last-token-id () (response uint uint))

;; URI for metadata associated with the token
;; URI for metadata associated with the token
(get-token-uri (uint) (response (optional (string-ascii 256)) uint))

;; Owner of a given token identifier
(get-owner (uint) (response (optional principal) uint))

;; Transfer from the sender to a new principal
(transfer (uint principal principal) (response bool uint))
(transfer (uint principal principal) (response bool (tuple (kind (string-ascii 32)) (code uint))))
)
)

0 comments on commit 506c24f

Please sign in to comment.