UserState

Struct UserState 

Source
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

Source

pub fn default() -> Self

Returns the default state.

Source

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.

Source

pub fn validate_caller_owner(&self) -> Result<(), UserStateError>

Validates if the caller is the owner.

Source

pub fn validate_caller_wallet_canister(&self) -> Result<(), UserStateError>

Validates if the caller is the wallet canister.

Source

pub fn validate_caller_wallet_canister_or_user( &self, user: &Principal, ) -> Result<(), UserStateError>

Validates if the caller is the wallet canister, or the user.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl CandidType for UserState

Source§

fn _ty() -> Type

Source§

fn id() -> TypeId

Source§

fn idl_serialize<__S>(&self, __serializer: __S) -> Result<(), __S::Error>
where __S: Serializer,

Source§

fn ty() -> Type

Source§

impl Debug for UserState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for UserState

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,