From 45cbd966c2b31b366f4fd2df34e1cc0863d03bad Mon Sep 17 00:00:00 2001 From: AlphaGamingArcade Date: Wed, 11 Dec 2024 13:18:03 +0800 Subject: [PATCH] add aga testnet config --- node/src/chain_spec.rs | 64 +++++++++++++++++++++++++++++++++++++++--- node/src/command.rs | 2 +- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index bee9e89..97b71c6 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -2,8 +2,10 @@ use aga_runtime::{AccountId, RuntimeGenesisConfig, Signature, WASM_BINARY, Balan use sc_service::ChainType; use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_consensus_grandpa::AuthorityId as GrandpaId; -use sp_core::{sr25519, Pair, Public}; +use sp_core::{ed25519, sr25519, Pair, Public}; use sp_runtime::traits::{IdentifyAccount, Verify}; +use std::str::FromStr; +use serde_json::json; // The URL for the telemetry server. // const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; @@ -11,9 +13,9 @@ use sp_runtime::traits::{IdentifyAccount, Verify}; /// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type. pub type ChainSpec = sc_service::GenericChainSpec; -pub fn aga_config() -> Result { - ChainSpec::from_json_bytes(&include_bytes!("../../resources/aga-chain-spec-raw.json")[..]) -} +// pub fn aga_config() -> Result { +// ChainSpec::from_json_bytes(&include_bytes!("../../resources/aga-chain-spec-raw.json")[..]) +// } /// Generate a crypto pair from seed. pub fn get_from_seed(seed: &str) -> ::Public { @@ -57,6 +59,7 @@ pub fn development_config() -> Result { .with_name("Development") .with_id("dev") .with_chain_type(ChainType::Development) + .with_protocol_id("aga") .with_genesis_config_patch(testnet_genesis( // Initial PoA authorities vec![authority_keys_from_seed("Alice")], @@ -71,6 +74,7 @@ pub fn development_config() -> Result { ], true, )) + .with_properties(default_properties()) .build()) } @@ -82,6 +86,7 @@ pub fn local_testnet_config() -> Result { .with_name("Local Testnet") .with_id("local_testnet") .with_chain_type(ChainType::Local) + .with_protocol_id("aga") .with_genesis_config_patch(testnet_genesis( // Initial PoA authorities vec![authority_keys_from_seed("Alice"), authority_keys_from_seed("Bob")], @@ -104,6 +109,50 @@ pub fn local_testnet_config() -> Result { ], true, )) + .with_properties(default_properties()) + .build()) +} + +pub fn aga_testnet_config() -> Result { + const ROOT_PUBLIC_SR25519: &str = "5HTjThDzsZuY7neTGTZrgJGKADHjyW9R4W3emZYJwZPa91gS"; + + const NODE1_PUBLIC_SR25519: &str = "5GNJEdcdXmMyN7c95ZbeWtJsiZoSv7kVVVDvxfA5TnL7qA9k"; + const NODE1_PUBLIC_ED25519: &str = "5F7wpC4yLPC5pymEDKwSvmkfuqbKLFdwB9qbg8E4UEvqkoBE"; + + const NODE2_PUBLIC_SR25519: &str = "5H9Pr92kVX4wAmuuAEbVHHoDnccF4jZthaTcrfrYR2Q8Yh1u"; + const NODE2_PUBLIC_ED25519: &str = "5DJxo9qjo7o5Ses674Pe7aVojDqtWLYH4D5d8K5JmEoShDri"; + + Ok(ChainSpec::builder( + WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?, + None, + ) + .with_name("Aga Testnet") + .with_id("aga_testnet") + .with_chain_type(ChainType::Live) + .with_protocol_id("aga") + .with_genesis_config_patch(testnet_genesis( + // Initial PoA authorities + vec![ + ( + AccountId::from_str(NODE1_PUBLIC_SR25519).unwrap(), + AuraId::from(sr25519::Public::from_str(NODE1_PUBLIC_SR25519).unwrap()), + GrandpaId::from(ed25519::Public::from_str(NODE1_PUBLIC_ED25519).unwrap()), + ), + ( + AccountId::from_str(NODE2_PUBLIC_SR25519).unwrap(), + AuraId::from(sr25519::Public::from_str(NODE2_PUBLIC_SR25519).unwrap()), + GrandpaId::from(ed25519::Public::from_str(NODE2_PUBLIC_ED25519).unwrap()), + ) + ], + // Sudo account + AccountId::from_str(ROOT_PUBLIC_SR25519).unwrap(), + // Pre-funded accounts + vec![ + AccountId::from_str(ROOT_PUBLIC_SR25519).unwrap() + ], + true, + )) + .with_properties(default_properties()) .build()) } @@ -144,4 +193,11 @@ fn testnet_genesis( "key": Some(root_key), } }) +} + +fn default_properties() -> sc_service::Properties { + let mut props : sc_service::Properties = sc_service::Properties::new(); + props.insert("tokenSymbol".to_string(), json!("AGAT")); + props.insert("tokenDecimals".to_string(), json!(18)); + return props; } \ No newline at end of file diff --git a/node/src/command.rs b/node/src/command.rs index c49948d..f5c99d5 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -46,7 +46,7 @@ impl SubstrateCli for Cli { Ok(match id { "dev" => Box::new(chain_spec::development_config()?), "" | "local" => Box::new(chain_spec::local_testnet_config()?), - "aga" => Box::new(chain_spec::aga_config()?), + "aga" => Box::new(chain_spec::aga_testnet_config()?), path => { Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?) },