Here is a simple edit of the pallet/template/lib.rs
that uses Vec<u8>
in storage:
#![cfg_attr(not(feature = "std"), no_std)]
pub use pallet::*;
#[frame_support::pallet]
pub mod pallet {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
#[pallet::config]
pub trait Config: frame_system::Config {
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
}
#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
pub struct Pallet<T>(_);
#[pallet::storage]
#[pallet::getter(fn something)]
pub(super) type Something<T: Config> = StorageMap<
_,
Twox64Concat,
T::AccountId,
Vec<u8>,
ValueQuery,
>;
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
SomethingStored(Vec<u8>, T::AccountId),
}
#[pallet::error]
pub enum Error<T> {
NoneValue,
StorageOverflow,
}
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::weight(10_000 + T::DbWeight::get().writes(1))]
pub fn do_something(origin: OriginFor<T>, something: Vec<u8>) -> DispatchResult {
let who = ensure_signed(origin)?;
<Something<T>>::insert(&who, &something);
Self::deposit_event(Event::SomethingStored(something, who));
Ok(())
}
}
}
Using it with the current substrate-node-template is not compiling due to the following error:
error[E0277]: the trait bound `Vec<u8>: MaxEncodedLen` is not satisfied
--> pallets/template/src/lib.rs:15:12
|
15 | #[pallet::pallet]
| ^^^^^^ the trait `MaxEncodedLen` is not implemented for `Vec<u8>`
|
= note: required because of the requirements on the impl of `StorageInfoTrait` for `frame_support::pallet_prelude::StorageMap<_GeneratedPrefixForStorageSomething<T>, frame_support::Twox64Concat, <T as frame_system::Config>::AccountId, Vec<u8>, frame_support::pallet_prelude::ValueQuery>`
I can compile it using a previous version of the substrate-node-template
or using the BoundedVec<u8, T::MaxLength>
, but is there a way to keep using the Vec<u8>
?