pub struct UserData {
pub name: String,
pub email: String,
pub balance: u128,
pub accounts: Vec<UserAccountData>,
pub settings: HashMap<String, UserDataSettingValue>,
/* private fields */
}Fields§
§name: String§email: String§balance: u128§accounts: Vec<UserAccountData>§settings: HashMap<String, UserDataSettingValue>Implementations§
Source§impl UserData
impl UserData
pub fn new(user_args: UserDataArgs, account_args: UserAccountArgs) -> Self
Sourcepub fn update(&mut self, args: UserDataArgs) -> UserDataArgs
pub fn update(&mut self, args: UserDataArgs) -> UserDataArgs
Updates the user’s data based on the provided UserDataArgs struct. Only updates fields that are set to Some(value) in the options.
Sourcepub fn update_profile(&mut self, args: UserProfileArgs) -> UserProfileArgs
pub fn update_profile(&mut self, args: UserProfileArgs) -> UserProfileArgs
Update the user’s profile. Only updates fields that are set to Some(value) in the options. Returns the updated profile.
Sourcepub fn create_account(
&mut self,
args: UserAccountArgs,
) -> Result<UserAccountData, UserStateError>
pub fn create_account( &mut self, args: UserAccountArgs, ) -> Result<UserAccountData, UserStateError>
Adds a new account for the user with the given key and account data. Returns an error if the key already exists.
Sourcepub fn get_new_key(&self) -> Result<usize, UserStateError>
pub fn get_new_key(&self) -> Result<usize, UserStateError>
New Key to add to derivation path based on the number of accounts created. Returns the new key.
Sourcepub fn get_derivation_path(
&self,
principal: Principal,
key: u8,
) -> Result<Vec<u8>, UserStateError>
pub fn get_derivation_path( &self, principal: Principal, key: u8, ) -> Result<Vec<u8>, UserStateError>
Get Derivation Path for the given key. Returns the derivation path.
Sourcepub fn get_key_is_valid(&self, key: usize) -> Result<(), UserStateError>
pub fn get_key_is_valid(&self, key: usize) -> Result<(), UserStateError>
Checks if the key is valid for the user. Returns an error if the key is invalid.
Sourcepub fn get_account(&self, key: usize) -> Result<UserAccountData, UserStateError>
pub fn get_account(&self, key: usize) -> Result<UserAccountData, UserStateError>
Retrieves an account by key for the user. Returns the account data if the key is found, or error if the key was not found.
Sourcepub fn get_account_mut(
&mut self,
key: usize,
) -> Result<&mut UserAccountData, UserStateError>
pub fn get_account_mut( &mut self, key: usize, ) -> Result<&mut UserAccountData, UserStateError>
Retrieves a mutable reference to the account by key for the user. Returns the account data if the key is found, or error if the key was not found.
Sourcepub fn get_accounts(&self) -> &Vec<UserAccountData>
pub fn get_accounts(&self) -> &Vec<UserAccountData>
Retrieves all the accounts created by the user. Returns a Vec of UserAccountData objects.
Sourcepub fn set_password(&mut self, password: &str) -> Result<(), UserStateError>
pub fn set_password(&mut self, password: &str) -> Result<(), UserStateError>
Sets the password for the user.
Sourcepub fn check_password(&self, password: &str) -> Result<bool, UserStateError>
pub fn check_password(&self, password: &str) -> Result<bool, UserStateError>
Checks if the provided password matches the user’s password.
Sourcepub fn get_setting(
&self,
key: &str,
) -> Result<UserDataSettingValue, UserStateError>
pub fn get_setting( &self, key: &str, ) -> Result<UserDataSettingValue, UserStateError>
Retrieves the user’s setting. Returns the value if the key is found, or None if the key was not found.
Sourcepub fn get_setting_mut(
&mut self,
key: &str,
) -> Result<&mut UserDataSettingValue, UserStateError>
pub fn get_setting_mut( &mut self, key: &str, ) -> Result<&mut UserDataSettingValue, UserStateError>
Retrieves a mutable reference to the user’s setting. Returns the value if the key is found, or None if the key was not found.
Sourcepub fn get_settings(&self) -> &HashMap<String, UserDataSettingValue>
pub fn get_settings(&self) -> &HashMap<String, UserDataSettingValue>
Retrieves a setting value by key for the user. Returns the value if the key is found, or None if the key was not found.
Sourcepub fn set_setting(&mut self, key: String, value: UserDataSettingValue)
pub fn set_setting(&mut self, key: String, value: UserDataSettingValue)
Sets a setting key-value pair for the user.
Sourcepub fn remove_setting(&mut self, key: &str) -> Result<bool, UserStateError>
pub fn remove_setting(&mut self, key: &str) -> Result<bool, UserStateError>
Removes a setting key for the user. Returns the removed value if it existed, or None if the key was not found.
Sourcepub fn update_settings(
&mut self,
new_settings: HashMap<String, UserDataSettingValue>,
)
pub fn update_settings( &mut self, new_settings: HashMap<String, UserDataSettingValue>, )
Updates all the settings for the user with the new settings.