pub struct UserState {
pub owner: Principal,
pub wallet_canister: Principal,
pub config: UserStateConfig,
pub users: BTreeMap<Principal, UserData>,
}Expand description
Represents the state of the canister, including users, and wallet canister.
Fields§
§owner: Principal§wallet_canister: Principal§config: UserStateConfig§users: BTreeMap<Principal, UserData>Implementations§
Source§impl UserState
impl UserState
Sourcepub fn init(&mut self, wallet_canister: Principal)
pub fn init(&mut self, wallet_canister: Principal)
Initializes the state with the wallet canister. This function should only be called once, when the canister is first installed.
Sourcepub fn validate_caller_owner(&self) -> Result<(), UserStateError>
pub fn validate_caller_owner(&self) -> Result<(), UserStateError>
Validates if the caller is the owner.
Sourcepub fn validate_caller_wallet_canister(&self) -> Result<(), UserStateError>
pub fn validate_caller_wallet_canister(&self) -> Result<(), UserStateError>
Validates if the caller is the wallet canister.
Sourcepub fn validate_caller_wallet_canister_or_user(
&self,
user: &Principal,
) -> Result<(), UserStateError>
pub fn validate_caller_wallet_canister_or_user( &self, user: &Principal, ) -> Result<(), UserStateError>
Validates if the caller is the wallet canister, or the user.
Sourcepub fn change_owner(
&mut self,
new_owner: Principal,
) -> Result<Principal, UserStateError>
pub fn change_owner( &mut self, new_owner: Principal, ) -> Result<Principal, UserStateError>
Changes the owner of the canister.
This function should only be called by the owner.
Sourcepub fn change_wallet_canister(
&mut self,
new_wallet_canister: Principal,
) -> Result<Principal, UserStateError>
pub fn change_wallet_canister( &mut self, new_wallet_canister: Principal, ) -> Result<Principal, UserStateError>
Changes the wallet canister. This function should only be called by the owner.
Sourcepub fn create_user(
&mut self,
user: Principal,
user_args: UserDataArgs,
account_args: UserAccountArgs,
) -> Result<UserData, UserStateError>
pub fn create_user( &mut self, user: Principal, user_args: UserDataArgs, account_args: UserAccountArgs, ) -> Result<UserData, UserStateError>
This function returns a reference to the user data. Adds new user data for a given user Principal.
Sourcepub fn get_user_mut(
&mut self,
user: &Principal,
) -> Result<&mut UserData, UserStateError>
pub fn get_user_mut( &mut self, user: &Principal, ) -> Result<&mut UserData, UserStateError>
This function returns a mutable reference to the user data. Retrieves user data for a given user Principal.
Sourcepub fn get_user(&self, user: &Principal) -> Result<&UserData, UserStateError>
pub fn get_user(&self, user: &Principal) -> Result<&UserData, UserStateError>
This function returns a reference to the user data. Retrieves user data for a given user Principal.
Sourcepub fn get_user_derivation_path(
&self,
user: &Principal,
key: u8,
) -> Result<Vec<u8>, UserStateError>
pub fn get_user_derivation_path( &self, user: &Principal, key: u8, ) -> Result<Vec<u8>, UserStateError>
This function returns a Derivation Path for a given user Principal.