removed pallet::getter from example pallets (#3371)

part of #3326 

@ggwpez @kianenigma @shawntabrizi

---------

Signed-off-by: Matteo Muraca <mmuraca247@gmail.com>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
Matteo Muraca
2024-02-22 00:02:31 +01:00
committed by GitHub
parent 318fed32f8
commit cd91c6b782
12 changed files with 41 additions and 36 deletions
+3 -11
View File
@@ -286,9 +286,7 @@ pub mod pallet {
let _sender = ensure_signed(origin)?;
// Read the value of dummy from storage.
// let dummy = Self::dummy();
// Will also work using the `::get` on the storage item type itself:
// let dummy = <Dummy<T>>::get();
// let dummy = Dummy::<T>::get();
// Calculate the new value.
// let new_dummy = dummy.map_or(increase_by, |dummy| dummy + increase_by);
@@ -381,20 +379,14 @@ pub mod pallet {
// - `Foo::put(1); Foo::get()` returns `1`;
// - `Foo::kill(); Foo::get()` returns `0` (u32::default()).
#[pallet::storage]
// The getter attribute generate a function on `Pallet` placeholder:
// `fn getter_name() -> Type` for basic value items or
// `fn getter_name(key: KeyType) -> ValueType` for map items.
#[pallet::getter(fn dummy)]
pub(super) type Dummy<T: Config> = StorageValue<_, T::Balance>;
// A map that has enumerable entries.
#[pallet::storage]
#[pallet::getter(fn bar)]
pub(super) type Bar<T: Config> = StorageMap<_, Blake2_128Concat, T::AccountId, T::Balance>;
// this one uses the query kind: `ValueQuery`, we'll demonstrate the usage of 'mutate' API.
#[pallet::storage]
#[pallet::getter(fn foo)]
pub(super) type Foo<T: Config> = StorageValue<_, T::Balance, ValueQuery>;
#[pallet::storage]
@@ -433,10 +425,10 @@ impl<T: Config> Pallet<T> {
fn accumulate_foo(origin: T::RuntimeOrigin, increase_by: T::Balance) -> DispatchResult {
let _sender = ensure_signed(origin)?;
let prev = <Foo<T>>::get();
let prev = Foo::<T>::get();
// Because Foo has 'default', the type of 'foo' in closure is the raw type instead of an
// Option<> type.
let result = <Foo<T>>::mutate(|foo| {
let result = Foo::<T>::mutate(|foo| {
*foo = foo.saturating_add(increase_by);
*foo
});