use std::string;
use sui::package;
use sui::table;
use sage_utils::string_helpers;
Explore this module further in the Mover Registry: @sage/user
Structs
UserRegistry
Registry that contains a map to all User
s.
public struct UserRegistry has key
id: sui::object::UID,
address_registry: Table<address, std::string::String>,
address_reverse_registry: Table<std::string::String, address>,
user_owned_registry: Table<std::string::String, address>,
user_owned_reverse_registry: Table<address, std::string::String>,
user_shared_registry: Table<std::string::String, address>,
user_shared_reverse_registry: Table<address, std::string::String>
Constants
Error code when a wallet address does not have an associated User
.
const EAddressRecordDoesNotExist: u64 = 370;
Error code when a User
name does not exist in the registry.
const EUsernameRecordDoesNotExist: u64 = 371;
Functions
assert_user_address_exists
Aborts with EAddressRecordDoesNotExist
when a wallet address is not associated with a User
.
public fun assert_user_address_exists(user_registry: &UserRegistry, wallet_address: address)
public fun assert_user_address_exists(
user_registry: &UserRegistry,
wallet_address: address
) {
let is_user = has_address_record(
user_registry,
wallet_address
);
assert!(is_user, EAddressRecordDoesNotExist);
}
assert_user_name_exists
Aborts with EUsernameRecordDoesNotExist
when the User
name does not exist in the registry.
public fun assert_user_name_exists(user_registry: &UserRegistry, username: String)
public fun assert_user_name_exists(
user_registry: &UserRegistry,
username: String
) {
let is_user = has_username_record(
user_registry,
username
);
assert!(is_user, EUsernameRecordDoesNotExist);
}
get_owner_address_from_key
Returns the wallet address for the User
with the specified lowercase name.
public fun get_owner_address_from_key(user_registry: &UserRegistry, user_key: String): address
public fun get_owner_address_from_key (
user_registry: &UserRegistry,
user_key: String
): address {
*user_registry.address_reverse_registry.borrow(user_key)
}
get_owned_user_address_from_key
Returns the address for the OwnedUser
with the specified lowercase name.
public fun get_owned_user_address_from_key(user_registry: &UserRegistry, user_key: String): address
public fun get_owned_user_address_from_key (
user_registry: &UserRegistry,
user_key: String
): address {
*user_registry.user_owned_registry.borrow(user_key)
}
get_shared_user_address_from_key
Returns the address for the SharedUser
with the specified lowercase name.
public fun get_shared_user_address_from_key (user_registry: &UserRegistry, user_key: String): address
public fun get_shared_user_address_from_key (
user_registry: &UserRegistry,
user_key: String
): address {
*user_registry.user_shared_registry.borrow(user_key)
}
get_key_from_owner_address
Returns the User
lowercase name associated with the wallet address.
public fun get_key_from_owner_address(user_registry: &UserRegistry, user_address: address): String
public fun get_key_from_owner_address (
user_registry: &UserRegistry,
user_address: address
): String {
*user_registry.address_registry.borrow(user_address)
}
get_key_from_owned_user_address
Returns the User
lowercase name associated with the OwnedUser
address.
public fun get_key_from_owned_user_address(user_registry: &UserRegistry, user_address: address): String
public fun get_key_from_owned_user_address (
user_registry: &UserRegistry,
user_address: address
): String {
*user_registry.user_owned_reverse_registry.borrow(user_address)
}
get_key_from_shared_user_address
Returns the User
lowercase name associated with the SharedUser
address.
public fun get_key_from_shared_user_address(user_registry: &UserRegistry, user_address: address): String
public fun get_key_from_shared_user_address (
user_registry: &UserRegistry,
user_address: address
): String {
*user_registry.user_shared_reverse_registry.borrow(user_address)
}
has_address_record
Returns true or false based on whether the wallet address has an associated User
.
public fun has_address_record(user_registry: &UserRegistry, wallet_address: address): bool
public fun has_address_record (
user_registry: &UserRegistry,
wallet_address: address
): bool {
user_registry.address_registry.contains(wallet_address)
}
has_username_record
Returns true or false based on whether the specified lowercase User
name is in use.
public fun has_username_record(user_registry: &UserRegistry, username: String): bool
public fun has_username_record (
user_registry: &UserRegistry,
username: String
): bool {
let user_key = string_helpers::to_lowercase(
&username
);
user_registry.user_owned_registry.contains(user_key) &&
user_registry.user_shared_registry.contains(user_key)
}