forked from sui-foundation/sui-move-intro-course
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranscript_1.move_wip
52 lines (43 loc) · 1.6 KB
/
transcript_1.move_wip
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
// Copyright (c) 2022, Sui Foundation
// SPDX-License-Identifier: Apache-2.0
/// A basic object example for Sui Move, part of the Sui Move intro course:
/// https://github.com/sui-foundation/sui-move-intro-course
///
module sui_intro_unit_two::transcript {
use sui::object::{Self, UID};
use sui::tx_context::{Self, TxContext};
use sui::transfer;
struct Transcript {
history: u8,
math: u8,
literature: u8,
}
struct TranscriptObject has key {
id: UID,
history: u8,
math: u8,
literature: u8,
}
public entry fun create_transcript_object(history: u8, math: u8, literature: u8, ctx: &mut TxContext) {
let transcriptObject = TranscriptObject {
id: object::new(ctx),
history,
math,
literature,
};
transfer::transfer(transcriptObject, tx_context::sender(ctx))
}
// You are allowed to retrieve the score but cannot modify it
public fun view_score(transcriptObject: &TranscriptObject): u8{
transcriptObject.literature
}
// You are allowed to view and edit the score but not allowed to delete it
public entry fun update_score(transcriptObject: &mut TranscriptObject, score: u8){
transcriptObject.literature = score
}
// You are allowed to do anything with the score, including view, edit, delete the entire transcript itself.
public entry fun delete_transcript(transcriptObject: TranscriptObject){
let TranscriptObject {id, history: _, math: _, literature: _ } = transcriptObject;
object::delete(id);
}
}