diff --git a/pallets/template/src/lib.rs b/pallets/template/src/lib.rs index 58a5a5b8..3d11317b 100644 --- a/pallets/template/src/lib.rs +++ b/pallets/template/src/lib.rs @@ -16,7 +16,8 @@ mod benchmarking; #[frame_support::pallet] pub mod pallet { - use frame_support::pallet_prelude::*; + +use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; /// Configure the pallet by specifying the parameters and types on which it depends. @@ -38,6 +39,11 @@ pub mod pallet { // https://docs.substrate.io/v3/runtime/storage#declaring-storage-items pub type Something = StorageValue<_, u32>; + + #[pallet::storage] + #[pallet::getter(fn my_bytes_val)] + pub type MyBytesVal = StorageValue<_, MyBytes, ValueQuery>; + // Pallets use events to inform users when important changes are made. // https://docs.substrate.io/v3/runtime/events-and-errors #[pallet::event] @@ -48,6 +54,8 @@ pub mod pallet { SomethingStored(u32, T::AccountId), } + pub type MyBytes = BoundedVec>; + // Errors inform users that something went wrong. #[pallet::error] pub enum Error { @@ -98,5 +106,19 @@ pub mod pallet { }, } } + + #[pallet::weight(10_000 + T::DbWeight::get().writes(1))] + pub fn insert_my_bytes(origin: OriginFor, optional_bytes: Option) -> DispatchResult { + // Check that the extrinsic was signed and get the signer. + // This function will return an error if the extrinsic is not signed. + // https://docs.substrate.io/v3/runtime/origins + let who = ensure_signed(origin)?; + + // Update storage. + let s = optional_bytes.unwrap_or_default(); + >::put(s); + // Return a successful DispatchResultWithPostInfo + Ok(()) + } } -} \ No newline at end of file +}