I was following this guide Configuring Genesis for Balances.
In my parachain
, I replaced T::Balance
with BalanceOf<T>
type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
#[pallet::config]
pub trait Config: frame_system::Config {
type Currency: ReservableCurrency<Self::AccountId>
+ LockableCurrency<Self::AccountId, Moment = Self::BlockNumber>;
...
}
#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
pub struct Pallet<T>(PhantomData<T>);
#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
fn build(&self) {
<SingleValue<T>>::put(&self.single_balance);
for (a, b) in &self.account_map {
<AccountMap<T>>::insert(a, b);
}
}
}
#[pallet::genesis_config]
pub struct GenesisConfig<T: Config> {
pub single_balance: BalanceOf<T>,
pub account_map: Vec<(T::AccountId, BalanceOf<T>)>,
}
#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
Self { single_balance: Default::default(), account_map: Default::default() }
}
}
// https://docs.substrate.io/v3/runtime/storage#declaring-storage-items
#[pallet::storage]
#[pallet::getter(fn single_value)]
pub type SingleValue<T: Config> = StorageValue<_, u32, ValueQuery>; //
#[pallet::storage]
#[pallet::getter(fn single_balance)]
pub type SingleBalance<T: Config> = StorageValue<_, BalanceOf<T>>;
// A map that has enumerable entries.
#[pallet::storage]
#[pallet::getter(fn accounts)]
pub type AccountMap<T: Config> = StorageMap<_, Blake2_128Concat, T::AccountId, BalanceOf<T>>;
error[E0277]: the trait bound &<<T as pallet::Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance: EncodeLike<u32>
is not satisfied.
Here's the genesis
configuration:
#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
fn build(&self) {
<SingleValue<T>>::put(&self.single_balance);
for (a, b) in &self.account_map {
<AccountMap<T>>::insert(a, b);
}
}
}
And the error I'm getting:
EncodeLike<u32>
is not implemented for &<<T as pallet::Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance
122 | pub fn put<Arg: EncodeLike<Value>>(val: Arg) { | ^^^^^^^^^^^^^^^^ required by this bound in frame_support::pallet_prelude::StorageValue::<Prefix, Value, QueryKind, OnEmpty>::put help: consider introducing a
where bound, but there might be an alternative better way to express this requirement
impl<T: Config> GenesisBuild<T> for GenesisConfig<T>
where &<<T as pallet::Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance: EncodeLike<u32> {
What am I missing?