-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #234 from jbencin/fix/handle-failed-nft-deposits
fix: Send failed NFT deposits back to user
- Loading branch information
Showing
4 changed files
with
647 additions
and
19 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
core-contracts/contracts/helper/simple-nft-l2-no-deposit.clar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
;; Version of `simple-nft-l2.clar` in which deposit always fails | ||
|
||
(define-constant CONTRACT_OWNER tx-sender) | ||
(define-constant CONTRACT_ADDRESS (as-contract tx-sender)) | ||
|
||
(define-constant ERR_NOT_AUTHORIZED (err u1001)) | ||
|
||
(impl-trait 'ST000000000000000000002AMW42H.subnet.nft-trait) | ||
|
||
(define-data-var lastId uint u0) | ||
|
||
(define-non-fungible-token nft-token uint) | ||
|
||
|
||
;; NFT trait functions | ||
(define-read-only (get-last-token-id) | ||
(ok (var-get lastId)) | ||
) | ||
|
||
(define-read-only (get-owner (id uint)) | ||
(ok (nft-get-owner? nft-token id)) | ||
) | ||
|
||
(define-read-only (get-token-uri (id uint)) | ||
(ok (some "unimplemented")) | ||
) | ||
|
||
(define-public (transfer (id uint) (sender principal) (recipient principal)) | ||
(begin | ||
(asserts! (is-eq tx-sender sender) ERR_NOT_AUTHORIZED) | ||
(nft-transfer? nft-token id sender recipient) | ||
) | ||
) | ||
|
||
;; mint functions | ||
(define-public (mint-next (recipient principal)) | ||
(let | ||
((newId (+ (var-get lastId) u1))) | ||
(var-set lastId newId) | ||
(nft-mint? nft-token newId recipient) | ||
) | ||
) | ||
|
||
(define-public (gift-nft (recipient principal) (id uint)) | ||
(begin | ||
(nft-mint? nft-token id recipient) | ||
) | ||
) | ||
|
||
(define-read-only (get-token-owner (id uint)) | ||
(nft-get-owner? nft-token id) | ||
) | ||
|
||
(impl-trait 'ST000000000000000000002AMW42H.subnet.subnet-asset) | ||
|
||
;; Called for deposit from the burnchain to the subnet | ||
(define-public (deposit-from-burnchain (id uint) (recipient principal)) | ||
ERR_NOT_AUTHORIZED | ||
) | ||
|
||
;; Called for withdrawal from the subnet to the burnchain | ||
(define-public (burn-for-withdrawal (id uint) (owner principal)) | ||
(begin | ||
(asserts! (is-eq tx-sender owner) ERR_NOT_AUTHORIZED) | ||
(nft-burn? nft-token id owner) | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.