Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions node/parallel/src/chain_spec/heiko.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ use sp_runtime::{
FixedPointNumber,
};

use crate::chain_spec::{get_account_id_from_seed, get_authority_keys_from_seed, Extensions};
use crate::chain_spec::{
as_properties, get_account_id_from_seed, get_authority_keys_from_seed, Extensions,
};

/// Specialized `ChainSpec` for the normal parachain runtime.
pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig, Extensions>;
Expand Down Expand Up @@ -75,8 +77,8 @@ pub fn development_config(id: ParaId) -> ChainSpec {
},
vec![],
None,
None,
None,
Some("heiko-dev"),
Some(as_properties(network::NetworkType::Heiko)),
Extensions {
relay_chain: "rococo-local".into(),
para_id: id.into(),
Expand Down Expand Up @@ -168,8 +170,8 @@ pub fn local_testnet_config(id: ParaId) -> ChainSpec {
},
vec![],
None,
None,
None,
Some("heiko-local"),
Some(as_properties(network::NetworkType::Heiko)),
Extensions {
relay_chain: "kusama".into(),
para_id: id.into(),
Expand Down
33 changes: 32 additions & 1 deletion node/parallel/src/chain_spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,44 @@
pub mod heiko;
pub mod parallel;

use primitives::*;
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use sc_service::Properties;
use serde::{Deserialize, Serialize};
use serde_json::json;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::{sr25519, Pair, Public};
use sp_runtime::traits::IdentifyAccount;

use primitives::{network::NetworkType, *};

/// Token symbol of heiko network.
pub const HEIKO_TOKEN: &str = "HKO";
/// Token symbol of parallel network.
pub const PARALLEL_TOKEN: &str = "PARA";

/// Generate chain properties for network.
///
/// For fields definition, see https://github.com/polkadot-js/apps/blob/bd78840d2142df121d182e8700b20308880dde0a/packages/react-api/src/Api.tsx#L115
pub(crate) fn as_properties(network: NetworkType) -> Properties {
let (symbol, decimal) = token_info(&network);
json!({
"ss58Format": network.ss58_addr_format_id(),
"tokenSymbol": symbol,
"tokenDecimals": decimal,
})
.as_object()
.expect("Network properties are valid; qed")
.to_owned()
}

/// Return (token_symbol, token_decimal) of this network.
fn token_info(network: &NetworkType) -> (&str, u8) {
match network {
NetworkType::Heiko => (HEIKO_TOKEN, 12),
NetworkType::Parallel => (PARALLEL_TOKEN, 12),
}
}

/// Helper function to generate a crypto pair from seed
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
TPublic::Pair::from_string(&format!("//{}", seed), None)
Expand Down
14 changes: 8 additions & 6 deletions node/parallel/src/chain_spec/parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use parallel_runtime::{
SystemConfig, TechnicalCommitteeConfig, TokensConfig, ValidatorFeedersMembershipConfig,
VestingConfig, WASM_BINARY,
};
use primitives::*;
use primitives::{network::NetworkType, *};
use sc_service::ChainType;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::crypto::UncheckedInto;
Expand All @@ -32,7 +32,9 @@ use sp_runtime::{
FixedPointNumber,
};

use crate::chain_spec::{get_account_id_from_seed, get_authority_keys_from_seed, Extensions};
use crate::chain_spec::{
as_properties, get_account_id_from_seed, get_authority_keys_from_seed, Extensions,
};

/// Specialized `ChainSpec` for the normal parachain runtime.
pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig, Extensions>;
Expand Down Expand Up @@ -74,8 +76,8 @@ pub fn development_config(id: ParaId) -> ChainSpec {
},
vec![],
None,
None,
None,
Some("parallel-dev"),
Some(as_properties(NetworkType::Parallel)),
Extensions {
relay_chain: "rococo-local".into(),
para_id: id.into(),
Expand Down Expand Up @@ -167,8 +169,8 @@ pub fn local_testnet_config(id: ParaId) -> ChainSpec {
},
vec![],
None,
None,
None,
Some("parallel-local"),
Some(as_properties(NetworkType::Parallel)),
Extensions {
relay_chain: "polkadot".into(),
para_id: id.into(),
Expand Down
2 changes: 2 additions & 0 deletions primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#![allow(clippy::unnecessary_cast)]
#![allow(clippy::upper_case_acronyms)]

pub mod network;

use codec::{Decode, Encode};
use sp_runtime::{
traits::{CheckedDiv, IdentifyAccount, Verify},
Expand Down
24 changes: 24 additions & 0 deletions primitives/src/network.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
use sp_runtime::RuntimeDebug;

/// Network type for parallel.
#[derive(Clone, Copy, RuntimeDebug)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub enum NetworkType {
Parallel,
Heiko,
}

impl NetworkType {
/// Return ss58 address prefix from network type.
pub fn ss58_addr_format_id(&self) -> u8 {
match self {
NetworkType::Heiko => HEIKO_PREFIX,
NetworkType::Parallel => PARALLEL_PREFIX,
}
}
}

pub const HEIKO_PREFIX: u8 = 110;
pub const PARALLEL_PREFIX: u8 = 172;