스토리지 구조체 (struct) 생성하기
#[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>;// `admin`를 `T::AccountId` 타입으로 선언합니다. #[pallet::genesis_config] pub struct GenesisConfig<T: Config> { pub admin: T::AccountId, } // 기본값을 지정합니다. #[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 { // StorageValue 구조체에 대한 별칭 생성하기 let mut meta = MetaDataStore::<T>::get(); // `issuance` 필드에 값을 추가합니다. let value: T::Balance = 50u8.into(); meta.issuance = meta.issuance.saturating_add(value); // 스토리지의 `minter` 계정에 금액 추가하기 Accounts::<T>::mutate(&meta.minter, |bal| { *bal = bal.saturating_add(value); }); }
Last updated