-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprofile_clock.move
53 lines (43 loc) · 1.19 KB
/
profile_clock.move
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
module profile_clock::profile_clock {
use std::string::String;
use sui::clock::Clock;
const ONE_HOUR_IN_MS: u64 = 60 * 60 * 1000;
public struct Profile has key {
id: UID,
handle: String,
points: u64,
last_time: u64,
}
public fun mint(handle: String, ctx: &mut TxContext) {
let sender = ctx.sender();
let profile = new(handle, ctx);
transfer::transfer(profile, sender);
}
public fun click(profile: &mut Profile, clock: &Clock) {
let now = clock.timestamp_ms();
assert!(now > profile.last_time + ONE_HOUR_IN_MS);
profile.last_time = now;
profile.points = profile.points + 1;
}
public fun burn(profile: Profile) {
let Profile {
id,
..
} = profile;
object::delete(id);
}
public fun new(handle: String, ctx: &mut TxContext): Profile {
Profile {
id: object::new(ctx),
handle,
points: 0,
last_time: 0,
}
}
public fun points(profile: &Profile): u64 {
profile.points
}
public fun last_time(profile: &Profile): u64 {
profile.last_time
}
}