For this section, you should be in:
pallets/connect/lib.rs to follow along.
This section will focus on adding a new FRAME storage item to
pallet_connect. With our events and
errors defined, we have two items left on our action list:
- Implement events and errors
- Implement storage items
- Implement dispatchable functions (extrinsics)
Defining a Storage Item
While we have errors to define user as out of bounds and events that emit when someone successfully registers, there is currently no place to store the data about the user in underlying storage.
There are several types of storage items in FRAME. We will use a
StorageMap, which works similarly
HashMap in principle. Navigate to the struct called
UserMetadata, and right under it, add
this type alias:
/// Registered users mapped by address
pub type RegisteredUsers<T: Config> =
StorageMap<_, Blake2_128Concat, T::AccountId, UserMetadata<T>, OptionQuery>;
This storage item maps the
AccountId from Config (hence
T::AccountId) to the struct
#[pallet::storage] defines and expands this type alias for us.
A few notes about this storage item:
Blake2_128Concatrefers to how the keys are hashed, referring to the
Blake2_128hashing algorithm. This is a secure hashing algorithm.
T::AccountIdis the key to access the value,
- The generic
Tmust implement the
Configtrait. This gives it access to overarching types, such as core primitives (i.e.,
OptionQueryrefers to how to handle when the value is retrieved.
OptionQueryworks by returning an
Option<T>, meaning a user can either be