difftreelog
feat sapphire runtime
in: master
5 files changed
node/cli/Cargo.tomldiffbeforeafterboth--- a/node/cli/Cargo.toml
+++ b/node/cli/Cargo.toml
@@ -335,3 +335,7 @@
'quartz-runtime?/try-runtime',
'opal-runtime?/try-runtime',
]
+sapphire-runtime = [
+ 'opal-runtime',
+ 'opal-runtime/become-sapphire',
+]
node/cli/src/chain_spec.rsdiffbeforeafterboth1// 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;5657pub enum RuntimeId {58 #[cfg(feature = "unique-runtime")]59 Unique,6061 #[cfg(feature = "quartz-runtime")]62 Quartz,6364 Opal,65 Unknown(String),66}6768#[cfg(not(feature = "unique-runtime"))]69/// PARA_ID for Opal/Quartz70const PARA_ID: u32 = 2095;7172#[cfg(feature = "unique-runtime")]73/// PARA_ID for Unique74const PARA_ID: u32 = 2037;7576pub trait RuntimeIdentification {77 fn runtime_id(&self) -> RuntimeId;78}7980impl RuntimeIdentification for Box<dyn sc_service::ChainSpec> {81 fn runtime_id(&self) -> RuntimeId {82 #[cfg(feature = "unique-runtime")]83 if self.id().starts_with("unique") || self.id().starts_with("unq") {84 return RuntimeId::Unique;85 }8687 #[cfg(feature = "quartz-runtime")]88 if self.id().starts_with("quartz") || self.id().starts_with("qtz") {89 return RuntimeId::Quartz;90 }9192 if self.id().starts_with("opal") || self.id() == "dev" || self.id() == "local_testnet" {93 return RuntimeId::Opal;94 }9596 RuntimeId::Unknown(self.id().into())97 }98}99100pub enum ServiceId {101 Prod,102 Dev,103}104105pub trait ServiceIdentification {106 fn service_id(&self) -> ServiceId;107}108109impl ServiceIdentification for Box<dyn sc_service::ChainSpec> {110 fn service_id(&self) -> ServiceId {111 if self.id().ends_with("dev") {112 ServiceId::Dev113 } else {114 ServiceId::Prod115 }116 }117}118119/// Helper function to generate a crypto pair from seed120pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {121 TPublic::Pair::from_string(&format!("//{}", seed), None)122 .expect("static values are valid; qed")123 .public()124}125126/// The extensions for the [`DefaultChainSpec`].127#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)]128#[serde(deny_unknown_fields)]129pub struct Extensions {130 /// The relay chain of the Parachain.131 pub relay_chain: String,132 /// The id of the Parachain.133 pub para_id: u32,134}135136impl Extensions {137 /// Try to get the extension from the given `ChainSpec`.138 pub fn try_get(chain_spec: &dyn sc_service::ChainSpec) -> Option<&Self> {139 sc_chain_spec::get_extension(chain_spec.extensions())140 }141}142143type AccountPublic = <Signature as Verify>::Signer;144145/// Helper function to generate an account ID from seed146pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId147where148 AccountPublic: From<<TPublic::Pair as Pair>::Public>,149{150 AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()151}152153macro_rules! testnet_genesis {154 (155 $runtime:path,156 $root_key:expr,157 $initial_authorities:expr,158 $endowed_accounts:expr,159 $id:expr160 ) => {{161 use $runtime::*;162163 GenesisConfig {164 system: SystemConfig {165 code: WASM_BINARY166 .expect("WASM binary was not build, please build it!")167 .to_vec(),168 },169 balances: BalancesConfig {170 balances: $endowed_accounts171 .iter()172 .cloned()173 // 1e13 UNQ174 .map(|k| (k, 1 << 100))175 .collect(),176 },177 treasury: Default::default(),178 tokens: TokensConfig { balances: vec![] },179 sudo: SudoConfig {180 key: Some($root_key),181 },182 vesting: VestingConfig { vesting: vec![] },183 parachain_info: ParachainInfoConfig {184 parachain_id: $id.into(),185 },186 parachain_system: Default::default(),187 aura: AuraConfig {188 authorities: $initial_authorities,189 },190 aura_ext: Default::default(),191 evm: EVMConfig {192 accounts: BTreeMap::new(),193 },194 ethereum: EthereumConfig {},195 }196 }};197}198199pub fn development_config() -> DefaultChainSpec {200 let mut properties = Map::new();201 properties.insert("tokenSymbol".into(), default_runtime::TOKEN_SYMBOL.into());202 properties.insert("tokenDecimals".into(), 18.into());203 properties.insert(204 "ss58Format".into(),205 default_runtime::SS58Prefix::get().into(),206 );207208 DefaultChainSpec::from_genesis(209 // Name210 format!(211 "{}{}",212 default_runtime::RUNTIME_NAME.to_uppercase(),213 if cfg!(feature = "unique-runtime") {214 ""215 } else {216 " by UNIQUE"217 }218 )219 .as_str(),220 // ID221 format!("{}_dev", default_runtime::RUNTIME_NAME).as_str(),222 ChainType::Local,223 move || {224 testnet_genesis!(225 default_runtime,226 // Sudo account227 get_account_id_from_seed::<sr25519::Public>("Alice"),228 vec![229 get_from_seed::<AuraId>("Alice"),230 get_from_seed::<AuraId>("Bob"),231 ],232 // Pre-funded accounts233 vec![234 get_account_id_from_seed::<sr25519::Public>("Alice"),235 get_account_id_from_seed::<sr25519::Public>("Bob"),236 get_account_id_from_seed::<sr25519::Public>("Charlie"),237 get_account_id_from_seed::<sr25519::Public>("Dave"),238 get_account_id_from_seed::<sr25519::Public>("Eve"),239 get_account_id_from_seed::<sr25519::Public>("Ferdie"),240 get_account_id_from_seed::<sr25519::Public>("Alice//stash"),241 get_account_id_from_seed::<sr25519::Public>("Bob//stash"),242 get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),243 get_account_id_from_seed::<sr25519::Public>("Dave//stash"),244 get_account_id_from_seed::<sr25519::Public>("Eve//stash"),245 get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),246 ],247 PARA_ID248 )249 },250 // Bootnodes251 vec![],252 // Telemetry253 None,254 // Protocol ID255 None,256 None,257 // Properties258 Some(properties),259 // Extensions260 Extensions {261 relay_chain: "rococo-dev".into(),262 para_id: PARA_ID,263 },264 )265}266267pub fn local_testnet_config() -> DefaultChainSpec {268 let mut properties = Map::new();269 properties.insert("tokenSymbol".into(), default_runtime::TOKEN_SYMBOL.into());270 properties.insert("tokenDecimals".into(), 18.into());271 properties.insert(272 "ss58Format".into(),273 default_runtime::SS58Prefix::get().into(),274 );275276 DefaultChainSpec::from_genesis(277 // Name278 format!(279 "{}{}",280 default_runtime::RUNTIME_NAME.to_uppercase(),281 if cfg!(feature = "unique-runtime") {282 ""283 } else {284 " by UNIQUE"285 }286 )287 .as_str(),288 // ID289 format!("{}_local", default_runtime::RUNTIME_NAME).as_str(),290 ChainType::Local,291 move || {292 testnet_genesis!(293 default_runtime,294 // Sudo account295 get_account_id_from_seed::<sr25519::Public>("Alice"),296 vec![297 get_from_seed::<AuraId>("Alice"),298 get_from_seed::<AuraId>("Bob"),299 ],300 // Pre-funded accounts301 vec![302 get_account_id_from_seed::<sr25519::Public>("Alice"),303 get_account_id_from_seed::<sr25519::Public>("Bob"),304 get_account_id_from_seed::<sr25519::Public>("Charlie"),305 get_account_id_from_seed::<sr25519::Public>("Dave"),306 get_account_id_from_seed::<sr25519::Public>("Eve"),307 get_account_id_from_seed::<sr25519::Public>("Ferdie"),308 get_account_id_from_seed::<sr25519::Public>("Alice//stash"),309 get_account_id_from_seed::<sr25519::Public>("Bob//stash"),310 get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),311 get_account_id_from_seed::<sr25519::Public>("Dave//stash"),312 get_account_id_from_seed::<sr25519::Public>("Eve//stash"),313 get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),314 ],315 PARA_ID316 )317 },318 // Bootnodes319 vec![],320 // Telemetry321 None,322 // Protocol ID323 None,324 None,325 // Properties326 Some(properties),327 // Extensions328 Extensions {329 relay_chain: "westend-local".into(),330 para_id: PARA_ID,331 },332 )333}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;5657pub enum RuntimeId {58 #[cfg(feature = "unique-runtime")]59 Unique,6061 #[cfg(feature = "quartz-runtime")]62 Quartz,6364 Opal,65 Unknown(String),66}6768#[cfg(not(feature = "unique-runtime"))]69/// PARA_ID for Opal/Sapphire/Quartz70const PARA_ID: u32 = 2095;7172#[cfg(feature = "unique-runtime")]73/// PARA_ID for Unique74const PARA_ID: u32 = 2037;7576pub trait RuntimeIdentification {77 fn runtime_id(&self) -> RuntimeId;78}7980impl RuntimeIdentification for Box<dyn sc_service::ChainSpec> {81 fn runtime_id(&self) -> RuntimeId {82 #[cfg(feature = "unique-runtime")]83 if self.id().starts_with("unique") || self.id().starts_with("unq") {84 return RuntimeId::Unique;85 }8687 #[cfg(feature = "quartz-runtime")]88 if self.id().starts_with("quartz") || self.id().starts_with("qtz") {89 return RuntimeId::Quartz;90 }9192 if self.id().starts_with("opal")93 || self.id().starts_with("sapphire")94 || self.id() == "dev"95 || self.id() == "local_testnet"96 {97 return RuntimeId::Opal;98 }99100 RuntimeId::Unknown(self.id().into())101 }102}103104pub enum ServiceId {105 Prod,106 Dev,107}108109pub trait ServiceIdentification {110 fn service_id(&self) -> ServiceId;111}112113impl ServiceIdentification for Box<dyn sc_service::ChainSpec> {114 fn service_id(&self) -> ServiceId {115 if self.id().ends_with("dev") {116 ServiceId::Dev117 } else {118 ServiceId::Prod119 }120 }121}122123/// Helper function to generate a crypto pair from seed124pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {125 TPublic::Pair::from_string(&format!("//{}", seed), None)126 .expect("static values are valid; qed")127 .public()128}129130/// The extensions for the [`DefaultChainSpec`].131#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)]132#[serde(deny_unknown_fields)]133pub struct Extensions {134 /// The relay chain of the Parachain.135 pub relay_chain: String,136 /// The id of the Parachain.137 pub para_id: u32,138}139140impl Extensions {141 /// Try to get the extension from the given `ChainSpec`.142 pub fn try_get(chain_spec: &dyn sc_service::ChainSpec) -> Option<&Self> {143 sc_chain_spec::get_extension(chain_spec.extensions())144 }145}146147type AccountPublic = <Signature as Verify>::Signer;148149/// Helper function to generate an account ID from seed150pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId151where152 AccountPublic: From<<TPublic::Pair as Pair>::Public>,153{154 AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()155}156157macro_rules! testnet_genesis {158 (159 $runtime:path,160 $root_key:expr,161 $initial_authorities:expr,162 $endowed_accounts:expr,163 $id:expr164 ) => {{165 use $runtime::*;166167 GenesisConfig {168 system: SystemConfig {169 code: WASM_BINARY170 .expect("WASM binary was not build, please build it!")171 .to_vec(),172 },173 balances: BalancesConfig {174 balances: $endowed_accounts175 .iter()176 .cloned()177 // 1e13 UNQ178 .map(|k| (k, 1 << 100))179 .collect(),180 },181 treasury: Default::default(),182 tokens: TokensConfig { balances: vec![] },183 sudo: SudoConfig {184 key: Some($root_key),185 },186 vesting: VestingConfig { vesting: vec![] },187 parachain_info: ParachainInfoConfig {188 parachain_id: $id.into(),189 },190 parachain_system: Default::default(),191 aura: AuraConfig {192 authorities: $initial_authorities,193 },194 aura_ext: Default::default(),195 evm: EVMConfig {196 accounts: BTreeMap::new(),197 },198 ethereum: EthereumConfig {},199 }200 }};201}202203pub fn development_config() -> DefaultChainSpec {204 let mut properties = Map::new();205 properties.insert("tokenSymbol".into(), default_runtime::TOKEN_SYMBOL.into());206 properties.insert("tokenDecimals".into(), 18.into());207 properties.insert(208 "ss58Format".into(),209 default_runtime::SS58Prefix::get().into(),210 );211212 DefaultChainSpec::from_genesis(213 // Name214 format!(215 "{}{}",216 default_runtime::RUNTIME_NAME.to_uppercase(),217 if cfg!(feature = "unique-runtime") {218 ""219 } else {220 " by UNIQUE"221 }222 )223 .as_str(),224 // ID225 format!("{}_dev", default_runtime::RUNTIME_NAME).as_str(),226 ChainType::Local,227 move || {228 testnet_genesis!(229 default_runtime,230 // Sudo account231 get_account_id_from_seed::<sr25519::Public>("Alice"),232 vec![233 get_from_seed::<AuraId>("Alice"),234 get_from_seed::<AuraId>("Bob"),235 ],236 // Pre-funded accounts237 vec![238 get_account_id_from_seed::<sr25519::Public>("Alice"),239 get_account_id_from_seed::<sr25519::Public>("Bob"),240 get_account_id_from_seed::<sr25519::Public>("Charlie"),241 get_account_id_from_seed::<sr25519::Public>("Dave"),242 get_account_id_from_seed::<sr25519::Public>("Eve"),243 get_account_id_from_seed::<sr25519::Public>("Ferdie"),244 get_account_id_from_seed::<sr25519::Public>("Alice//stash"),245 get_account_id_from_seed::<sr25519::Public>("Bob//stash"),246 get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),247 get_account_id_from_seed::<sr25519::Public>("Dave//stash"),248 get_account_id_from_seed::<sr25519::Public>("Eve//stash"),249 get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),250 ],251 PARA_ID252 )253 },254 // Bootnodes255 vec![],256 // Telemetry257 None,258 // Protocol ID259 None,260 None,261 // Properties262 Some(properties),263 // Extensions264 Extensions {265 relay_chain: "rococo-dev".into(),266 para_id: PARA_ID,267 },268 )269}270271pub fn local_testnet_config() -> DefaultChainSpec {272 let mut properties = Map::new();273 properties.insert("tokenSymbol".into(), default_runtime::TOKEN_SYMBOL.into());274 properties.insert("tokenDecimals".into(), 18.into());275 properties.insert(276 "ss58Format".into(),277 default_runtime::SS58Prefix::get().into(),278 );279280 DefaultChainSpec::from_genesis(281 // Name282 format!(283 "{}{}",284 default_runtime::RUNTIME_NAME.to_uppercase(),285 if cfg!(feature = "unique-runtime") {286 ""287 } else {288 " by UNIQUE"289 }290 )291 .as_str(),292 // ID293 format!("{}_local", default_runtime::RUNTIME_NAME).as_str(),294 ChainType::Local,295 move || {296 testnet_genesis!(297 default_runtime,298 // Sudo account299 get_account_id_from_seed::<sr25519::Public>("Alice"),300 vec![301 get_from_seed::<AuraId>("Alice"),302 get_from_seed::<AuraId>("Bob"),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: "westend-local".into(),334 para_id: PARA_ID,335 },336 )337}node/cli/src/cli.rsdiffbeforeafterboth--- a/node/cli/src/cli.rs
+++ b/node/cli/src/cli.rs
@@ -101,6 +101,8 @@
"Unique"
} else if cfg!(feature = "quartz-runtime") {
"Quartz"
+ } else if cfg!(feature = "sapphire-runtime") {
+ "Sapphire"
} else {
"Opal"
}
runtime/opal/Cargo.tomldiffbeforeafterboth--- a/runtime/opal/Cargo.toml
+++ b/runtime/opal/Cargo.toml
@@ -181,6 +181,7 @@
'foreign-assets',
'pallet-test-utils',
]
+become-sapphire = []
refungible = []
scheduler = []
runtime/opal/src/lib.rsdiffbeforeafterboth--- a/runtime/opal/src/lib.rs
+++ b/runtime/opal/src/lib.rs
@@ -42,7 +42,14 @@
pub use runtime_common::*;
+#[cfg(feature = "become-sapphire")]
+pub const RUNTIME_NAME: &str = "sapphire";
+#[cfg(feature = "become-sapphire")]
+pub const TOKEN_SYMBOL: &str = "QTZ";
+
+#[cfg(not(feature = "become-sapphire"))]
pub const RUNTIME_NAME: &str = "opal";
+#[cfg(not(feature = "become-sapphire"))]
pub const TOKEN_SYMBOL: &str = "OPL";
/// This runtime version.
@@ -59,7 +66,16 @@
parameter_types! {
pub const Version: RuntimeVersion = VERSION;
- pub const SS58Prefix: u8 = 42;
+}
+#[cfg(feature = "become-sapphire")]
+parameter_types! {
+ pub const SS58Prefix: u16 = 8883;
+ pub const ChainId: u64 = 8883;
+}
+
+#[cfg(not(feature = "become-sapphire"))]
+parameter_types! {
+ pub const SS58Prefix: u16 = 42;
pub const ChainId: u64 = 8882;
}