Skip to content

Commit

Permalink
Add psc genesis file
Browse files Browse the repository at this point in the history
  • Loading branch information
icodezjb committed Dec 27, 2022
1 parent bb6e17c commit 5054e9c
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 38 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ log = "0.4.17"
codec = { package = "parity-scale-codec", version = "3.0.0" }
serde = { version = "1.0.145", features = ["derive"] }
jsonrpsee = { version = "0.15.1", features = ["server"] }
hex-literal = "0.3.4"

# Local
psc-runtime = { path = "../runtime/psc" }
Expand Down
58 changes: 22 additions & 36 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use cumulus_primitives_core::ParaId;
use hex_literal::hex;
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use sc_service::{ChainType, config::TelemetryEndpoints};
use serde::{Deserialize, Serialize};
use sp_core::{Pair, Public, sr25519, crypto::UncheckedInto};
use sp_runtime::traits::{IdentifyAccount, Verify};

use psc_runtime::{
common::{AccountId, AuraId, Balance, Signature},
constants::currency::EXISTENTIAL_DEPOSIT,
};
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use sc_service::{config::TelemetryEndpoints, ChainType};
use serde::{Deserialize, Serialize};
use sp_core::{sr25519, Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};

const POLKADOT_PARA_ID: u32 = 2053;
const DEFAULT_PROTOCOL_ID: &str = "psc_polkadot";
Expand Down Expand Up @@ -70,8 +72,8 @@ pub fn get_collator_keys_from_seed(seed: &str) -> AuraId {

/// Helper function to generate an account ID from seed
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
where
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
where
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
{
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
}
Expand Down Expand Up @@ -138,7 +140,7 @@ pub fn development_config() -> ChainSpec {
"dev",
ChainType::Development,
move || {
testnet_genesis(
psc_genesis(
// initial collators.
vec![
(
Expand Down Expand Up @@ -183,47 +185,31 @@ pub fn development_config() -> ChainSpec {
)
}

pub fn local_testnet_config() -> ChainSpec {
pub fn psc_config() -> ChainSpec {
let mut properties = sc_chain_spec::Properties::new();
properties.insert("ss58Format".into(), 0.into());
properties.insert("tokenSymbol".into(), "DOT".into());
properties.insert("tokenDecimals".into(), 10.into());

ChainSpec::from_genesis(
// Name
"Local Testnet",
"Polkadot Smart Chain",
// ID
"local_testnet",
ChainType::Local,
"psc",
ChainType::Live,
move || {
testnet_genesis(
psc_genesis(
// initial collators.
vec![
(
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_collator_keys_from_seed("Alice"),
),
(
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_collator_keys_from_seed("Bob"),
// 135jgXDi2HPt8KDmHrxLz44sNzNg1Dp3dcWmkmeQMaY9M8he
hex!("5c15207d5d764cc633fc7c29da559a1efc8a4369ce7868daeaf8844c6fc68739").into(),
hex!("ac0d16845456daf555c0102297f6337e52e600d879497610eb0ccf5c7e09485b").unchecked_into(),
),
],
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_account_id_from_seed::<sr25519::Public>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
],
vec![],
POLKADOT_PARA_ID.into(),
get_account_id_from_seed::<sr25519::Public>("Alice"),
hex!("5c15207d5d764cc633fc7c29da559a1efc8a4369ce7868daeaf8844c6fc68739").into(),
)
},
// Bootnodes
Expand All @@ -241,13 +227,13 @@ pub fn local_testnet_config() -> ChainSpec {
Some(properties),
// Extensions
Extensions {
relay_chain: "rococo-local".into(), // You MUST set this to the correct network!
relay_chain: "polkadot".into(), // You MUST set this to the correct network!
para_id: POLKADOT_PARA_ID,
},
)
}

fn testnet_genesis(
fn psc_genesis(
invulnerables: Vec<(AccountId, AuraId)>,
endowed_accounts: Vec<AccountId>,
id: ParaId,
Expand Down
6 changes: 4 additions & 2 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ use crate::{
fn load_spec(id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
Ok(match id {
"dev" => Box::new(chain_spec::development_config()),
"template-rococo" => Box::new(chain_spec::local_testnet_config()),
"" | "local" => Box::new(chain_spec::local_testnet_config()),
"genesis" => Box::new(chain_spec::psc_config()),
"" => Box::new(chain_spec::ChainSpec::from_json_bytes(
&include_bytes!("./res/psc-raw.json")[..],
)?),
path => Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?),
})
}
Expand Down
1 change: 1 addition & 0 deletions node/src/res/2053-genesis-state
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x0000000000000000000000000000000000000000000000000000000000000000008b8e48dd2d65498594225f09c33eac6c8dea101b4258503b00066039afc3f5a503170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c11131400
1 change: 1 addition & 0 deletions node/src/res/2053-genesis-wasm

Large diffs are not rendered by default.

105 changes: 105 additions & 0 deletions node/src/res/psc-raw.json

Large diffs are not rendered by default.

0 comments on commit 5054e9c

Please sign in to comment.