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

Add pallet attribute macro to declare pallets #6877

Merged
47 commits merged into from
Dec 24, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
b67c866
rename system Config to system Trait.
gui1117 Oct 27, 2020
336d3c9
make construct_runtime handle Pallet and Module
gui1117 Oct 27, 2020
942c161
introduce pallet attribute macro
gui1117 Oct 27, 2020
1e1e8a3
allow to print some upgrade helper from decl_storage
gui1117 Oct 29, 2020
0d9bb3e
Improved error msg, typo.
gui1117 Nov 19, 2020
b48cfc6
Improved error msg, typo.
gui1117 Nov 19, 2020
cc165a3
Improved error message on unexpected attributes + ui test
gui1117 Nov 19, 2020
460ccf9
add test for transactional
gui1117 Nov 19, 2020
5ced0a8
various typo
gui1117 Nov 19, 2020
688f044
some tips when spans are lost
gui1117 Nov 23, 2020
c5ef21f
allow pallet to depend on other pallet instances
gui1117 Nov 23, 2020
240a2a7
make event type metadata consistent with call and constant
gui1117 Nov 23, 2020
1229c33
error messages
gui1117 Nov 23, 2020
30000d0
Merge remote-tracking branch 'origin/master' into gui-macro-attribute
gui1117 Nov 23, 2020
c2148b0
ignore doc example
gui1117 Nov 23, 2020
e5485c8
fix pallet upgrade template
gui1117 Nov 23, 2020
1ff085e
Merge remote-tracking branch 'origin/master' into gui-macro-attribute
gui1117 Nov 25, 2020
d5b745f
fixup
gui1117 Nov 25, 2020
8e8ee8d
fix doc
gui1117 Nov 25, 2020
3ea926c
fix indentation
gui1117 Nov 25, 2020
bd99a8d
Apply suggestions code formatting
gui1117 Nov 30, 2020
0adbb30
some renames + fix compilation
gui1117 Nov 30, 2020
c96e1cf
remove unsupported genesis config type alias
gui1117 Nov 30, 2020
04a54d6
Merge remote-tracking branch 'origin/master' into gui-macro-attribute
gui1117 Nov 30, 2020
78789d6
merge fixup
gui1117 Nov 30, 2020
96845d8
fix ui tests
gui1117 Dec 2, 2020
1762c47
additional doc
gui1117 Dec 2, 2020
a03a4b4
Merge remote-tracking branch 'origin/master' into gui-macro-attribute
gui1117 Dec 2, 2020
4cb71d8
Merge remote-tracking branch 'origin/master' into gui-macro-attribute
gui1117 Dec 3, 2020
cf7ae7d
implement StorageInstance with new syntax
gui1117 Dec 3, 2020
88e6995
fix line width
gui1117 Dec 3, 2020
d1ec690
Merge remote-tracking branch 'origin/master' into gui-macro-attribute
gui1117 Dec 3, 2020
3a29683
fix doc: because pallet doc goes below reexport doc
gui1117 Dec 4, 2020
9430b34
Merge remote-tracking branch 'origin/master' into HEAD
gui1117 Dec 9, 2020
888d121
Update frame/support/procedural/src/pallet/parse/event.rs
gui1117 Dec 9, 2020
6fa68a9
Merge remote-tracking branch 'origin/master' into gui-macro-attribute
gui1117 Dec 9, 2020
0c6f916
Merge remote-tracking branch 'origin/master' into gui-macro-attribute
gui1117 Dec 14, 2020
52a654f
Update frame/system/src/lib.rs
gui1117 Dec 23, 2020
03c7fbf
Update frame/support/test/tests/pallet_ui.rs
gui1117 Dec 23, 2020
3f23d3c
improve doc as suggested
gui1117 Dec 23, 2020
d9d48c7
revert construct_runtime Pallet part.
gui1117 Dec 23, 2020
0d56f2b
refactor with less intricated code
gui1117 Dec 23, 2020
d9fdc4b
Merge remote-tracking branch 'origin/master' into gui-macro-attribute
gui1117 Dec 23, 2020
98cdc0e
fix ui test with new image
gui1117 Dec 23, 2020
ae38859
fix ui tests
gui1117 Dec 23, 2020
c158e5f
add minor tests
gui1117 Dec 24, 2020
10e8a92
Merge remote-tracking branch 'origin/master' into gui-macro-attribute
gui1117 Dec 24, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions bin/node-template/pallets/template/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod tests;
/// Configure the pallet by specifying the parameters and types on which it depends.
pub trait Trait: frame_system::Trait {
/// Because this pallet emits events, it depends on the runtime's definition of an event.
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
}

// The pallet's runtime storage items.
Expand All @@ -35,7 +35,7 @@ decl_storage! {
// Pallets use events to inform users when important changes are made.
// https://substrate.dev/docs/en/knowledgebase/runtime/events
decl_event!(
pub enum Event<T> where AccountId = <T as frame_system::Trait>::AccountId {
pub enum Event<T> where AccountId = <T as frame_system::Config>::AccountId {
/// Event documentation should end with an array that provides descriptive names for event
/// parameters. [something, who]
SomethingStored(u32, AccountId),
Expand Down
2 changes: 1 addition & 1 deletion bin/node-template/pallets/template/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ parameter_types! {
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
}

impl system::Trait for Test {
impl system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Call = ();
Expand Down
2 changes: 1 addition & 1 deletion bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ parameter_types! {

// Configure FRAME pallets to include in runtime.

impl frame_system::Trait for Runtime {
impl frame_system::Config for Runtime {
/// The basic call filter to use in dispatchable.
type BaseCallFilter = ();
/// The identifier used to distinguish between accounts.
Expand Down
2 changes: 1 addition & 1 deletion bin/node/executor/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ const CODE_TRANSFER: &str = r#"
#[test]
fn deploying_wasm_contract_should_work() {
let transfer_code = wat::parse_str(CODE_TRANSFER).unwrap();
let transfer_ch = <Runtime as frame_system::Trait>::Hashing::hash(&transfer_code);
let transfer_ch = <Runtime as frame_system::Config>::Hashing::hash(&transfer_code);

let addr = <Runtime as pallet_contracts::Trait>::DetermineContractAddress::contract_address_for(
&transfer_ch,
Expand Down
4 changes: 2 additions & 2 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ parameter_types! {

const_assert!(AvailableBlockRatio::get().deconstruct() >= AVERAGE_ON_INITIALIZE_WEIGHT.deconstruct());

impl frame_system::Trait for Runtime {
impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type Origin = Origin;
type Call = Call;
Expand Down Expand Up @@ -401,7 +401,7 @@ parameter_types! {

impl pallet_session::Trait for Runtime {
type Event = Event;
type ValidatorId = <Self as frame_system::Trait>::AccountId;
type ValidatorId = <Self as frame_system::Config>::AccountId;
type ValidatorIdOf = pallet_staking::StashOf<Self>;
type ShouldEndSession = Babe;
type NextSessionRotation = Babe;
Expand Down
6 changes: 3 additions & 3 deletions frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ use sp_runtime::traits::One;
/// The module configuration trait.
pub trait Trait: frame_system::Trait {
/// The overarching event type.
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;

/// The units in which we record balances.
type Balance: Member + Parameter + AtLeast32BitUnsigned + Default + Copy;
Expand Down Expand Up @@ -226,7 +226,7 @@ decl_module! {

decl_event! {
pub enum Event<T> where
<T as frame_system::Trait>::AccountId,
<T as frame_system::Config>::AccountId,
<T as Trait>::Balance,
<T as Trait>::AssetId,
{
Expand Down Expand Up @@ -298,7 +298,7 @@ mod tests {
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
Expand Down
4 changes: 2 additions & 2 deletions frame/atomic-swap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl<T: Trait, AccountId, C> SwapAction<AccountId, T> for BalanceSwapAction<Acco
/// Atomic swap's pallet configuration trait.
pub trait Trait: frame_system::Trait {
/// The overarching event type.
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
/// Swap action.
type SwapAction: SwapAction<Self::AccountId, Self> + Parameter;
/// Limit of proof size.
Expand Down Expand Up @@ -186,7 +186,7 @@ decl_error! {
decl_event!(
/// Event of atomic swap pallet.
pub enum Event<T> where
AccountId = <T as system::Trait>::AccountId,
AccountId = <T as system::Config>::AccountId,
PendingSwap = PendingSwap<T>,
{
/// Swap created. \[account, proof, swap\]
Expand Down
2 changes: 1 addition & 1 deletion frame/atomic-swap/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ parameter_types! {
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
Expand Down
2 changes: 1 addition & 1 deletion frame/aura/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ parameter_types! {
pub const MinimumPeriod: u64 = 1;
}

impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
Expand Down
2 changes: 1 addition & 1 deletion frame/authority-discovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ mod tests {
pub const AvailableBlockRatio: Perbill = Perbill::one();
}

impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
Expand Down
2 changes: 1 addition & 1 deletion frame/authorship/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ mod tests {
pub const AvailableBlockRatio: Perbill = Perbill::one();
}

impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
Expand Down
4 changes: 2 additions & 2 deletions frame/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ decl_module! {
}
}

impl<T: Trait> RandomnessT<<T as frame_system::Trait>::Hash> for Module<T> {
impl<T: Trait> RandomnessT<<T as frame_system::Config>::Hash> for Module<T> {
/// Some BABE blocks have VRF outputs where the block producer has exactly one bit of influence,
/// either they make the block or they do not make the block and thus someone else makes the
/// next block. Yet, this randomness is not fresh in all BABE blocks.
Expand All @@ -332,7 +332,7 @@ impl<T: Trait> RandomnessT<<T as frame_system::Trait>::Hash> for Module<T> {
subject.reserve(VRF_OUTPUT_LENGTH);
subject.extend_from_slice(&Self::randomness()[..]);

<T as frame_system::Trait>::Hashing::hash(&subject[..])
<T as frame_system::Config>::Hashing::hash(&subject[..])
}
}

Expand Down
4 changes: 2 additions & 2 deletions frame/babe/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ parameter_types! {
pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(16);
}

impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
Expand Down Expand Up @@ -109,7 +109,7 @@ impl_opaque_keys! {

impl pallet_session::Trait for Test {
type Event = ();
type ValidatorId = <Self as frame_system::Trait>::AccountId;
type ValidatorId = <Self as frame_system::Config>::AccountId;
type ValidatorIdOf = pallet_staking::StashOf<Self>;
type ShouldEndSession = Babe;
type NextSessionRotation = Babe;
Expand Down
12 changes: 6 additions & 6 deletions frame/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@
//! # type Currency: Currency<Self::AccountId>;
//! # }
//!
//! pub type BalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
//! pub type NegativeImbalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::NegativeImbalance;
//! pub type BalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
//! pub type NegativeImbalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance;
//!
//! # fn main() {}
//! ```
Expand All @@ -118,8 +118,8 @@
//! type Currency: LockableCurrency<Self::AccountId, Moment=Self::BlockNumber>;
//! }
//! # struct StakingLedger<T: Trait> {
//! # stash: <T as frame_system::Trait>::AccountId,
//! # total: <<T as Trait>::Currency as frame_support::traits::Currency<<T as frame_system::Trait>::AccountId>>::Balance,
//! # stash: <T as frame_system::Config>::AccountId,
//! # total: <<T as Trait>::Currency as frame_support::traits::Currency<<T as frame_system::Config>::AccountId>>::Balance,
//! # phantom: std::marker::PhantomData<T>,
//! # }
//! # const STAKING_ID: [u8; 8] = *b"staking ";
Expand Down Expand Up @@ -207,7 +207,7 @@ pub trait Trait<I: Instance = DefaultInstance>: frame_system::Trait {
type DustRemoval: OnUnbalanced<NegativeImbalance<Self, I>>;

/// The overarching event type.
type Event: From<Event<Self, I>> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self, I>> + Into<<Self as frame_system::Config>::Event>;

/// The minimum amount required to keep an account open.
type ExistentialDeposit: Get<Self::Balance>;
Expand All @@ -233,7 +233,7 @@ impl<T: Trait<I>, I: Instance> Subtrait<I> for T {

decl_event!(
pub enum Event<T, I: Instance = DefaultInstance> where
<T as frame_system::Trait>::AccountId,
<T as frame_system::Config>::AccountId,
<T as Trait<I>>::Balance
{
/// An account was created with some free balance. \[account, free_balance\]
Expand Down
2 changes: 1 addition & 1 deletion frame/balances/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ macro_rules! decl_tests {
pub type System = frame_system::Module<$test>;
pub type Balances = Module<$test>;

pub const CALL: &<$test as frame_system::Trait>::Call = &$crate::tests::CallWithDispatchInfo;
pub const CALL: &<$test as frame_system::Config>::Call = &$crate::tests::CallWithDispatchInfo;

/// create a transaction info struct from weight. Handy to avoid building the whole struct.
pub fn info_from_weight(w: Weight) -> DispatchInfo {
Expand Down
2 changes: 1 addition & 1 deletion frame/balances/src/tests_composite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ parameter_types! {
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
Expand Down
2 changes: 1 addition & 1 deletion frame/balances/src/tests_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ parameter_types! {
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
Expand Down
2 changes: 1 addition & 1 deletion frame/benchmarking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub trait Trait: frame_system::Trait + OtherTrait
#[derive(Clone, Eq, PartialEq)]
pub struct Test;

impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
Expand Down
2 changes: 1 addition & 1 deletion frame/collective/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const MAX_BYTES: u32 = 1_024;

fn assert_last_event<T: Trait<I>, I: Instance>(generic_event: <T as Trait<I>>::Event) {
let events = System::<T>::events();
let system_event: <T as frame_system::Trait>::Event = generic_event.into();
let system_event: <T as frame_system::Config>::Event = generic_event.into();
// compare to the last event record
let EventRecord { event, .. } = &events[events.len() - 1];
assert_eq!(event, &system_event);
Expand Down
12 changes: 6 additions & 6 deletions frame/collective/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub trait Trait<I: Instance=DefaultInstance>: frame_system::Trait {
+ GetDispatchInfo;

/// The outer event type.
type Event: From<Event<Self, I>> + Into<<Self as frame_system::Trait>::Event>;
type Event: From<Event<Self, I>> + Into<<Self as frame_system::Config>::Event>;

/// The time-out for council motions.
type MotionDuration: Get<Self::BlockNumber>;
Expand Down Expand Up @@ -166,7 +166,7 @@ pub enum RawOrigin<AccountId, I> {
}

/// Origin for the collective module.
pub type Origin<T, I=DefaultInstance> = RawOrigin<<T as frame_system::Trait>::AccountId, I>;
pub type Origin<T, I=DefaultInstance> = RawOrigin<<T as frame_system::Config>::AccountId, I>;

#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
/// Info for keeping track of a motion being voted on.
Expand Down Expand Up @@ -209,8 +209,8 @@ decl_storage! {

decl_event! {
pub enum Event<T, I=DefaultInstance> where
<T as frame_system::Trait>::Hash,
<T as frame_system::Trait>::AccountId,
<T as frame_system::Config>::Hash,
<T as frame_system::Config>::AccountId,
{
/// A motion (given hash) has been proposed (by given account) with a threshold (given
/// `MemberCount`).
Expand Down Expand Up @@ -276,7 +276,7 @@ fn get_result_weight(result: DispatchResultWithPostInfo) -> Option<Weight> {

// Note that councillor operations are assigned to the operational class.
decl_module! {
pub struct Module<T: Trait<I>, I: Instance=DefaultInstance> for enum Call where origin: <T as frame_system::Trait>::Origin {
pub struct Module<T: Trait<I>, I: Instance=DefaultInstance> for enum Call where origin: <T as frame_system::Config>::Origin {
type Error = Error<T, I>;

fn deposit_event() = default;
Expand Down Expand Up @@ -952,7 +952,7 @@ mod tests {
pub const MaxProposals: u32 = 100;
pub const MaxMembers: u32 = 100;
}
impl frame_system::Trait for Test {
impl frame_system::Config for Test {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
Expand Down
10 changes: 5 additions & 5 deletions frame/contracts/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ use frame_support::{
};
use pallet_contracts_primitives::{ErrorOrigin, ExecError, ExecReturnValue, ExecResult, ReturnFlags};

pub type AccountIdOf<T> = <T as frame_system::Trait>::AccountId;
pub type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
pub type MomentOf<T> = <<T as Trait>::Time as Time>::Moment;
pub type SeedOf<T> = <T as frame_system::Trait>::Hash;
pub type BlockNumberOf<T> = <T as frame_system::Trait>::BlockNumber;
pub type SeedOf<T> = <T as frame_system::Config>::Hash;
pub type BlockNumberOf<T> = <T as frame_system::Config>::BlockNumber;
pub type StorageKey = [u8; 32];

/// A type that represents a topic of an event. At the moment a hash is used.
pub type TopicOf<T> = <T as frame_system::Trait>::Hash;
pub type TopicOf<T> = <T as frame_system::Config>::Hash;

/// Describes whether we deal with a contract or a plain account.
pub enum TransactorKind {
Expand Down Expand Up @@ -770,7 +770,7 @@ mod tests {

fn insert(&mut self, f: impl Fn(MockCtx) -> ExecResult + 'a) -> CodeHash<Test> {
// Generate code hashes as monotonically increasing values.
let code_hash = <Test as frame_system::Trait>::Hash::from_low_u64_be(self.counter);
let code_hash = <Test as frame_system::Config>::Hash::from_low_u64_be(self.counter);

self.counter += 1;
self.map.insert(code_hash, MockExecutable::new(f));
Expand Down
Loading