-
Notifications
You must be signed in to change notification settings - Fork 1.2k
migrate alliance, fast-unstake and bags list to use derive-impl #1636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
49b6757
e9b5626
b304cfd
cd8513b
b3ae7ce
a319f93
97f953e
e652c54
5965703
3c74110
bfcb62d
917f54f
ed28c1c
8f99359
581e218
38f196f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -216,7 +216,7 @@ pub mod pallet { | |
| /// Default implementations of [`DefaultConfig`], which can be used to implement [`Config`]. | ||
| pub mod config_preludes { | ||
| use super::*; | ||
| use frame_support::derive_impl; | ||
| use frame_support::{derive_impl, traits::ConstU64}; | ||
|
|
||
| pub struct TestDefaultConfig; | ||
|
|
||
|
|
@@ -227,12 +227,17 @@ pub mod pallet { | |
| impl DefaultConfig for TestDefaultConfig { | ||
| #[inject_runtime_type] | ||
| type RuntimeEvent = (); | ||
| #[inject_runtime_type] | ||
| type RuntimeHoldReason = (); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh, when we have
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can be any type (as long as it is a valid type identifier) and any type is valid because in |
||
|
|
||
| type Balance = u64; | ||
| type ExistentialDeposit = ConstU64<1>; | ||
|
|
||
| type ReserveIdentifier = (); | ||
| type FreezeIdentifier = (); | ||
|
|
||
| type DustRemoval = (); | ||
|
|
||
| type MaxLocks = (); | ||
| type MaxReserves = (); | ||
| type MaxFreezes = (); | ||
|
|
@@ -249,6 +254,10 @@ pub mod pallet { | |
| type RuntimeEvent: From<Event<Self, I>> | ||
| + IsType<<Self as frame_system::Config>::RuntimeEvent>; | ||
|
|
||
| /// The overarching hold reason. | ||
| #[pallet::no_default_bounds] | ||
| type RuntimeHoldReason: Parameter + Member + MaxEncodedLen + Ord + Copy; | ||
|
|
||
| /// Weight information for extrinsics in this pallet. | ||
| type WeightInfo: WeightInfo; | ||
|
|
||
|
|
@@ -266,7 +275,7 @@ pub mod pallet { | |
| + FixedPointOperand; | ||
|
|
||
| /// Handler for the unbalanced reduction when removing a dust account. | ||
| #[pallet::no_default] | ||
| #[pallet::no_default_bounds] | ||
| type DustRemoval: OnUnbalanced<CreditOf<Self, I>>; | ||
|
|
||
| /// The minimum amount required to keep an account open. MUST BE GREATER THAN ZERO! | ||
|
|
@@ -278,7 +287,7 @@ pub mod pallet { | |
| /// | ||
| /// Bottom line: Do yourself a favour and make it at least one! | ||
| #[pallet::constant] | ||
| #[pallet::no_default] | ||
| #[pallet::no_default_bounds] | ||
| type ExistentialDeposit: Get<Self::Balance>; | ||
|
|
||
| /// The means of storing the balances of an account. | ||
|
|
@@ -290,10 +299,6 @@ pub mod pallet { | |
| /// Use of reserves is deprecated in favour of holds. See `https://github.com/paritytech/substrate/pull/12951/` | ||
| type ReserveIdentifier: Parameter + Member + MaxEncodedLen + Ord + Copy; | ||
|
|
||
| /// The overarching hold reason. | ||
| #[pallet::no_default] | ||
| type RuntimeHoldReason: Parameter + Member + MaxEncodedLen + Ord + Copy; | ||
|
|
||
| /// The ID type for freezes. | ||
| type FreezeIdentifier: Parameter + Member + MaxEncodedLen + Ord + Copy; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ | |
|
|
||
| use crate::{self as fast_unstake}; | ||
| use frame_support::{ | ||
| assert_ok, | ||
| assert_ok, derive_impl, | ||
| pallet_prelude::*, | ||
| parameter_types, | ||
| traits::{ConstU64, Currency}, | ||
|
|
@@ -32,7 +32,6 @@ use pallet_staking::{Exposure, IndividualExposure, StakerStatus}; | |
| use sp_std::prelude::*; | ||
|
|
||
| pub type AccountId = u128; | ||
| pub type Nonce = u32; | ||
| pub type BlockNumber = u64; | ||
| pub type Balance = u128; | ||
| pub type T = Runtime; | ||
|
|
@@ -44,30 +43,13 @@ parameter_types! { | |
| ); | ||
| } | ||
|
|
||
| #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] | ||
| impl frame_system::Config for Runtime { | ||
| type BaseCallFilter = frame_support::traits::Everything; | ||
| type BlockWeights = BlockWeights; | ||
| type BlockLength = (); | ||
| type DbWeight = (); | ||
| type RuntimeOrigin = RuntimeOrigin; | ||
| type Nonce = Nonce; | ||
| type RuntimeCall = RuntimeCall; | ||
| type Hash = sp_core::H256; | ||
| type Hashing = sp_runtime::traits::BlakeTwo256; | ||
| type AccountId = AccountId; | ||
| type Lookup = IdentityLookup<Self::AccountId>; | ||
| type Block = Block; | ||
| type RuntimeEvent = RuntimeEvent; | ||
| type BlockHashCount = (); | ||
| type Version = (); | ||
| type PalletInfo = PalletInfo; | ||
| type AccountData = pallet_balances::AccountData<Balance>; | ||
| type OnNewAccount = (); | ||
| type OnKilledAccount = (); | ||
| type SystemWeightInfo = (); | ||
| type SS58Prefix = (); | ||
| type OnSetCode = (); | ||
| type MaxConsumers = frame_support::traits::ConstU32<16>; | ||
| // we use U128 account id in this pallet for a good reason. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the 'good reason'? should we mention it in this comment?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had mixed this in nomination-pools, where we do use u128 such that the process of converting a pool id into account id would work and yield different numbers. I actually don't know the reason for this, and will try and move it to u32.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems to have something to do with iteration order -- with u128, if I insert
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the right behavior is actually to be agnostic to the order, as the pallet makes no guarantees there. |
||
| type AccountId = AccountId; | ||
| type Lookup = IdentityLookup<Self::AccountId>; | ||
| } | ||
|
|
||
| impl pallet_timestamp::Config for Runtime { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,24 +43,15 @@ frame_support::construct_runtime!( | |
| impl frame_system::Config for Test { | ||
| type Block = Block; | ||
| type BlockHashCount = ConstU32<250>; | ||
| type RuntimeOrigin = RuntimeOrigin; | ||
| type RuntimeCall = RuntimeCall; | ||
| type RuntimeEvent = RuntimeEvent; | ||
| type BaseCallFilter = TestBaseCallFilter; | ||
| type PalletInfo = PalletInfo; | ||
| type OnSetCode = (); | ||
|
|
||
| type AccountData = pallet_balances::AccountData<u64>; | ||
| // This pallet wishes to overwrite this. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not aware tbh, but somehow in the test setu they wishes to on;y allow balances and remark transactions. Probably to test that any call filter here cannot be bipassed by being wrapped in a multisig. |
||
| type BaseCallFilter = TestBaseCallFilter; | ||
| } | ||
|
|
||
| #[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)] | ||
| impl pallet_balances::Config for Test { | ||
| type RuntimeEvent = RuntimeEvent; | ||
| type RuntimeHoldReason = (); | ||
| type ReserveIdentifier = [u8; 8]; | ||
| type DustRemoval = (); | ||
| type AccountStore = System; | ||
| type ExistentialDeposit = ConstU64<1>; | ||
| } | ||
|
|
||
| pub struct TestBaseCallFilter; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -877,6 +877,8 @@ pub fn inject_runtime_type(_: TokenStream, tokens: TokenStream) -> TokenStream { | |||
| if item.ident != "RuntimeCall" && | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd love to see docs on these macros
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Docs are available here:
|
||||
| item.ident != "RuntimeEvent" && | ||||
| item.ident != "RuntimeOrigin" && | ||||
| item.ident != "RuntimeHoldReason" && | ||||
| item.ident != "RuntimeFreezeReason" && | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be good to modify the error message as well. |
||||
| item.ident != "PalletInfo" | ||||
| { | ||||
| return syn::Error::new_spanned( | ||||
|
|
||||
Uh oh!
There was an error while loading. Please reload this page.