Last active
June 13, 2024 14:27
-
-
Save wolivera/2cf6ecd181a1eba13402e9173b1dc4b1 to your computer and use it in GitHub Desktop.
A SUI Blockchain demo implementation for a profile in Move
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
module zircon::profile { | |
// === Imports === | |
use std::string::String; | |
use zircon::profile_cap::{Self, ProfileCap}; | |
// === Structs === | |
/// The user's Profile. | |
public struct Profile has key { | |
id: UID, | |
/// For tracing ownership from Profile | |
cap_id: ID, | |
/// Global points in platform | |
points: u64, | |
username: String, | |
user_address: address | |
} | |
// === Public-Mutative Functions === | |
public(package) fun new(points: u64, username: String, user_address: address, ctx: &mut TxContext): (Profile, ProfileCap) { | |
let mut profile = Profile { | |
id: object::new(ctx), | |
cap_id: object::id_from_address(@0x0), | |
points, | |
username, | |
user_address | |
}; | |
let profile_cap = profile_cap::new(object::id(&profile), ctx); | |
profile.cap_id = object::id(&profile_cap); | |
(profile, profile_cap) | |
} | |
#[allow(lint(share_owned))] | |
public(package) fun share(profile: Profile) { | |
transfer::share_object(profile); | |
} | |
public(package) fun drop(profile: Profile) { | |
let Profile { | |
id, | |
cap_id: _, | |
points: _, | |
username: _, | |
user_address: _ | |
} = profile; | |
id.delete(); | |
} | |
public(package) fun points_mut(profile: &mut Profile): &mut u64 { | |
&mut profile.points | |
} | |
public(package) fun username_mut(profile: &mut Profile): &mut String { | |
&mut profile.username | |
} | |
// === Public-View Functions === | |
public(package) fun cap_id(profile: &Profile): &ID { | |
&profile.cap_id | |
} | |
public(package) fun points(profile: &Profile): &u64 { | |
&profile.points | |
} | |
public(package) fun username(profile: &Profile): &String { | |
&profile.username | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment