Skip to content

Commit

Permalink
encapsulate properties object
Browse files Browse the repository at this point in the history
  • Loading branch information
herryho committed Dec 10, 2021
1 parent b66d8ed commit bab0bb7
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 174 deletions.
123 changes: 36 additions & 87 deletions node/service/src/chain_spec/asgard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use cumulus_primitives_core::ParaId;
use frame_benchmarking::{account, whitelisted_caller};
use hex_literal::hex;
use node_primitives::{CurrencyId, TokenInfo, TokenSymbol};
use sc_chain_spec::Properties;
use sc_service::ChainType;
use sc_telemetry::TelemetryEndpoints;
use sp_core::{crypto::UncheckedInto, sr25519};
Expand All @@ -43,6 +44,38 @@ pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig, RelayExtensions

const ENDOWMENT: u128 = 1_000_000 * DOLLARS;

fn asgard_properties() -> Properties {
let mut properties = sc_chain_spec::Properties::new();
let mut token_symbol: Vec<String> = vec![];
let mut token_decimals: Vec<u32> = vec![];
[
// native token
CurrencyId::Native(TokenSymbol::ASG),
// stable token
CurrencyId::Stable(TokenSymbol::KUSD),
// token
CurrencyId::Token(TokenSymbol::DOT),
CurrencyId::Token(TokenSymbol::KSM),
CurrencyId::Token(TokenSymbol::KAR),
CurrencyId::Token(TokenSymbol::ZLK),
CurrencyId::Token(TokenSymbol::PHA),
// vstoken
CurrencyId::VSToken(TokenSymbol::KSM),
CurrencyId::VSToken(TokenSymbol::DOT),
]
.iter()
.for_each(|token| {
token_symbol.push(token.symbol().to_string());
token_decimals.push(token.decimals() as u32);
});

properties.insert("tokenSymbol".into(), token_symbol.into());
properties.insert("tokenDecimals".into(), token_decimals.into());
properties.insert("ss58Format".into(), SS58Prefix::get().into());

properties
}

/// Helper function to create asgard GenesisConfig for testing
pub fn asgard_genesis(
invulnerables: Vec<(AccountId, AuraId)>,
Expand Down Expand Up @@ -169,34 +202,6 @@ fn development_config_genesis(id: ParaId) -> GenesisConfig {
}

pub fn development_config(id: ParaId) -> Result<ChainSpec, String> {
let mut properties = sc_chain_spec::Properties::new();
let mut token_symbol: Vec<String> = vec![];
let mut token_decimals: Vec<u32> = vec![];
[
// native token
CurrencyId::Native(TokenSymbol::ASG),
// stable token
CurrencyId::Stable(TokenSymbol::KUSD),
// token
CurrencyId::Token(TokenSymbol::DOT),
CurrencyId::Token(TokenSymbol::KSM),
CurrencyId::Token(TokenSymbol::KAR),
CurrencyId::Token(TokenSymbol::ZLK),
CurrencyId::Token(TokenSymbol::PHA),
// vstoken
CurrencyId::VSToken(TokenSymbol::KSM),
CurrencyId::VSToken(TokenSymbol::DOT),
]
.iter()
.for_each(|token| {
token_symbol.push(token.symbol().to_string());
token_decimals.push(token.decimals() as u32);
});

properties.insert("tokenSymbol".into(), token_symbol.into());
properties.insert("tokenDecimals".into(), token_decimals.into());
properties.insert("ss58Format".into(), SS58Prefix::get().into());

Ok(ChainSpec::from_genesis(
"Development",
"dev",
Expand All @@ -205,7 +210,7 @@ pub fn development_config(id: ParaId) -> Result<ChainSpec, String> {
vec![],
None,
Some(DEFAULT_PROTOCOL_ID),
Some(properties),
Some(asgard_properties()),
RelayExtensions { relay_chain: "westend-dev".into(), para_id: id.into() },
))
}
Expand Down Expand Up @@ -276,34 +281,6 @@ fn local_config_genesis(id: ParaId) -> GenesisConfig {
}

pub fn local_testnet_config(id: ParaId) -> Result<ChainSpec, String> {
let mut properties = sc_chain_spec::Properties::new();
let mut token_symbol: Vec<String> = vec![];
let mut token_decimals: Vec<u32> = vec![];
[
// native token
CurrencyId::Native(TokenSymbol::ASG),
// stable token
CurrencyId::Stable(TokenSymbol::KUSD),
// token
CurrencyId::Token(TokenSymbol::DOT),
CurrencyId::Token(TokenSymbol::KSM),
CurrencyId::Token(TokenSymbol::KAR),
CurrencyId::Token(TokenSymbol::ZLK),
CurrencyId::Token(TokenSymbol::PHA),
// vstoken
CurrencyId::VSToken(TokenSymbol::KSM),
CurrencyId::VSToken(TokenSymbol::DOT),
]
.iter()
.for_each(|token| {
token_symbol.push(token.symbol().to_string());
token_decimals.push(token.decimals() as u32);
});

properties.insert("tokenSymbol".into(), token_symbol.into());
properties.insert("tokenDecimals".into(), token_decimals.into());
properties.insert("ss58Format".into(), SS58Prefix::get().into());

Ok(ChainSpec::from_genesis(
"Asgard Local Testnet",
"asgard_local_testnet",
Expand All @@ -312,40 +289,12 @@ pub fn local_testnet_config(id: ParaId) -> Result<ChainSpec, String> {
vec![],
None,
Some(DEFAULT_PROTOCOL_ID),
Some(properties),
Some(asgard_properties()),
RelayExtensions { relay_chain: "westend-local".into(), para_id: id.into() },
))
}

pub fn chainspec_config(id: ParaId) -> ChainSpec {
let mut properties = sc_chain_spec::Properties::new();
let mut token_symbol: Vec<String> = vec![];
let mut token_decimals: Vec<u32> = vec![];
[
// native token
CurrencyId::Native(TokenSymbol::ASG),
// stable token
CurrencyId::Stable(TokenSymbol::KUSD),
// token
CurrencyId::Token(TokenSymbol::DOT),
CurrencyId::Token(TokenSymbol::KSM),
CurrencyId::Token(TokenSymbol::KAR),
CurrencyId::Token(TokenSymbol::ZLK),
CurrencyId::Token(TokenSymbol::PHA),
// vstoken
CurrencyId::VSToken(TokenSymbol::KSM),
CurrencyId::VSToken(TokenSymbol::DOT),
]
.iter()
.for_each(|token| {
token_symbol.push(token.symbol().to_string());
token_decimals.push(token.decimals() as u32);
});

properties.insert("tokenSymbol".into(), token_symbol.into());
properties.insert("tokenDecimals".into(), token_decimals.into());
properties.insert("ss58Format".into(), SS58Prefix::get().into());

ChainSpec::from_genesis(
"Bifrost Asgard CC4",
"asgard_testnet",
Expand All @@ -354,7 +303,7 @@ pub fn chainspec_config(id: ParaId) -> ChainSpec {
vec![],
TelemetryEndpoints::new(vec![(TELEMETRY_URL.into(), 0)]).ok(),
Some(DEFAULT_PROTOCOL_ID),
Some(properties),
Some(asgard_properties()),
RelayExtensions { relay_chain: "westend".into(), para_id: id.into() },
)
}
Expand Down
123 changes: 36 additions & 87 deletions node/service/src/chain_spec/bifrost_kusama.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use cumulus_primitives_core::ParaId;
use frame_benchmarking::{account, whitelisted_caller};
use hex_literal::hex;
use node_primitives::{CurrencyId, TokenInfo, TokenSymbol};
use sc_chain_spec::Properties;
use sc_service::ChainType;
use sc_telemetry::TelemetryEndpoints;
use serde::de::DeserializeOwned;
Expand All @@ -52,6 +53,38 @@ pub fn ENDOWMENT() -> u128 {
1_000_000 * dollar(CurrencyId::Native(TokenSymbol::BNC))
}

fn bifrost_properties() -> Properties {
let mut properties = sc_chain_spec::Properties::new();
let mut token_symbol: Vec<String> = vec![];
let mut token_decimals: Vec<u32> = vec![];
[
// native token
CurrencyId::Native(TokenSymbol::BNC),
// stable token
CurrencyId::Stable(TokenSymbol::KUSD),
// token
CurrencyId::Token(TokenSymbol::DOT),
CurrencyId::Token(TokenSymbol::KSM),
CurrencyId::Token(TokenSymbol::KAR),
CurrencyId::Token(TokenSymbol::ZLK),
CurrencyId::Token(TokenSymbol::PHA),
// vstoken
CurrencyId::VSToken(TokenSymbol::KSM),
CurrencyId::VSToken(TokenSymbol::DOT),
]
.iter()
.for_each(|token| {
token_symbol.push(token.symbol().to_string());
token_decimals.push(token.decimals() as u32);
});

properties.insert("tokenSymbol".into(), token_symbol.into());
properties.insert("tokenDecimals".into(), token_decimals.into());
properties.insert("ss58Format".into(), SS58Prefix::get().into());

properties
}

pub fn bifrost_genesis(
invulnerables: Vec<(AccountId, AuraId)>,
balances: Vec<(AccountId, Balance)>,
Expand Down Expand Up @@ -154,34 +187,6 @@ fn development_config_genesis(id: ParaId) -> GenesisConfig {
}

pub fn development_config(id: ParaId) -> Result<ChainSpec, String> {
let mut properties = sc_chain_spec::Properties::new();
let mut token_symbol: Vec<String> = vec![];
let mut token_decimals: Vec<u32> = vec![];
[
// native token
CurrencyId::Native(TokenSymbol::BNC),
// stable token
CurrencyId::Stable(TokenSymbol::KUSD),
// token
CurrencyId::Token(TokenSymbol::DOT),
CurrencyId::Token(TokenSymbol::KSM),
CurrencyId::Token(TokenSymbol::KAR),
CurrencyId::Token(TokenSymbol::ZLK),
CurrencyId::Token(TokenSymbol::PHA),
// vstoken
CurrencyId::VSToken(TokenSymbol::KSM),
CurrencyId::VSToken(TokenSymbol::DOT),
]
.iter()
.for_each(|token| {
token_symbol.push(token.symbol().to_string());
token_decimals.push(token.decimals() as u32);
});

properties.insert("tokenSymbol".into(), token_symbol.into());
properties.insert("tokenDecimals".into(), token_decimals.into());
properties.insert("ss58Format".into(), SS58Prefix::get().into());

Ok(ChainSpec::from_genesis(
"Bifrost Development",
"bifrost_dev",
Expand All @@ -190,7 +195,7 @@ pub fn development_config(id: ParaId) -> Result<ChainSpec, String> {
vec![],
None,
Some(DEFAULT_PROTOCOL_ID),
Some(properties),
Some(bifrost_properties()),
RelayExtensions { relay_chain: "kusama-dev".into(), para_id: id.into() },
))
}
Expand Down Expand Up @@ -262,34 +267,6 @@ fn local_config_genesis(id: ParaId) -> GenesisConfig {
}

pub fn local_testnet_config(id: ParaId) -> Result<ChainSpec, String> {
let mut properties = sc_chain_spec::Properties::new();
let mut token_symbol: Vec<String> = vec![];
let mut token_decimals: Vec<u32> = vec![];
[
// native token
CurrencyId::Native(TokenSymbol::BNC),
// stable token
CurrencyId::Stable(TokenSymbol::KUSD),
// token
CurrencyId::Token(TokenSymbol::DOT),
CurrencyId::Token(TokenSymbol::KSM),
CurrencyId::Token(TokenSymbol::KAR),
CurrencyId::Token(TokenSymbol::ZLK),
CurrencyId::Token(TokenSymbol::PHA),
// vstoken
CurrencyId::VSToken(TokenSymbol::KSM),
CurrencyId::VSToken(TokenSymbol::DOT),
]
.iter()
.for_each(|token| {
token_symbol.push(token.symbol().to_string());
token_decimals.push(token.decimals() as u32);
});

properties.insert("tokenSymbol".into(), token_symbol.into());
properties.insert("tokenDecimals".into(), token_decimals.into());
properties.insert("ss58Format".into(), SS58Prefix::get().into());

Ok(ChainSpec::from_genesis(
"Bifrost Local Testnet",
"bifrost_local_testnet",
Expand All @@ -298,40 +275,12 @@ pub fn local_testnet_config(id: ParaId) -> Result<ChainSpec, String> {
vec![],
None,
Some(DEFAULT_PROTOCOL_ID),
Some(properties),
Some(bifrost_properties()),
RelayExtensions { relay_chain: "kusama-local".into(), para_id: id.into() },
))
}

pub fn chainspec_config(id: ParaId) -> ChainSpec {
let mut properties = sc_chain_spec::Properties::new();
let mut token_symbol: Vec<String> = vec![];
let mut token_decimals: Vec<u32> = vec![];
[
// native token
CurrencyId::Native(TokenSymbol::BNC),
// stable token
CurrencyId::Stable(TokenSymbol::KUSD),
// token
CurrencyId::Token(TokenSymbol::DOT),
CurrencyId::Token(TokenSymbol::KSM),
CurrencyId::Token(TokenSymbol::KAR),
CurrencyId::Token(TokenSymbol::ZLK),
CurrencyId::Token(TokenSymbol::PHA),
// vstoken
CurrencyId::VSToken(TokenSymbol::KSM),
CurrencyId::VSToken(TokenSymbol::DOT),
]
.iter()
.for_each(|token| {
token_symbol.push(token.symbol().to_string());
token_decimals.push(token.decimals() as u32);
});

properties.insert("tokenSymbol".into(), token_symbol.into());
properties.insert("tokenDecimals".into(), token_decimals.into());
properties.insert("ss58Format".into(), SS58Prefix::get().into());

ChainSpec::from_genesis(
"Bifrost",
"bifrost",
Expand All @@ -340,7 +289,7 @@ pub fn chainspec_config(id: ParaId) -> ChainSpec {
vec![],
TelemetryEndpoints::new(vec![(TELEMETRY_URL.into(), 0)]).ok(),
Some(DEFAULT_PROTOCOL_ID),
Some(properties),
Some(bifrost_properties()),
RelayExtensions { relay_chain: "kusama".into(), para_id: id.into() },
)
}
Expand Down

0 comments on commit bab0bb7

Please sign in to comment.