pallet_proxy_genesis_companion/
lib.rs1#![cfg_attr(not(feature = "std"), no_std)]
24
25#[cfg(test)]
26mod mock;
27#[cfg(test)]
28mod tests;
29
30use frame_support::pallet;
31pub use pallet::*;
32
33#[pallet]
34pub mod pallet {
35 use frame_support::pallet_prelude::*;
36 use sp_runtime::traits::BlockNumberProvider;
37 use sp_std::vec::Vec;
38
39 type BlockNumberFor<T> =
40 <<T as Config>::BlockNumberProvider as BlockNumberProvider>::BlockNumber;
41
42 #[pallet::pallet]
44 #[pallet::without_storage_info]
45 pub struct Pallet<T>(PhantomData<T>);
46
47 #[pallet::config]
51 pub trait Config:
52 frame_system::Config
53 + pallet_proxy::Config<
54 ProxyType = <Self as Config>::ProxyType,
55 BlockNumberProvider = <Self as Config>::BlockNumberProvider,
56 >
57 {
58 type ProxyType: MaybeSerializeDeserialize + Clone;
60
61 type BlockNumberProvider: BlockNumberProvider<
62 BlockNumber: MaybeSerializeDeserialize + Clone,
63 >;
64 }
65
66 #[pallet::genesis_config]
67 pub struct GenesisConfig<T: Config> {
68 pub proxies: Vec<(
69 T::AccountId,
70 T::AccountId,
71 <T as Config>::ProxyType,
72 BlockNumberFor<T>,
73 )>,
74 }
75
76 impl<T: Config> Default for GenesisConfig<T> {
77 fn default() -> Self {
78 Self {
79 proxies: Vec::new(),
80 }
81 }
82 }
83
84 #[pallet::genesis_build]
85 impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
86 fn build(&self) {
87 for (delegator, delegatee, proxy_type, delay) in &self.proxies {
88 pallet_proxy::Pallet::<T>::add_proxy_delegate(
89 delegator,
90 delegatee.clone(),
91 proxy_type.clone(),
92 *delay,
93 )
94 .expect("Genesis proxy could not be added");
95 }
96 }
97 }
98}