multiversx_sc_modules::users

Trait UsersModule

Source
pub trait UsersModule: ContractBase + Sized {
    // Required methods
    fn get_user_id(&self, address: &ManagedAddress<Self::Api>) -> usize;
    fn set_user_id(&self, address: &ManagedAddress<Self::Api>, user_id: usize);
    fn get_user_address(&self, user_id: usize) -> ManagedAddress<Self::Api>;
    fn set_user_address(
        &self,
        user_id: usize,
        address: &ManagedAddress<Self::Api>,
    );
    fn get_num_users(&self) -> usize;
    fn set_num_users(&self, num_users: usize);

    // Provided methods
    fn get_or_create_user(&self, address: &ManagedAddress<Self::Api>) -> usize { ... }
    fn update_user_address(
        &self,
        addresses: MultiValueEncoded<Self::Api, ManagedAddress<Self::Api>>,
    ) { ... }
}
Expand description

Standard smart contract module that when added to a smart contract manages a list of users.

It was created before there was such a thing as storage mappers. The UserMapper is a more elegant solution nowadays that solves the same problem.

It provides a bi-directional map:

  • from user address to a unique user id
  • from user id to address

Required Methods§

Source

fn get_user_id(&self, address: &ManagedAddress<Self::Api>) -> usize

Each user gets a user id. This is in order to be able to iterate over their data. This is a mapping from user address to user id. The key is the bytes “user_id” concatenated with their public key. The value is the user id.

Source

fn set_user_id(&self, address: &ManagedAddress<Self::Api>, user_id: usize)

Source

fn get_user_address(&self, user_id: usize) -> ManagedAddress<Self::Api>

Source

fn set_user_address(&self, user_id: usize, address: &ManagedAddress<Self::Api>)

Source

fn get_num_users(&self) -> usize

Retrieves the number of delegtors, including the owner, even if they no longer have anything in the contract.

Source

fn set_num_users(&self, num_users: usize)

Yields how accounts are registered in the contract. Note that not all of them must have stakes greater than zero.

Provided Methods§

Source

fn get_or_create_user(&self, address: &ManagedAddress<Self::Api>) -> usize

Source

fn update_user_address( &self, addresses: MultiValueEncoded<Self::Api, ManagedAddress<Self::Api>>, )

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<C> UsersModule for C
where C: AutoImpl,