Skip to content

Commit

Permalink
Update Parachain templates to latest convention
Browse files Browse the repository at this point in the history
  • Loading branch information
dudo50 committed Oct 28, 2024
1 parent 4287a83 commit 6004eb8
Show file tree
Hide file tree
Showing 49 changed files with 2,842 additions and 2,200 deletions.
4,225 changes: 2,535 additions & 1,690 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ members = [
"bridges/chains/chain-bridge-hub-rococo",
"bridges/chains/chain-bridge-hub-westend",
"bridges/chains/chain-kusama",
"templates/parachain/pallets/xcnft",
"templates/parachain_two/pallets/xcnft",
"bridges/chains/chain-polkadot",
"bridges/chains/chain-polkadot-bulletin",
"bridges/chains/chain-rococo",
Expand Down Expand Up @@ -537,11 +539,9 @@ members = [
"templates/minimal/runtime",
"templates/parachain/node",
"templates/parachain/pallets/template",
"templates/parachain/pallets/xcnft",
"templates/parachain/runtime",
"templates/parachain_two/node",
"templates/parachain_two/pallets/template",
"templates/parachain_two/pallets/xcnft",
"templates/parachain_two/runtime",
"templates/solochain/node",
"templates/solochain/pallets/template",
Expand Down Expand Up @@ -687,6 +687,8 @@ collectives-westend-emulated-chain = { path = "cumulus/parachains/integration-te
collectives-westend-runtime = { path = "cumulus/parachains/runtimes/collectives/collectives-westend" }
color-eyre = { version = "0.6.3", default-features = false }
color-print = { version = "0.3.4" }
pallet-parachain-xcnft = { path = "templates/parachain/pallets/xcnft", default-features = false }
pallet-parachain-xcnft-two = { path = "templates/parachain_two/pallets/xcnft", default-features = false }
colored = { version = "2.0.4" }
comfy-table = { version = "7.1.0", default-features = false }
console = { version = "0.15.8" }
Expand Down Expand Up @@ -962,9 +964,7 @@ pallet-offences = { path = "substrate/frame/offences", default-features = false
pallet-offences-benchmarking = { path = "substrate/frame/offences/benchmarking", default-features = false }
pallet-paged-list = { path = "substrate/frame/paged-list", default-features = false }
pallet-parachain-template = { path = "templates/parachain/pallets/template", default-features = false }
pallet-parachain-xcnft = { path = "templates/parachain/pallets/xcnft", default-features = false }
pallet-parachain-template-two = {path = "templates/parachain_two/pallets/template", default-features = false }
pallet-parachain-xcnft-two = { path = "templates/parachain_two/pallets/xcnft", default-features = false }
pallet-parachain-template-two = { path = "templates/parachain_two/pallets/template", default-features = false }
pallet-parameters = { path = "substrate/frame/parameters", default-features = false }
pallet-preimage = { path = "substrate/frame/preimage", default-features = false }
pallet-proxy = { path = "substrate/frame/proxy", default-features = false }
Expand Down Expand Up @@ -1014,7 +1014,7 @@ pallet-xcm-bridge-hub = { path = "bridges/modules/xcm-bridge-hub", default-featu
pallet-xcm-bridge-hub-router = { path = "bridges/modules/xcm-bridge-hub-router", default-features = false }
parachain-info = { path = "cumulus/parachains/pallets/parachain-info", default-features = false, package = "staging-parachain-info" }
parachain-template-runtime = { path = "templates/parachain/runtime" }
parachain-template-runtime-two = { path = "templates/parachain_two/runtime"}
parachain-template-runtime-two = { path = "templates/parachain_two/runtime" }
parachains-common = { path = "cumulus/parachains/common", default-features = false }
parachains-relay = { path = "bridges/relays/parachains" }
parachains-runtimes-test-utils = { path = "cumulus/parachains/runtimes/test-utils", default-features = false }
Expand Down
25 changes: 0 additions & 25 deletions substrate/frame/nfts/src/common_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,31 +61,6 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
Ok(())
}

/// Returns item depositor
//pub fn item_depositor(collection: T::CollectionId, item: T::ItemId) -> Option<T::AccountId> {
// Item::<T, I>::get(collection, item).map(|i| i.deposit.account)
//}

/// Returns item deposit amount
//pub fn item_deposit(collection: T::CollectionId, item: T::ItemId) -> Option<DepositBalanceOf<T, I>>{
// Item::<T, I>::get(collection, item).map(|i| i.deposit.amount)
//}

/// Returns collection deposit
//pub fn deposit(collection: T::CollectionId) -> Option<DepositBalanceOf<T, I>>{
// Collection::<T, I>::get(collection).map(|i| i.owner_deposit)
//}

/// Returns collection data
//pub fn collection_data(collection: T::CollectionId) -> Option<BoundedVec<u8, <T as Config<I>>::StringLimit>> {
// CollectionMetadataOf::<T, I>::get(collection).map(|i| i.data)
//}

/// Returns item data
//pub fn item_data(collection: T::CollectionId, item: T::ItemId) -> Option<BoundedVec<u8, <T as Config<I>>::StringLimit>> {
// ItemMetadataOf::<T, I>::get(collection, item).map(|i| i.data)
//}

pub(crate) fn set_next_collection_id(collection: T::CollectionId) {
let next_id = collection.increment();
NextCollectionId::<T, I>::set(next_id);
Expand Down
3 changes: 1 addition & 2 deletions substrate/frame/nfts/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ pub type ApprovalsOf<T, I = ()> = BoundedBTreeMap<
pub type ItemAttributesApprovals<T, I = ()> =
BoundedBTreeSet<<T as SystemConfig>::AccountId, <T as Config<I>>::ItemAttributesApprovalsLimit>;
/// A type that holds the deposit for a single item.
pub type ItemDepositOf<T, I> =
ItemDeposit<DepositBalanceOf<T, I>, <T as SystemConfig>::AccountId>;
pub type ItemDepositOf<T, I> = ItemDeposit<DepositBalanceOf<T, I>, <T as SystemConfig>::AccountId>;
/// A type that holds the deposit amount for an item's attribute.
pub type AttributeDepositOf<T, I> =
AttributeDeposit<DepositBalanceOf<T, I>, <T as SystemConfig>::AccountId>;
Expand Down
2 changes: 1 addition & 1 deletion templates/parachain/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ runtime-benchmarks = [
try-runtime = [
"parachain-template-runtime/try-runtime",
"polkadot-sdk/try-runtime",
]
]
2 changes: 1 addition & 1 deletion templates/parachain/node/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ fn main() {
generate_cargo_keys();

rerun_if_git_head_changed();
}
}
1 change: 1 addition & 0 deletions templates/parachain/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

use polkadot_sdk::*;

use parachain_template_runtime as runtime;
Expand Down
2 changes: 1 addition & 1 deletion templates/parachain/node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@ impl RelayChainCli {
base: clap::Parser::parse_from(relay_chain_args),
}
}
}
}
1 change: 1 addition & 0 deletions templates/parachain/node/src/command.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

use polkadot_sdk::*;

use cumulus_client_service::storage_proof_size::HostFunctions as ReclaimHostFunctions;
Expand Down
2 changes: 1 addition & 1 deletion templates/parachain/node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ mod service;

fn main() -> sc_cli::Result<()> {
command::run()
}
}
2 changes: 1 addition & 1 deletion templates/parachain/node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ where
module.merge(System::new(client.clone(), pool).into_rpc())?;
module.merge(TransactionPayment::new(client).into_rpc())?;
Ok(module)
}
}
1 change: 1 addition & 0 deletions templates/parachain/node/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

//! Service and ServiceFactory implementation. Specialized wrapper over substrate service.
// std
Expand Down
47 changes: 38 additions & 9 deletions templates/parachain/pallets/template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,45 @@ publish = false
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { features = ["derive"], workspace = true }
scale-info = { features = ["derive"], workspace = true }
codec = { features = [
"derive",
], workspace = true }
scale-info = { features = [
"derive",
], workspace = true }

frame = { workspace = true, default-features = false, features = [
"experimental",
"runtime",
] }
# frame deps
frame-benchmarking = { optional = true, workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }

# primitive deps
sp-runtime = { workspace = true }

[dev-dependencies]
sp-core = { workspace = true, default-features = true }
sp-io = { workspace = true, default-features = true }

[features]
default = ["std"]
runtime-benchmarks = ["frame/runtime-benchmarks"]
std = ["codec/std", "frame/std", "scale-info/std"]
try-runtime = ["frame/try-runtime"]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
std = [
"codec/std",
"scale-info/std",

"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",

"sp-runtime/std",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"sp-runtime/try-runtime",
]
3 changes: 2 additions & 1 deletion templates/parachain/pallets/template/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! Benchmarking setup for pallet-template
#![cfg(feature = "runtime-benchmarks")]

use super::*;
use frame::{deps::frame_benchmarking::v2::*, prelude::*};
use frame_benchmarking::v2::*;

#[benchmarks]
mod benchmarks {
Expand Down
8 changes: 6 additions & 2 deletions templates/parachain/pallets/template/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,17 @@ mod benchmarking;
// To see a full list of `pallet` macros and their use cases, see:
// <https://paritytech.github.io/polkadot-sdk/master/pallet_example_kitchensink/index.html>
// <https://paritytech.github.io/polkadot-sdk/master/frame_support/pallet_macros/index.html>
#[frame::pallet]
#[frame_support::pallet]
pub mod pallet {
use frame::prelude::*;
use frame_support::{dispatch::DispatchResultWithPostInfo, pallet_prelude::*, DefaultNoBound};
use frame_system::pallet_prelude::*;
use sp_runtime::traits::{CheckedAdd, One};

/// 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.
/// <https://paritytech.github.io/polkadot-sdk/master/polkadot_sdk_docs/reference_docs/frame_runtime_types/index.html>
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;

/// A type representing the weights required by the dispatchables of this pallet.
Expand Down
15 changes: 6 additions & 9 deletions templates/parachain/pallets/template/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use frame::{
deps::{frame_support::weights::constants::RocksDbWeight, frame_system::GenesisConfig},
prelude::*,
runtime::prelude::*,
testing_prelude::*,
};
use frame_support::{derive_impl, weights::constants::RocksDbWeight};
use frame_system::{mocking::MockBlock, GenesisConfig};
use sp_runtime::{traits::ConstU64, BuildStorage};

// Configure a mock runtime to test the pallet.
#[frame_construct_runtime]
#[frame_support::runtime]
mod test_runtime {
#[runtime::runtime]
#[runtime::derive(
Expand All @@ -25,7 +22,7 @@ mod test_runtime {
#[runtime::pallet_index(0)]
pub type System = frame_system;
#[runtime::pallet_index(1)]
pub type Template = crate;
pub type TemplateModule = crate;
}

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
Expand All @@ -42,6 +39,6 @@ impl crate::Config for Test {
}

// Build genesis storage according to the mock runtime.
pub fn new_test_ext() -> TestState {
pub fn new_test_ext() -> sp_io::TestExternalities {
GenesisConfig::<Test>::default().build_storage().unwrap().into()
}
9 changes: 6 additions & 3 deletions templates/parachain/pallets/template/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::{mock::*, Error, Something};
use frame::testing_prelude::*;
use frame_support::{assert_noop, assert_ok};

#[test]
fn it_works_for_default_value() {
new_test_ext().execute_with(|| {
// Dispatch a signed extrinsic.
assert_ok!(Template::do_something(RuntimeOrigin::signed(1), 42));
assert_ok!(TemplateModule::do_something(RuntimeOrigin::signed(1), 42));
// Read pallet storage and assert an expected result.
assert_eq!(Something::<Test>::get().map(|v| v.block_number), Some(42));
});
Expand All @@ -15,6 +15,9 @@ fn it_works_for_default_value() {
fn correct_error_for_none_value() {
new_test_ext().execute_with(|| {
// Ensure the expected error is thrown when no value is present.
assert_noop!(Template::cause_error(RuntimeOrigin::signed(1)), Error::<Test>::NoneValue);
assert_noop!(
TemplateModule::cause_error(RuntimeOrigin::signed(1)),
Error::<Test>::NoneValue
);
});
}
18 changes: 9 additions & 9 deletions templates/parachain/pallets/template/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#![allow(unused_parens)]
#![allow(unused_imports)]

use frame::{deps::frame_support::weights::constants::RocksDbWeight, prelude::*};
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
use core::marker::PhantomData;

/// Weight functions needed for pallet_template.
Expand All @@ -41,8 +41,8 @@ pub trait WeightInfo {
/// Weights for pallet_template using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// Storage: Template Something (r:0 w:1)
/// Proof: Template Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
/// Storage: TemplateModule Something (r:0 w:1)
/// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
fn do_something() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
Expand All @@ -51,8 +51,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
Weight::from_parts(9_000_000, 0)
.saturating_add(T::DbWeight::get().writes(1_u64))
}
/// Storage: Template Something (r:1 w:1)
/// Proof: Template Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
/// Storage: TemplateModule Something (r:1 w:1)
/// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
fn cause_error() -> Weight {
// Proof Size summary in bytes:
// Measured: `32`
Expand All @@ -66,8 +66,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {

// For backwards compatibility and tests
impl WeightInfo for () {
/// Storage: Template Something (r:0 w:1)
/// Proof: Template Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
/// Storage: TemplateModule Something (r:0 w:1)
/// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
fn do_something() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
Expand All @@ -76,8 +76,8 @@ impl WeightInfo for () {
Weight::from_parts(9_000_000, 0)
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
/// Storage: Template Something (r:1 w:1)
/// Proof: Template Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
/// Storage: TemplateModule Something (r:1 w:1)
/// Proof: TemplateModule Something (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen)
fn cause_error() -> Weight {
// Proof Size summary in bytes:
// Measured: `32`
Expand Down
Loading

0 comments on commit 6004eb8

Please sign in to comment.