Create a Storage Structure
Before you begin
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default)] pub struct MetaData<AccountId, Balance> { issuance: Balance, minter: AccountId, burner: AccountId, }#[pallet::storage] #[pallet::getter(fn meta_data)] pub(super) type MetaDataStore<T: Config> = StorageValue<_, MetaData<T::AccountId, T::Balance>, ValueQuery>;// Declare `admin` as type `T::AccountId`. #[pallet::genesis_config] pub struct GenesisConfig<T: Config> { pub admin: T::AccountId, } // Give it a default value. #[cfg(feature = "std")] impl<T: Config> Default for GenesisConfig<T> { fn default() -> Self { Self { admin: Default::default(), } } }#[pallet::genesis_build] impl<T: Config> GenesisBuild<T> for GenesisConfig<T> { fn build(&self) { MetaDataStore::<T>::put(MetaData { issuance: Zero::zero(), minter: self.admin.clone(), burner: self.admin.clone(), }); } }fn on_initialize(_n: T::BlockNumber) -> Weight { // Create an alias for the StorageValue struct. let mut meta = MetaDataStore::<T>::get(); // Add a value to the `issuance` field. let value: T::Balance = 50u8.into(); meta.issuance = meta.issuance.saturating_add(value); // Add the amount to the `minter` account in storage. Accounts::<T>::mutate(&meta.minter, |bal| { *bal = bal.saturating_add(value); }); }
Examples
Resources
Last updated