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

Commit 2130f53

Browse files
committed
fix pallet::const_
1 parent 91eff0b commit 2130f53

File tree

4 files changed

+43
-10
lines changed

4 files changed

+43
-10
lines changed

bin/node-template/pallets/template/src/lib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ mod mock;
1313
#[cfg(test)]
1414
mod tests;
1515

16+
#[frame_support::pallet(TemplateModule)]
17+
mod pallet {
1618
/// Configure the pallet by specifying the parameters and types on which it depends.
17-
pub trait Trait: frame_system::Trait {
18-
/// Because this pallet emits events, it depends on the runtime's definition of an event.
19-
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
20-
}
19+
#[pallet::trait_]
20+
pub trait Trait: frame_system::Trait {
21+
/// Because this pallet emits events, it depends on the runtime's definition of an event.
22+
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
23+
}
2124

2225
// The pallet's runtime storage items.
2326
// https://substrate.dev/docs/en/knowledgebase/runtime/storage

frame/example-offchain-worker/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,21 @@ mod pallet {
133133
/// To avoid sending too many transactions, we only attempt to send one
134134
/// every `GRACE_PERIOD` blocks. We use Local Storage to coordinate
135135
/// sending between distinct runs of this offchain worker.
136+
#[pallet::const_]
136137
type GracePeriod: Get<Self::BlockNumber>;
137138

138139
/// Number of blocks of cooldown after unsigned transaction is included.
139140
///
140141
/// This ensures that we only accept unsigned transactions once, every `UnsignedInterval`
141142
/// blocks.
143+
#[pallet::const_]
142144
type UnsignedInterval: Get<Self::BlockNumber>;
143145

144146
/// A configuration for base priority of unsigned transactions.
145147
///
146148
/// This is exposed so that it can be tuned for particular runtime, when
147149
/// multiple pallets send unsigned transactions.
150+
#[pallet::const_]
148151
type UnsignedPriority: Get<TransactionPriority>;
149152
}
150153

frame/support/procedural/src/pallet/expand/trait_.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub fn expand_trait_(def: &mut Def) -> proc_macro2::TokenStream {
8888
)
8989
),
9090
documentation: #scrate::dispatch::DecodeDifferent::Encode(
91-
&[ #( #doc )* ]
91+
&[ #( #doc ),* ]
9292
),
9393
}
9494
})
@@ -101,7 +101,7 @@ pub fn expand_trait_(def: &mut Def) -> proc_macro2::TokenStream {
101101
pub fn module_constants_metadata()
102102
-> &'static [#scrate::dispatch::ModuleConstantMetadata]
103103
{
104-
&[ #( #consts )* ]
104+
&[ #( #consts ),* ]
105105
}
106106
}
107107
)

frame/support/test/tests/pallet.rs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,18 @@ pub mod pallet {
3333

3434
#[pallet::trait_]
3535
pub trait Trait: frame_system::Trait {
36+
/// Some comment
37+
/// Some comment
3638
#[pallet::const_]
3739
type MyGetParam: Get<u32>;
40+
41+
/// Some comment
42+
/// Some comment
43+
#[pallet::const_]
44+
type MyGetParam2: Get<u32>;
45+
3846
type Balance: Parameter + Default;
47+
3948
type Event: From<Event<Self>> + IsType<<Self as frame_system::Trait>::Event>;
4049
}
4150

@@ -68,7 +77,7 @@ pub mod pallet {
6877
impl<T: Trait> Call for Module<T> where T::Balance: From<u64> {
6978
/// Doc comment put in metadata
7079
#[pallet::weight(Weight::from(*_foo))]
71-
fn foo(origin: OriginFor<T>, #[pallet::compact] _foo: u32) -> DispatchResultWithPostInfo {
80+
fn foo(origin: OriginFor<T>, #[pallet::compact] _foo: u32, _bar: u32) -> DispatchResultWithPostInfo {
7281
T::Balance::from(3u64); // Test for where clause
7382
let _ = origin;
7483
Self::deposit_event(Event::Something(3));
@@ -174,6 +183,7 @@ pub mod pallet {
174183

175184
frame_support::parameter_types!(
176185
pub const MyGetParam: u32= 10;
186+
pub const MyGetParam2: u32= 11;
177187
pub const BlockHashCount: u32 = 250;
178188
pub const MaximumBlockWeight: frame_support::weights::Weight = 1024;
179189
pub const MaximumBlockLength: u32 = 2 * 1024;
@@ -210,6 +220,7 @@ impl frame_system::Trait for Runtime {
210220
impl pallet::Trait for Runtime {
211221
type Event = Event;
212222
type MyGetParam= MyGetParam;
223+
type MyGetParam2= MyGetParam2;
213224
type Balance = u64;
214225
}
215226

@@ -230,7 +241,7 @@ frame_support::construct_runtime!(
230241

231242
#[test]
232243
fn call_expand() {
233-
let call_foo = pallet::Call::<Runtime>::foo(3);
244+
let call_foo = pallet::Call::<Runtime>::foo(3, 0);
234245
assert_eq!(
235246
call_foo.get_dispatch_info(),
236247
DispatchInfo {
@@ -275,7 +286,7 @@ fn instance_expand() {
275286
fn module_expand_deposit_event() {
276287
TestExternalities::default().execute_with(|| {
277288
frame_system::Module::<Runtime>::set_block_number(1);
278-
pallet::Call::<Runtime>::foo(3).dispatch_bypass_filter(None.into()).unwrap();
289+
pallet::Call::<Runtime>::foo(3, 0).dispatch_bypass_filter(None.into()).unwrap();
279290
assert_eq!(
280291
frame_system::Module::<Runtime>::events()[0].event,
281292
Event::pallet(pallet::Event::Something(3)),
@@ -432,6 +443,10 @@ fn metadata() {
432443
FunctionArgumentMetadata {
433444
name: DecodeDifferent::Decoded("_foo".to_string()),
434445
ty: DecodeDifferent::Decoded("Compact<u32>".to_string()),
446+
},
447+
FunctionArgumentMetadata {
448+
name: DecodeDifferent::Decoded("_bar".to_string()),
449+
ty: DecodeDifferent::Decoded("u32".to_string()),
435450
}
436451
]),
437452
documentation: DecodeDifferent::Decoded(vec![
@@ -477,7 +492,19 @@ fn metadata() {
477492
name: DecodeDifferent::Decoded("MyGetParam".to_string()),
478493
ty: DecodeDifferent::Decoded("u32".to_string()),
479494
value: DecodeDifferent::Decoded(vec![10, 0, 0, 0]),
480-
documentation: DecodeDifferent::Decoded(vec![]),
495+
documentation: DecodeDifferent::Decoded(vec![
496+
" Some comment".to_string(),
497+
" Some comment".to_string(),
498+
]),
499+
},
500+
ModuleConstantMetadata {
501+
name: DecodeDifferent::Decoded("MyGetParam2".to_string()),
502+
ty: DecodeDifferent::Decoded("u32".to_string()),
503+
value: DecodeDifferent::Decoded(vec![11, 0, 0, 0]),
504+
documentation: DecodeDifferent::Decoded(vec![
505+
" Some comment".to_string(),
506+
" Some comment".to_string(),
507+
]),
481508
},
482509
]),
483510
errors: DecodeDifferent::Decoded(vec![

0 commit comments

Comments
 (0)