Skip to content
This repository was archived by the owner on Mar 13, 2023. It is now read-only.

Commit c8ba4bd

Browse files
committed
feat: migrate crab->backing from declarative macro to procedural macro
1 parent 235e3cb commit c8ba4bd

File tree

1 file changed

+51
-39
lines changed
  • frame/bridge/crab/backing/src

1 file changed

+51
-39
lines changed

frame/bridge/crab/backing/src/lib.rs

Lines changed: 51 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,66 +20,78 @@
2020
2121
#![cfg_attr(not(feature = "std"), no_std)]
2222

23+
pub use pallet::*;
24+
2325
pub mod weights;
2426
// --- darwinia ---
2527
pub use weights::WeightInfo;
2628

29+
use frame_support::traits::Currency;
30+
2731
mod types {
2832
// --- darwinia ---
29-
#[cfg(feature = "std")]
3033
use crate::*;
3134

3235
pub type AccountId<T> = <T as frame_system::Config>::AccountId;
3336

34-
#[cfg(feature = "std")]
35-
pub type RingBalance<T> = <RingCurrency<T> as Currency<AccountId<T>>>::Balance;
36-
37-
#[cfg(feature = "std")]
3837
type RingCurrency<T> = <T as Config>::RingCurrency;
38+
39+
pub type RingBalance<T> = <RingCurrency<T> as Currency<AccountId<T>>>::Balance;
3940
}
4041

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::*;
4950

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>;
5256

53-
type RingCurrency: Currency<AccountId<Self>>;
57+
type RingCurrency: Currency<AccountId<Self>>;
5458

55-
type WeightInfo: WeightInfo;
56-
}
59+
type WeightInfo: WeightInfo;
5760

58-
decl_storage! {
59-
trait Store for Module<T: Config> as DarwiniaCrabBacking {}
61+
// no event for this pallet
62+
}
6063

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>,
6977
}
70-
}
7178

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+
}
7886
}
79-
}
8087

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+
}
8496
}
8597
}

0 commit comments

Comments
 (0)