|
20 | 20 |
|
21 | 21 | #![cfg_attr(not(feature = "std"), no_std)] |
22 | 22 |
|
| 23 | +pub use pallet::*; |
| 24 | + |
23 | 25 | pub mod weights; |
24 | 26 | // --- darwinia --- |
25 | 27 | pub use weights::WeightInfo; |
26 | 28 |
|
| 29 | +use frame_support::traits::Currency; |
| 30 | + |
27 | 31 | mod types { |
28 | 32 | // --- darwinia --- |
29 | | - #[cfg(feature = "std")] |
30 | 33 | use crate::*; |
31 | 34 |
|
32 | 35 | pub type AccountId<T> = <T as frame_system::Config>::AccountId; |
33 | 36 |
|
34 | | - #[cfg(feature = "std")] |
35 | | - pub type RingBalance<T> = <RingCurrency<T> as Currency<AccountId<T>>>::Balance; |
36 | | - |
37 | | - #[cfg(feature = "std")] |
38 | 37 | type RingCurrency<T> = <T as Config>::RingCurrency; |
| 38 | + |
| 39 | + pub type RingBalance<T> = <RingCurrency<T> as Currency<AccountId<T>>>::Balance; |
39 | 40 | } |
40 | 41 |
|
41 | | -// --- substrate --- |
42 | | -use frame_support::{ |
43 | | - decl_module, decl_storage, |
44 | | - traits::{Currency, Get}, |
45 | | -}; |
46 | | -use sp_runtime::{traits::AccountIdConversion, ModuleId}; |
47 | | -// --- darwinia --- |
48 | | -use types::*; |
| 42 | +#[frame_support::pallet] |
| 43 | +pub mod pallet { |
| 44 | + use super::*; |
| 45 | + use frame_support::pallet_prelude::*; |
| 46 | + use frame_support::traits::{Currency, Get}; |
| 47 | + use frame_system::pallet_prelude::*; |
| 48 | + use sp_runtime::{traits::AccountIdConversion, ModuleId}; |
| 49 | + use types::*; |
49 | 50 |
|
50 | | -pub trait Config: frame_system::Config { |
51 | | - type ModuleId: Get<ModuleId>; |
| 51 | + /// Configure the pallet by specifying the parameters and types on which it depends. |
| 52 | + #[pallet::config] |
| 53 | + pub trait Config: frame_system::Config { |
| 54 | + #[pallet::constant] |
| 55 | + type ModuleId: Get<ModuleId>; |
52 | 56 |
|
53 | | - type RingCurrency: Currency<AccountId<Self>>; |
| 57 | + type RingCurrency: Currency<AccountId<Self>>; |
54 | 58 |
|
55 | | - type WeightInfo: WeightInfo; |
56 | | -} |
| 59 | + type WeightInfo: WeightInfo; |
57 | 60 |
|
58 | | -decl_storage! { |
59 | | - trait Store for Module<T: Config> as DarwiniaCrabBacking {} |
| 61 | + // no event for this pallet |
| 62 | + } |
60 | 63 |
|
61 | | - add_extra_genesis { |
62 | | - config(backed_ring): RingBalance<T>; |
63 | | - build(|config| { |
64 | | - let _ = T::RingCurrency::make_free_balance_be( |
65 | | - &<Module<T>>::account_id(), |
66 | | - T::RingCurrency::minimum_balance() + config.backed_ring |
67 | | - ); |
68 | | - }); |
| 64 | + // Define the pallet struct placeholder, various pallet function are implemented on it. |
| 65 | + #[pallet::pallet] |
| 66 | + pub struct Pallet<T>(_); |
| 67 | + |
| 68 | + #[pallet::hooks] |
| 69 | + impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {} |
| 70 | + |
| 71 | + #[pallet::call] |
| 72 | + impl<T: Config> Pallet<T> {} |
| 73 | + |
| 74 | + #[pallet::genesis_config] |
| 75 | + pub struct GenesisConfig<T: Config> { |
| 76 | + pub backed_ring: RingBalance<T>, |
69 | 77 | } |
70 | | -} |
71 | 78 |
|
72 | | -decl_module! { |
73 | | - pub struct Module<T: Config> for enum Call |
74 | | - where |
75 | | - origin: T::Origin |
76 | | - { |
77 | | - const ModuleId: ModuleId = T::ModuleId::get(); |
| 79 | + #[cfg(feature = "std")] |
| 80 | + impl<T: Config> Default for GenesisConfig<T> { |
| 81 | + fn default() -> Self { |
| 82 | + Self { |
| 83 | + backed_ring: Default::default(), |
| 84 | + } |
| 85 | + } |
78 | 86 | } |
79 | | -} |
80 | 87 |
|
81 | | -impl<T: Config> Module<T> { |
82 | | - pub fn account_id() -> T::AccountId { |
83 | | - T::ModuleId::get().into_account() |
| 88 | + #[pallet::genesis_build] |
| 89 | + impl<T: Config> GenesisBuild<T> for GenesisConfig<T> { |
| 90 | + fn build(&self) { |
| 91 | + let _ = T::RingCurrency::make_free_balance_be( |
| 92 | + &T::ModuleId::get().into_account(), |
| 93 | + T::RingCurrency::minimum_balance() + self.backed_ring, |
| 94 | + ); |
| 95 | + } |
84 | 96 | } |
85 | 97 | } |
0 commit comments