-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdigital-time-capsule.clar
More file actions
59 lines (56 loc) · 1.49 KB
/
Copy pathdigital-time-capsule.clar
File metadata and controls
59 lines (56 loc) · 1.49 KB
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
56
57
58
59
;; Digital-Time-Capsule
(define-data-var next-id uint u1)
(define-map time-capsules
{
id: uint
}
{
owner: principal,
message: (optional (string-ascii 256)),
file-hash: (optional (string-ascii 64)), ;; Assuming file is stored as a hash
nft: (optional (tuple (contract principal) (token-id uint))),
release-date: uint
}
)
;; Function to lock a time capsule
(define-public (lock-capsule
(message (optional (string-ascii 256)))
(file-hash (optional (string-ascii 64)))
(nft (optional (tuple (contract principal) (token-id uint))))
(release-date uint))
(begin
;; Ensure the release date is in the future
(asserts! (> release-date block-height) (err u102))
;; Get the next capsule ID
(let ((capsule-id (var-get next-id)))
;; Save the capsule
(map-set time-capsules
{ id: capsule-id }
{
owner: tx-sender,
message: message,
file-hash: file-hash,
nft: nft,
release-date: release-date
})
;; Increment the next capsule ID
(var-set next-id (+ capsule-id u1))
;; Return the new capsule ID
(ok capsule-id)
)
)
)
;; Function to retrieve a time capsule
(define-public (retrieve-capsule (capsule-id uint))
(begin
(let ((capsule (map-get? time-capsules { id: capsule-id })))
(match capsule
capsule-data
(begin
;; Ensure the release date has passed
(asserts! (<= (get release-date capsule-data) block-height) (err u102))
;; Ensure the caller is the owner
(asserts! (is-eq (get owner capsule-data) tx-sender) (err u103))
;; Return the capsule data
(ok capsule-data))
(err u101)))))