Struct b3_users::state::UserState

source ·
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: Principal

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, address_args: UserAddressArgs ) -> 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.

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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<T> for T

§

type Output = T

Should always be Self
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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