Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 @@ -34,7 +34,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("dev"),
Comment thread
alannotnerd marked this conversation as resolved.
Outdated
Some(as_properties(network::NetworkType::Heiko)),
Extensions {
relay_chain: "rococo-local".into(),
para_id: id.into(),
Expand Down Expand Up @@ -161,8 +163,8 @@ pub fn local_testnet_config(id: ParaId) -> ChainSpec {
},
vec![],
None,
None,
None,
Some("dev"),
Comment thread
alannotnerd marked this conversation as resolved.
Outdated
Some(as_properties(network::NetworkType::Heiko)),
Extensions {
relay_chain: "kusama".into(),
para_id: id.into(),
Expand Down
20 changes: 19 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,31 @@
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, *};

/// 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) = network.token_info();
json!({
"ss58Format": network.ss58_addr_format_id(),
"tokenSymbol": symbol,
"tokenDecimals": decimal,
})
.as_object()
.expect("Network properties are valid; qed")
Comment thread
alannotnerd marked this conversation as resolved.
.to_owned()
}

/// 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 @@ -23,7 +23,7 @@ use parallel_runtime::{
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 @@ -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 @@ -73,8 +75,8 @@ pub fn development_config(id: ParaId) -> ChainSpec {
},
vec![],
None,
None,
None,
Some("dev"),
Comment thread
alannotnerd marked this conversation as resolved.
Outdated
Some(as_properties(NetworkType::Parallel)),
Extensions {
relay_chain: "rococo-local".into(),
para_id: id.into(),
Expand Down Expand Up @@ -160,8 +162,8 @@ pub fn local_testnet_config(id: ParaId) -> ChainSpec {
},
vec![],
None,
None,
None,
Some("dev"),
Comment thread
alannotnerd marked this conversation as resolved.
Outdated
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
37 changes: 37 additions & 0 deletions primitives/src/network.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use codec::{Decode, Encode};
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
use sp_runtime::RuntimeDebug;

/// Network type for parallel.
#[derive(PartialEq, Eq, Clone, Copy, Encode, Decode, RuntimeDebug)]
Comment thread
alannotnerd marked this conversation as resolved.
Outdated
#[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 => 110,
Comment thread
alannotnerd marked this conversation as resolved.
Outdated
NetworkType::Parallel => 172,
}
}

/// Return (token_symbol, token_decimal) of this network.
pub fn token_info(&self) -> (&str, u8) {
match self {
NetworkType::Heiko => (HEIKO_TOKEN, 12),
Comment thread
alannotnerd marked this conversation as resolved.
Outdated
NetworkType::Parallel => (PARALLEL_TOKEN, 12),
}
}
}

pub const HEIKO_PREFIX: u8 = 110;
pub const PARALLEL_PREFIX: u8 = 172;
/// Token symbol of heiko network.
pub const HEIKO_TOKEN: &str = "HKO";
/// Token symbol of parallel network.
pub const PARALLEL_TOKEN: &str = "PARA";
Comment thread
alannotnerd marked this conversation as resolved.
Outdated