git.delta.rocks / unique-network / refs/commits / eb5b53586bb9

difftreelog

source

node/src/chain_spec.rs6.9 KiBsourcehistory
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56use nft_runtime::*;7use nft_data_structs::*;8use sc_service::ChainType;9use sp_consensus_aura::sr25519::AuthorityId as AuraId;10use sp_core::{sr25519, Pair, Public};11use sp_finality_grandpa::AuthorityId as GrandpaId;12use sp_runtime::traits::{IdentifyAccount, Verify};13use serde_json::map::Map;1415// Note this is the URL for the telemetry server16//const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";1718/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.19pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig>;2021/// Helper function to generate a crypto pair from seed22pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {23    TPublic::Pair::from_string(&format!("//{}", seed), None)24        .expect("static values are valid; qed")25        .public()26}2728type AccountPublic = <Signature as Verify>::Signer;2930/// Helper function to generate an account ID from seed31pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId32where33    AccountPublic: From<<TPublic::Pair as Pair>::Public>,34{35    AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()36}3738/// Helper function to generate an authority key for Aura39pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) {40    (get_from_seed::<AuraId>(s), get_from_seed::<GrandpaId>(s))41}4243pub fn development_config() -> Result<ChainSpec, String> {44	let wasm_binary = WASM_BINARY.ok_or("Development wasm binary not available".to_string())?;4546	let mut properties = Map::new();47	properties.insert("tokenSymbol".into(), "UniqueTest".into());48	properties.insert("tokenDecimals".into(), 15.into());49	properties.insert("ss58Format".into(), 42.into()); // Generic Substrate wildcard (SS58 checksum preimage)5051	Ok(ChainSpec::from_genesis(52		// Name53		"Development",54		// ID55		"dev",56		ChainType::Development,57		move || testnet_genesis(58			wasm_binary,59			// Initial PoA authorities60			vec![61				authority_keys_from_seed("Alice"),62			],63			// Sudo account64			get_account_id_from_seed::<sr25519::Public>("Alice"),65			// Pre-funded accounts66			vec![67				get_account_id_from_seed::<sr25519::Public>("Alice"),68				get_account_id_from_seed::<sr25519::Public>("Bob"),69				get_account_id_from_seed::<sr25519::Public>("Alice//stash"),70				get_account_id_from_seed::<sr25519::Public>("Bob//stash"),71			],72			true,73		),74		// Bootnodes75		vec![],76		// Telemetry77		None,78		// Protocol ID79		None,80		// Properties81		Some(properties),82		// Extensions83		None,84	))85}8687pub fn local_testnet_config() -> Result<ChainSpec, String> {88	let wasm_binary = WASM_BINARY.ok_or("Development wasm binary not available".to_string())?;8990	Ok(ChainSpec::from_genesis(91		// Name92		"Local Testnet",93		// ID94		"local_testnet",95		ChainType::Local,96		move || testnet_genesis(97			wasm_binary,98			// Initial PoA authorities99			vec![100				authority_keys_from_seed("Alice"),101				authority_keys_from_seed("Bob"),102			],103			// Sudo account104			get_account_id_from_seed::<sr25519::Public>("Alice"),105			// Pre-funded accounts106			vec![107				get_account_id_from_seed::<sr25519::Public>("Alice"),108				get_account_id_from_seed::<sr25519::Public>("Bob"),109				get_account_id_from_seed::<sr25519::Public>("Charlie"),110				get_account_id_from_seed::<sr25519::Public>("Dave"),111				get_account_id_from_seed::<sr25519::Public>("Eve"),112				get_account_id_from_seed::<sr25519::Public>("Ferdie"),113				get_account_id_from_seed::<sr25519::Public>("Alice//stash"),114				get_account_id_from_seed::<sr25519::Public>("Bob//stash"),115				get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),116				get_account_id_from_seed::<sr25519::Public>("Dave//stash"),117				get_account_id_from_seed::<sr25519::Public>("Eve//stash"),118				get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),119			],120			true,121		),122		// Bootnodes123		vec![],124		// Telemetry125		None,126		// Protocol ID127		None,128		// Properties129		None,130		// Extensions131		None,132	))133}134135fn testnet_genesis(136    wasm_binary: &[u8],137    initial_authorities: Vec<(AuraId, GrandpaId)>,138    root_key: AccountId,139    endowed_accounts: Vec<AccountId>,140    enable_println: bool,141) -> GenesisConfig {142143	let vested_accounts = vec![144		get_account_id_from_seed::<sr25519::Public>("Bob"),145	];146147    GenesisConfig {148        system: Some(SystemConfig {149            code: wasm_binary.to_vec(),150            changes_trie_config: Default::default(),151        }),152        pallet_balances: Some(BalancesConfig {153            balances: endowed_accounts154                .iter()155                .cloned()156                .map(|k| (k, 1 << 70))157                .collect(),158        }),159        pallet_aura: Some(AuraConfig {160            authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(),161        }),162		pallet_grandpa: Some(GrandpaConfig {163            authorities: initial_authorities164                .iter()165                .map(|x| (x.1.clone(), 1))166                .collect(),167		}),168		pallet_treasury: Some(Default::default()),169		pallet_sudo: Some(SudoConfig { key: root_key }),170		pallet_vesting: Some(VestingConfig {171            vesting: vested_accounts172                .iter()173                .cloned()174                .map(|k| (k, 1000, 100, 1 << 98))175                .collect(),176        }),177        pallet_nft: Some(NftConfig {178            collection_id: vec![(179                1,180                Collection {181                    owner: get_account_id_from_seed::<sr25519::Public>("Alice"),182                    mode: CollectionMode::NFT,183                    access: AccessMode::Normal,184                    decimal_points: 0,185                    name: vec![],186                    description: vec![],187                    token_prefix: vec![],188                    mint_mode: false,189					offchain_schema: vec![],190					schema_version: SchemaVersion::default(),191                    sponsorship: SponsorshipState::Confirmed(get_account_id_from_seed::<sr25519::Public>("Alice")),192                    const_on_chain_schema: vec![],193					variable_on_chain_schema: vec![],194					limits: CollectionLimits::default()195                },196            )],197            nft_item_id: vec![],198            fungible_item_id: vec![],199            refungible_item_id: vec![],200            chain_limit: ChainLimits {201                collection_numbers_limit: 100000,202                account_token_ownership_limit: 1000000,203                collections_admins_limit: 5,204                custom_data_limit: 2048,205                nft_sponsor_transfer_timeout: 15,206                fungible_sponsor_transfer_timeout: 15,207				refungible_sponsor_transfer_timeout: 15,208				offchain_schema_limit: 1024,209				variable_on_chain_schema_limit: 1024,210				const_on_chain_schema_limit: 1024,211            },212        }),213        pallet_contracts: Some(ContractsConfig {214            current_schedule: ContractsSchedule {215                enable_println,216                ..Default::default()217            },218        }),219    }220}