diff --git a/Cargo.toml b/Cargo.toml index d77ff631396..5c68b6c8a4d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,6 @@ panic = 'unwind' [workspace] members = [ 'node', - 'pallets/template', + 'pallets/cfgeneric', 'runtime', ] diff --git a/pallets/template/Cargo.toml b/pallets/template/Cargo.toml deleted file mode 100644 index 8f08d3eb7fd..00000000000 --- a/pallets/template/Cargo.toml +++ /dev/null @@ -1,68 +0,0 @@ -[dev-dependencies.serde] -version = '1.0.119' - -[dev-dependencies.sp-core] -default-features = false -git = 'https://github.com/paritytech/substrate.git' -rev = 'd6c33e7ec313f9bd5e319dc0a5a3ace5543f9617' -version = '3.0.0' - -[dev-dependencies.sp-io] -default-features = false -git = 'https://github.com/paritytech/substrate.git' -rev = 'd6c33e7ec313f9bd5e319dc0a5a3ace5543f9617' -version = '3.0.0' - -[dev-dependencies.sp-runtime] -default-features = false -git = 'https://github.com/paritytech/substrate.git' -rev = 'd6c33e7ec313f9bd5e319dc0a5a3ace5543f9617' -version = '3.0.0' -[dependencies.codec] -default-features = false -features = ['derive'] -package = 'parity-scale-codec' -version = '2.0.0' - -[dependencies.frame-benchmarking] -default-features = false -git = 'https://github.com/paritytech/substrate.git' -optional = true -rev = 'd6c33e7ec313f9bd5e319dc0a5a3ace5543f9617' -version = '3.1.0' - -[dependencies.frame-support] -default-features = false -git = 'https://github.com/paritytech/substrate.git' -rev = 'd6c33e7ec313f9bd5e319dc0a5a3ace5543f9617' -version = '3.0.0' - -[dependencies.frame-system] -default-features = false -git = 'https://github.com/paritytech/substrate.git' -rev = 'd6c33e7ec313f9bd5e319dc0a5a3ace5543f9617' -version = '3.0.0' - -[features] -default = ['std'] -runtime-benchmarks = ['frame-benchmarking'] -std = [ - 'codec/std', - 'frame-support/std', - 'frame-system/std', - 'frame-benchmarking/std', -] -try-runtime = ['frame-support/try-runtime'] - -[package] -authors = ['Substrate DevHub '] -description = 'FRAME pallet template for defining custom runtime logic.' -edition = '2018' -homepage = 'https://substrate.dev' -license = 'Unlicense' -name = 'pallet-template' -readme = 'README.md' -repository = 'https://github.com/substrate-developer-hub/substrate-node-template/' -version = '3.0.0' -[package.metadata.docs.rs] -targets = ['x86_64-unknown-linux-gnu'] diff --git a/pallets/template/README.md b/pallets/template/README.md deleted file mode 100644 index 8d751a42207..00000000000 --- a/pallets/template/README.md +++ /dev/null @@ -1 +0,0 @@ -License: Unlicense \ No newline at end of file diff --git a/pallets/template/src/benchmarking.rs b/pallets/template/src/benchmarking.rs deleted file mode 100644 index 93d7fa395ad..00000000000 --- a/pallets/template/src/benchmarking.rs +++ /dev/null @@ -1,24 +0,0 @@ -//! Benchmarking setup for pallet-template - -use super::*; - -use frame_system::RawOrigin; -use frame_benchmarking::{benchmarks, whitelisted_caller, impl_benchmark_test_suite}; -#[allow(unused)] -use crate::Pallet as Template; - -benchmarks! { - do_something { - let s in 0 .. 100; - let caller: T::AccountId = whitelisted_caller(); - }: _(RawOrigin::Signed(caller), s) - verify { - assert_eq!(Something::::get(), Some(s)); - } -} - -impl_benchmark_test_suite!( - Template, - crate::mock::new_test_ext(), - crate::mock::Test, -); diff --git a/pallets/template/src/lib.rs b/pallets/template/src/lib.rs deleted file mode 100644 index 373a56f4441..00000000000 --- a/pallets/template/src/lib.rs +++ /dev/null @@ -1,104 +0,0 @@ -#![cfg_attr(not(feature = "std"), no_std)] - -/// Edit this file to define custom logic or remove it if it is not needed. -/// Learn more about FRAME and the core library of Substrate FRAME pallets: -/// - -pub use pallet::*; - -#[cfg(test)] -mod mock; - -#[cfg(test)] -mod tests; - -#[cfg(feature = "runtime-benchmarks")] -mod benchmarking; - -#[frame_support::pallet] -pub mod pallet { - use frame_support::{dispatch::DispatchResult, pallet_prelude::*}; - use frame_system::pallet_prelude::*; - - /// Configure the pallet by specifying the parameters and types on which it depends. - #[pallet::config] - pub trait Config: frame_system::Config { - /// Because this pallet emits events, it depends on the runtime's definition of an event. - type Event: From> + IsType<::Event>; - } - - #[pallet::pallet] - #[pallet::generate_store(pub(super) trait Store)] - pub struct Pallet(_); - - // The pallet's runtime storage items. - // https://substrate.dev/docs/en/knowledgebase/runtime/storage - #[pallet::storage] - #[pallet::getter(fn something)] - // Learn more about declaring storage items: - // https://substrate.dev/docs/en/knowledgebase/runtime/storage#declaring-storage-items - pub type Something = StorageValue<_, u32>; - - // Pallets use events to inform users when important changes are made. - // https://substrate.dev/docs/en/knowledgebase/runtime/events - #[pallet::event] - #[pallet::metadata(T::AccountId = "AccountId")] - #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event { - /// Event documentation should end with an array that provides descriptive names for event - /// parameters. [something, who] - SomethingStored(u32, T::AccountId), - } - - // Errors inform users that something went wrong. - #[pallet::error] - pub enum Error { - /// Error names should be descriptive. - NoneValue, - /// Errors should have helpful documentation associated with them. - StorageOverflow, - } - - // Dispatchable functions allows users to interact with the pallet and invoke state changes. - // These functions materialize as "extrinsics", which are often compared to transactions. - // Dispatchable functions must be annotated with a weight and must return a DispatchResult. - #[pallet::call] - impl Pallet { - /// An example dispatchable that takes a singles value as a parameter, writes the value to - /// storage and emits an event. This function must be dispatched by a signed extrinsic. - #[pallet::weight(10_000 + T::DbWeight::get().writes(1))] - pub fn do_something(origin: OriginFor, something: u32) -> DispatchResult { - // Check that the extrinsic was signed and get the signer. - // This function will return an error if the extrinsic is not signed. - // https://substrate.dev/docs/en/knowledgebase/runtime/origin - let who = ensure_signed(origin)?; - - // Update storage. - >::put(something); - - // Emit an event. - Self::deposit_event(Event::SomethingStored(something, who)); - // Return a successful DispatchResultWithPostInfo - Ok(()) - } - - /// An example dispatchable that may throw a custom error. - #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))] - pub fn cause_error(origin: OriginFor) -> DispatchResult { - let _who = ensure_signed(origin)?; - - // Read a value from storage. - match >::get() { - // Return an error if the value has not been set. - None => Err(Error::::NoneValue)?, - Some(old) => { - // Increment the value read from storage; will error in the event of overflow. - let new = old.checked_add(1).ok_or(Error::::StorageOverflow)?; - // Update the value in storage with the incremented result. - >::put(new); - Ok(()) - }, - } - } - } -} diff --git a/pallets/template/src/mock.rs b/pallets/template/src/mock.rs deleted file mode 100644 index 8719bcb4df2..00000000000 --- a/pallets/template/src/mock.rs +++ /dev/null @@ -1,62 +0,0 @@ -use crate as pallet_template; -use sp_core::H256; -use frame_support::parameter_types; -use sp_runtime::{ - traits::{BlakeTwo256, IdentityLookup}, testing::Header, -}; -use frame_system as system; - -type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; -type Block = frame_system::mocking::MockBlock; - -// Configure a mock runtime to test the pallet. -frame_support::construct_runtime!( - pub enum Test where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic, - { - System: frame_system::{Pallet, Call, Config, Storage, Event}, - TemplateModule: pallet_template::{Pallet, Call, Storage, Event}, - } -); - -parameter_types! { - pub const BlockHashCount: u64 = 250; - pub const SS58Prefix: u8 = 42; -} - -impl system::Config for Test { - type BaseCallFilter = (); - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type Origin = Origin; - type Call = Call; - type Index = u64; - type BlockNumber = u64; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = u64; - type Lookup = IdentityLookup; - type Header = Header; - type Event = Event; - type BlockHashCount = BlockHashCount; - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = (); - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = SS58Prefix; - type OnSetCode = (); -} - -impl pallet_template::Config for Test { - type Event = Event; -} - -// Build genesis storage according to the mock runtime. -pub fn new_test_ext() -> sp_io::TestExternalities { - system::GenesisConfig::default().build_storage::().unwrap().into() -} diff --git a/pallets/template/src/tests.rs b/pallets/template/src/tests.rs deleted file mode 100644 index 3356b29ff35..00000000000 --- a/pallets/template/src/tests.rs +++ /dev/null @@ -1,23 +0,0 @@ -use crate::{Error, mock::*}; -use frame_support::{assert_ok, assert_noop}; - -#[test] -fn it_works_for_default_value() { - new_test_ext().execute_with(|| { - // Dispatch a signed extrinsic. - assert_ok!(TemplateModule::do_something(Origin::signed(1), 42)); - // Read pallet storage and assert an expected result. - assert_eq!(TemplateModule::something(), Some(42)); - }); -} - -#[test] -fn correct_error_for_none_value() { - new_test_ext().execute_with(|| { - // Ensure the expected error is thrown when no value is present. - assert_noop!( - TemplateModule::cause_error(Origin::signed(1)), - Error::::NoneValue - ); - }); -} diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 67bbfd5261d..bd110e4ddf6 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -85,11 +85,6 @@ git = 'https://github.com/paritytech/substrate.git' rev = 'd6c33e7ec313f9bd5e319dc0a5a3ace5543f9617' version = '3.0.0' -[dependencies.pallet-template] -default-features = false -path = '../pallets/template' -version = '3.0.0' - [dependencies.pallet-timestamp] default-features = false git = 'https://github.com/paritytech/substrate.git' @@ -198,7 +193,6 @@ runtime-benchmarks = [ 'frame-system/runtime-benchmarks', 'hex-literal', 'pallet-balances/runtime-benchmarks', - 'pallet-template/runtime-benchmarks', 'pallet-timestamp/runtime-benchmarks', 'sp-runtime/runtime-benchmarks', ] @@ -213,7 +207,6 @@ std = [ 'pallet-grandpa/std', 'pallet-randomness-collective-flip/std', 'pallet-sudo/std', - 'pallet-template/std', 'pallet-timestamp/std', 'pallet-transaction-payment-rpc-runtime-api/std', 'pallet-transaction-payment/std', diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 2ff4272747e..1fc2e5d7d99 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -39,8 +39,6 @@ pub use frame_support::{ }; use pallet_transaction_payment::CurrencyAdapter; -/// Import the template pallet. -pub use pallet_template; /// An index to a block. pub type BlockNumber = u32; @@ -274,10 +272,6 @@ impl pallet_sudo::Config for Runtime { type Call = Call; } -/// Configure the pallet-template in pallets/template. -impl pallet_template::Config for Runtime { - type Event = Event; -} // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( @@ -294,8 +288,6 @@ construct_runtime!( Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, TransactionPayment: pallet_transaction_payment::{Pallet, Storage}, Sudo: pallet_sudo::{Pallet, Call, Config, Storage, Event}, - // Include the custom logic from the pallet-template in the runtime. - TemplateModule: pallet_template::{Pallet, Call, Storage, Event}, } ); @@ -487,7 +479,6 @@ impl_runtime_apis! { add_benchmark!(params, batches, frame_system, SystemBench::); add_benchmark!(params, batches, pallet_balances, Balances); add_benchmark!(params, batches, pallet_timestamp, Timestamp); - add_benchmark!(params, batches, pallet_template, TemplateModule); if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } Ok(batches)