#![cfg_attr(not(feature = "std"), no_std)]
extern crate alloc;
use alloc::{vec, vec::Vec};
use frame_support::dispatch::DispatchResult;
use frame_system::ensure_signed;
pub use pallet::*;
#[cfg(test)]
mod tests;
type BalanceOf<T> = <T as pallet_balances::Config>::Balance;
#[frame_support::pallet(dev_mode)]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
#[pallet::config]
pub trait Config: pallet_balances::Config + frame_system::Config {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
}
#[pallet::pallet]
pub struct Pallet<T>(_);
#[pallet::call]
impl<T: Config> Pallet<T> {
pub fn add_dummy(origin: OriginFor<T>, id: T::AccountId) -> DispatchResult {
ensure_root(origin)?;
if let Some(mut dummies) = Dummy::<T>::get() {
dummies.push(id.clone());
Dummy::<T>::set(Some(dummies));
} else {
Dummy::<T>::set(Some(vec![id.clone()]));
}
Self::deposit_event(Event::AddDummy { account: id });
Ok(())
}
pub fn set_bar(
origin: OriginFor<T>,
#[pallet::compact] new_value: T::Balance,
) -> DispatchResult {
let sender = ensure_signed(origin)?;
<Bar<T>>::insert(&sender, new_value);
Self::deposit_event(Event::SetBar { account: sender, balance: new_value });
Ok(())
}
}
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
AddDummy { account: T::AccountId },
SetBar { account: T::AccountId, balance: BalanceOf<T> },
}
#[pallet::storage]
pub type Dummy<T: Config> = StorageValue<_, Vec<T::AccountId>>;
#[pallet::storage]
pub type Bar<T: Config> = StorageMap<_, _, T::AccountId, T::Balance>;
}