-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Replace last usages of <() as PalletInfo> in substrate
#8080
Changes from 4 commits
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 |
|---|---|---|
|
|
@@ -41,3 +41,15 @@ frame_support::decl_module! { | |
| /// Some test module | ||
| pub struct Module<T: Config> for enum Call where origin: T::Origin, system=self {} | ||
| } | ||
|
|
||
| /// A PalletInfo implementation which just panics. | ||
| pub struct PanicPalletInfo; | ||
|
|
||
| impl frame_support::traits::PalletInfo for PanicPalletInfo{ | ||
| fn index<P: 'static>() -> Option<usize> { | ||
| unimplemented!("PanicPalletInfo mustn't be triggered by tests"); | ||
| } | ||
| fn name<P: 'static>() -> Option<&'static str> { | ||
| unimplemented!("PanicPalletInfo mustn't be triggered by tests"); | ||
| } | ||
| } | ||
|
Member
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 don't you use it from
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. in frame-support I didn't expose it, it is hidden behind the
Member
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. Ahh I had overseen this. Maybe move it at least from the
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. yes, I moved it to |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -433,6 +433,37 @@ impl From<frame_system::Event<Runtime>> for Event { | |
| } | ||
| } | ||
|
|
||
| impl frame_support::traits::PalletInfo for Runtime { | ||
| fn index<P: 'static>() -> Option<usize> { | ||
| let type_id = sp_std::any::TypeId::of::<P>(); | ||
| if type_id == sp_std::any::TypeId::of::<system::Module<Runtime>>() { | ||
| return Some(0) | ||
| } | ||
| if type_id == sp_std::any::TypeId::of::<pallet_timestamp::Module<Runtime>>() { | ||
| return Some(1) | ||
| } | ||
| if type_id == sp_std::any::TypeId::of::<pallet_babe::Module<Runtime>>() { | ||
| return Some(2) | ||
| } | ||
|
|
||
| None | ||
| } | ||
| fn name<P: 'static>() -> Option<&'static str> { | ||
| let type_id = sp_std::any::TypeId::of::<P>(); | ||
| if type_id == sp_std::any::TypeId::of::<system::Module<Runtime>>() { | ||
| return Some("System") | ||
| } | ||
| if type_id == sp_std::any::TypeId::of::<pallet_timestamp::Module<Runtime>>() { | ||
| return Some("Timestamp") | ||
| } | ||
| if type_id == sp_std::any::TypeId::of::<pallet_babe::Module<Runtime>>() { | ||
| return Some("Babe") | ||
| } | ||
|
|
||
| None | ||
| } | ||
| } | ||
|
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. note: I didn't use construct_runtime here because runtime declare a very specific implementation of |
||
|
|
||
| parameter_types! { | ||
| pub const BlockHashCount: BlockNumber = 2400; | ||
| pub const MinimumPeriod: u64 = 5; | ||
|
|
@@ -463,7 +494,7 @@ impl frame_system::Config for Runtime { | |
| type BlockHashCount = BlockHashCount; | ||
| type DbWeight = (); | ||
| type Version = (); | ||
| type PalletInfo = (); | ||
| type PalletInfo = Self; | ||
| type AccountData = (); | ||
| type OnNewAccount = (); | ||
| type OnKilledAccount = (); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: I didn't use construct_runtime here because I don't think it is really needed for the test, and the easiest is a manual implementation.