git.delta.rocks / unique-network / refs/commits / 81e4404a75c5

difftreelog

feat(pallet nft) added GenesisConfig

PraetorP2023-04-20parent: #fb505f1.patch.diff
in: master

3 files changed

modifiednode/cli/src/chain_spec.rsdiffbeforeafterboth
before · node/cli/src/chain_spec.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};18use sc_service::ChainType;19use sp_core::{sr25519, Pair, Public};20use sp_runtime::traits::{IdentifyAccount, Verify};21use std::collections::BTreeMap;2223use serde::{Deserialize, Serialize};24use serde_json::map::Map;2526use up_common::types::opaque::*;2728#[cfg(feature = "unique-runtime")]29pub use unique_runtime as default_runtime;3031#[cfg(all(not(feature = "unique-runtime"), feature = "quartz-runtime"))]32pub use quartz_runtime as default_runtime;3334#[cfg(all(not(feature = "unique-runtime"), not(feature = "quartz-runtime")))]35pub use opal_runtime as default_runtime;3637/// The `ChainSpec` parameterized for the unique runtime.38#[cfg(feature = "unique-runtime")]39pub type UniqueChainSpec = sc_service::GenericChainSpec<unique_runtime::GenesisConfig, Extensions>;4041/// The `ChainSpec` parameterized for the quartz runtime.42#[cfg(feature = "quartz-runtime")]43pub type QuartzChainSpec = sc_service::GenericChainSpec<quartz_runtime::GenesisConfig, Extensions>;4445/// The `ChainSpec` parameterized for the opal runtime.46pub type OpalChainSpec = sc_service::GenericChainSpec<opal_runtime::GenesisConfig, Extensions>;4748#[cfg(feature = "unique-runtime")]49pub type DefaultChainSpec = UniqueChainSpec;5051#[cfg(all(not(feature = "unique-runtime"), feature = "quartz-runtime"))]52pub type DefaultChainSpec = QuartzChainSpec;5354#[cfg(all(not(feature = "unique-runtime"), not(feature = "quartz-runtime")))]55pub type DefaultChainSpec = OpalChainSpec;5657#[cfg(not(feature = "unique-runtime"))]58/// PARA_ID for Opal/Sapphire/Quartz59const PARA_ID: u32 = 2095;6061#[cfg(feature = "unique-runtime")]62/// PARA_ID for Unique63const PARA_ID: u32 = 2037;6465pub trait RuntimeIdentification {66	fn runtime_id(&self) -> RuntimeId;67}6869impl RuntimeIdentification for Box<dyn sc_service::ChainSpec> {70	fn runtime_id(&self) -> RuntimeId {71		#[cfg(feature = "unique-runtime")]72		if self.id().starts_with("unique") || self.id().starts_with("unq") {73			return RuntimeId::Unique;74		}7576		#[cfg(feature = "quartz-runtime")]77		if self.id().starts_with("quartz")78			|| self.id().starts_with("qtz")79			|| self.id().starts_with("sapphire")80		{81			return RuntimeId::Quartz;82		}8384		if self.id().starts_with("opal") || self.id() == "dev" || self.id() == "local_testnet" {85			return RuntimeId::Opal;86		}8788		RuntimeId::Unknown(self.id().into())89	}90}9192pub enum ServiceId {93	Prod,94	Dev,95}9697pub trait ServiceIdentification {98	fn service_id(&self) -> ServiceId;99}100101impl ServiceIdentification for Box<dyn sc_service::ChainSpec> {102	fn service_id(&self) -> ServiceId {103		if self.id().ends_with("dev") {104			ServiceId::Dev105		} else {106			ServiceId::Prod107		}108	}109}110111/// Helper function to generate a crypto pair from seed112pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {113	TPublic::Pair::from_string(&format!("//{}", seed), None)114		.expect("static values are valid; qed")115		.public()116}117118/// The extensions for the [`DefaultChainSpec`].119#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)]120#[serde(deny_unknown_fields)]121pub struct Extensions {122	/// The relay chain of the Parachain.123	pub relay_chain: String,124	/// The id of the Parachain.125	pub para_id: u32,126}127128impl Extensions {129	/// Try to get the extension from the given `ChainSpec`.130	pub fn try_get(chain_spec: &dyn sc_service::ChainSpec) -> Option<&Self> {131		sc_chain_spec::get_extension(chain_spec.extensions())132	}133}134135type AccountPublic = <Signature as Verify>::Signer;136137/// Helper function to generate an account ID from seed138pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId139where140	AccountPublic: From<<TPublic::Pair as Pair>::Public>,141{142	AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()143}144145#[cfg(not(feature = "unique-runtime"))]146macro_rules! testnet_genesis {147	(148		$runtime:path,149		$root_key:expr,150		$initial_invulnerables:expr,151		$endowed_accounts:expr,152		$id:expr153	) => {{154		use $runtime::*;155156		GenesisConfig {157			system: SystemConfig {158				code: WASM_BINARY159					.expect("WASM binary was not build, please build it!")160					.to_vec(),161			},162			balances: BalancesConfig {163				balances: $endowed_accounts164					.iter()165					.cloned()166					// 1e13 UNQ167					.map(|k| (k, 1 << 100))168					.collect(),169			},170			common: Default::default(),171			treasury: Default::default(),172			tokens: TokensConfig { balances: vec![] },173			sudo: SudoConfig {174				key: Some($root_key),175			},176			vesting: VestingConfig { vesting: vec![] },177			parachain_info: ParachainInfoConfig {178				parachain_id: $id.into(),179			},180			parachain_system: Default::default(),181			collator_selection: CollatorSelectionConfig {182				invulnerables: $initial_invulnerables183					.iter()184					.cloned()185					.map(|(acc, _)| acc)186					.collect(),187			},188			session: SessionConfig {189				keys: $initial_invulnerables190					.into_iter()191					.map(|(acc, aura)| {192						(193							acc.clone(),          // account id194							acc,                  // validator id195							SessionKeys { aura }, // session keys196						)197					})198					.collect(),199			},200			aura: Default::default(),201			aura_ext: Default::default(),202			evm: EVMConfig {203				accounts: BTreeMap::new(),204			},205			ethereum: EthereumConfig {},206			polkadot_xcm: Default::default(),207			transaction_payment: Default::default(),208		}209	}};210}211212#[cfg(feature = "unique-runtime")]213macro_rules! testnet_genesis {214	(215		$runtime:path,216		$root_key:expr,217		$initial_invulnerables:expr,218		$endowed_accounts:expr,219		$id:expr220	) => {{221		use $runtime::*;222223		GenesisConfig {224			system: SystemConfig {225				code: WASM_BINARY226					.expect("WASM binary was not build, please build it!")227					.to_vec(),228			},229			common: Default::default(),230			balances: BalancesConfig {231				balances: $endowed_accounts232					.iter()233					.cloned()234					// 1e13 UNQ235					.map(|k| (k, 1 << 100))236					.collect(),237			},238			treasury: Default::default(),239			tokens: TokensConfig { balances: vec![] },240			sudo: SudoConfig {241				key: Some($root_key),242			},243			vesting: VestingConfig { vesting: vec![] },244			parachain_info: ParachainInfoConfig {245				parachain_id: $id.into(),246			},247			parachain_system: Default::default(),248			aura: AuraConfig {249				authorities: $initial_invulnerables250					.into_iter()251					.map(|(_, aura)| aura)252					.collect(),253			},254			aura_ext: Default::default(),255			evm: EVMConfig {256				accounts: BTreeMap::new(),257			},258			ethereum: EthereumConfig {},259			polkadot_xcm: Default::default(),260			transaction_payment: Default::default(),261		}262	}};263}264265pub fn development_config() -> DefaultChainSpec {266	let mut properties = Map::new();267	properties.insert("tokenSymbol".into(), default_runtime::TOKEN_SYMBOL.into());268	properties.insert("tokenDecimals".into(), 18.into());269	properties.insert(270		"ss58Format".into(),271		default_runtime::SS58Prefix::get().into(),272	);273274	DefaultChainSpec::from_genesis(275		// Name276		format!(277			"{}{}",278			default_runtime::RUNTIME_NAME.to_uppercase(),279			if cfg!(feature = "unique-runtime") {280				""281			} else {282				" by UNIQUE"283			}284		)285		.as_str(),286		// ID287		format!("{}_dev", default_runtime::RUNTIME_NAME).as_str(),288		ChainType::Local,289		move || {290			testnet_genesis!(291				default_runtime,292				// Sudo account293				get_account_id_from_seed::<sr25519::Public>("Alice"),294				vec![295					(296						get_account_id_from_seed::<sr25519::Public>("Alice"),297						get_from_seed::<AuraId>("Alice"),298					),299					(300						get_account_id_from_seed::<sr25519::Public>("Bob"),301						get_from_seed::<AuraId>("Bob"),302					),303				],304				// Pre-funded accounts305				vec![306					get_account_id_from_seed::<sr25519::Public>("Alice"),307					get_account_id_from_seed::<sr25519::Public>("Bob"),308					get_account_id_from_seed::<sr25519::Public>("Charlie"),309					get_account_id_from_seed::<sr25519::Public>("Dave"),310					get_account_id_from_seed::<sr25519::Public>("Eve"),311					get_account_id_from_seed::<sr25519::Public>("Ferdie"),312					get_account_id_from_seed::<sr25519::Public>("Alice//stash"),313					get_account_id_from_seed::<sr25519::Public>("Bob//stash"),314					get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),315					get_account_id_from_seed::<sr25519::Public>("Dave//stash"),316					get_account_id_from_seed::<sr25519::Public>("Eve//stash"),317					get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),318				],319				PARA_ID320			)321		},322		// Bootnodes323		vec![],324		// Telemetry325		None,326		// Protocol ID327		None,328		None,329		// Properties330		Some(properties),331		// Extensions332		Extensions {333			relay_chain: "rococo-dev".into(),334			para_id: PARA_ID,335		},336	)337}338339pub fn local_testnet_config() -> DefaultChainSpec {340	let mut properties = Map::new();341	properties.insert("tokenSymbol".into(), default_runtime::TOKEN_SYMBOL.into());342	properties.insert("tokenDecimals".into(), 18.into());343	properties.insert(344		"ss58Format".into(),345		default_runtime::SS58Prefix::get().into(),346	);347348	DefaultChainSpec::from_genesis(349		// Name350		format!(351			"{}{}",352			default_runtime::RUNTIME_NAME.to_uppercase(),353			if cfg!(feature = "unique-runtime") {354				""355			} else {356				" by UNIQUE"357			}358		)359		.as_str(),360		// ID361		format!("{}_local", default_runtime::RUNTIME_NAME).as_str(),362		ChainType::Local,363		move || {364			testnet_genesis!(365				default_runtime,366				// Sudo account367				get_account_id_from_seed::<sr25519::Public>("Alice"),368				vec![369					(370						get_account_id_from_seed::<sr25519::Public>("Alice"),371						get_from_seed::<AuraId>("Alice"),372					),373					(374						get_account_id_from_seed::<sr25519::Public>("Bob"),375						get_from_seed::<AuraId>("Bob"),376					),377				],378				// Pre-funded accounts379				vec![380					get_account_id_from_seed::<sr25519::Public>("Alice"),381					get_account_id_from_seed::<sr25519::Public>("Bob"),382					get_account_id_from_seed::<sr25519::Public>("Charlie"),383					get_account_id_from_seed::<sr25519::Public>("Dave"),384					get_account_id_from_seed::<sr25519::Public>("Eve"),385					get_account_id_from_seed::<sr25519::Public>("Ferdie"),386					get_account_id_from_seed::<sr25519::Public>("Alice//stash"),387					get_account_id_from_seed::<sr25519::Public>("Bob//stash"),388					get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),389					get_account_id_from_seed::<sr25519::Public>("Dave//stash"),390					get_account_id_from_seed::<sr25519::Public>("Eve//stash"),391					get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),392				],393				PARA_ID394			)395		},396		// Bootnodes397		vec![],398		// Telemetry399		None,400		// Protocol ID401		None,402		None,403		// Properties404		Some(properties),405		// Extensions406		Extensions {407			relay_chain: "westend-local".into(),408			para_id: PARA_ID,409		},410	)411}
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -496,6 +496,7 @@
 			StorageVersion::new(1).put::<Pallet<T>>();
 		}
 	}
+
 	impl<T: Config> Pallet<T> {
 		/// Helper function that handles deposit events
 		pub fn deposit_event(event: Event<T>) {
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -281,6 +281,23 @@
 		Value = bool,
 		QueryKind = ValueQuery,
 	>;
+
+	#[pallet::genesis_config]
+	pub struct GenesisConfig<T>(PhantomData<T>);
+
+	#[cfg(feature = "std")]
+	impl<T: Config> Default for GenesisConfig<T> {
+		fn default() -> Self {
+			Self(Default::default())
+		}
+	}
+
+	#[pallet::genesis_build]
+	impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
+		fn build(&self) {
+			StorageVersion::new(1).put::<Pallet<T>>();
+		}
+	}
 }
 
 pub struct NonfungibleHandle<T: Config>(pallet_common::CollectionHandle<T>);