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§
Sourcefn get_user_id(&self, address: &ManagedAddress<Self::Api>) -> usize
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.
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>)
Sourcefn get_num_users(&self) -> usize
fn get_num_users(&self) -> usize
Retrieves the number of delegtors, including the owner, even if they no longer have anything in the contract.
Sourcefn set_num_users(&self, num_users: usize)
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§
fn get_or_create_user(&self, address: &ManagedAddress<Self::Api>) -> usize
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.