pub struct UserState {
pub users: BTreeMap<Principal, UserData>,
pub owner: Principal,
pub wallet_canister: Principal,
}Expand description
Represents the state of the canister, including users, and wallet canister.
Fields§
§users: BTreeMap<Principal, UserData>§owner: Principal§wallet_canister: PrincipalImplementations§
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,
address_args: UserAddressArgs
) -> Result<UserData, UserStateError>
pub fn create_user( &mut self, user: Principal, user_args: UserDataArgs, address_args: UserAddressArgs ) -> 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.
Trait Implementations§
source§impl CandidType for UserState
impl CandidType for UserState
source§impl<'de> Deserialize<'de> for UserState
impl<'de> Deserialize<'de> for UserState
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more