123456use nft_runtime::*;7use sp_core::{Pair, Public, sr25519};8use nft_runtime::{9 AccountId, AuraConfig, BalancesConfig, EVMConfig, EthereumConfig, GenesisConfig, GrandpaConfig,10 SudoConfig, SystemConfig, WASM_BINARY, Signature11};12use sp_consensus_aura::sr25519::AuthorityId as AuraId;13use sp_finality_grandpa::AuthorityId as GrandpaId;14use sp_runtime::traits::{Verify, IdentifyAccount};15use sc_service::ChainType;16use serde_json::map::Map;17use std::collections::BTreeMap;181920212223pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig>;242526pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {27 TPublic::Pair::from_string(&format!("//{}", seed), None)28 .expect("static values are valid; qed")29 .public()30}3132type AccountPublic = <Signature as Verify>::Signer;333435pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId36where37 AccountPublic: From<<TPublic::Pair as Pair>::Public>,38{39 AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()40}414243pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) {44 (get_from_seed::<AuraId>(s), get_from_seed::<GrandpaId>(s))45}4647pub fn development_config() -> Result<ChainSpec, String> {48 let wasm_binary = WASM_BINARY.ok_or("Development wasm binary not available".to_string())?;4950 let mut properties = Map::new();51 properties.insert("tokenSymbol".into(), "UniqueTest".into());52 properties.insert("tokenDecimals".into(), 15.into());53 properties.insert("ss58Format".into(), 42.into()); 5455 Ok(ChainSpec::from_genesis(56 57 "Development",58 59 "dev",60 ChainType::Development,61 move || testnet_genesis(62 wasm_binary,63 64 vec![65 authority_keys_from_seed("Alice"),66 ],67 68 get_account_id_from_seed::<sr25519::Public>("Alice"),69 70 vec![71 get_account_id_from_seed::<sr25519::Public>("Alice"),72 get_account_id_from_seed::<sr25519::Public>("Bob"),73 get_account_id_from_seed::<sr25519::Public>("Alice//stash"),74 get_account_id_from_seed::<sr25519::Public>("Bob//stash"),75 ],76 true,77 ),78 79 vec![],80 81 None,82 83 None,84 85 Some(properties),86 87 None,88 ))89}9091pub fn local_testnet_config() -> Result<ChainSpec, String> {92 let wasm_binary = WASM_BINARY.ok_or("Development wasm binary not available".to_string())?;9394 Ok(ChainSpec::from_genesis(95 96 "Local Testnet",97 98 "local_testnet",99 ChainType::Local,100 move || testnet_genesis(101 wasm_binary,102 103 vec![104 authority_keys_from_seed("Alice"),105 authority_keys_from_seed("Bob"),106 ],107 108 get_account_id_from_seed::<sr25519::Public>("Alice"),109 110 vec![111 get_account_id_from_seed::<sr25519::Public>("Alice"),112 get_account_id_from_seed::<sr25519::Public>("Bob"),113 get_account_id_from_seed::<sr25519::Public>("Charlie"),114 get_account_id_from_seed::<sr25519::Public>("Dave"),115 get_account_id_from_seed::<sr25519::Public>("Eve"),116 get_account_id_from_seed::<sr25519::Public>("Ferdie"),117 get_account_id_from_seed::<sr25519::Public>("Alice//stash"),118 get_account_id_from_seed::<sr25519::Public>("Bob//stash"),119 get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),120 get_account_id_from_seed::<sr25519::Public>("Dave//stash"),121 get_account_id_from_seed::<sr25519::Public>("Eve//stash"),122 get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),123 ],124 true,125 ),126 127 vec![],128 129 None,130 131 None,132 133 None,134 135 None,136 ))137}138139fn testnet_genesis(140 wasm_binary: &[u8],141 initial_authorities: Vec<(AuraId, GrandpaId)>,142 root_key: AccountId,143 endowed_accounts: Vec<AccountId>,144 enable_println: bool,145) -> GenesisConfig {146147 let vested_accounts = vec![148 get_account_id_from_seed::<sr25519::Public>("Bob"),149 ];150151 GenesisConfig {152 system: SystemConfig {153 code: wasm_binary.to_vec(),154 changes_trie_config: Default::default(),155 },156 pallet_balances: BalancesConfig {157 balances: endowed_accounts158 .iter()159 .cloned()160 .map(|k| (k, 1 << 100))161 .collect(),162 },163 pallet_aura: AuraConfig {164 authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(),165 },166 pallet_grandpa: GrandpaConfig {167 authorities: initial_authorities168 .iter()169 .map(|x| (x.1.clone(), 1))170 .collect(),171 },172 pallet_treasury: Default::default(),173 pallet_sudo: SudoConfig { key: root_key },174 pallet_vesting: VestingConfig {175 vesting: vested_accounts176 .iter()177 .cloned()178 .map(|k| (k, 1000, 100, 1 << 98))179 .collect(),180 },181 pallet_nft: NftConfig {182 collection_id: vec![(183 1,184 Collection {185 owner: get_account_id_from_seed::<sr25519::Public>("Alice"),186 mode: CollectionMode::NFT,187 access: AccessMode::Normal,188 decimal_points: 0,189 name: vec![],190 description: vec![],191 token_prefix: vec![],192 mint_mode: false,193 offchain_schema: vec![],194 schema_version: SchemaVersion::default(),195 sponsorship: SponsorshipState::Confirmed(get_account_id_from_seed::<sr25519::Public>("Alice")),196 const_on_chain_schema: vec![],197 variable_on_chain_schema: vec![],198 limits: CollectionLimits::default()199 },200 )],201 nft_item_id: vec![],202 fungible_item_id: vec![],203 refungible_item_id: vec![],204 chain_limit: ChainLimits {205 collection_numbers_limit: 100000,206 account_token_ownership_limit: 1000000,207 collections_admins_limit: 5,208 custom_data_limit: 2048,209 nft_sponsor_transfer_timeout: 15,210 fungible_sponsor_transfer_timeout: 15,211 refungible_sponsor_transfer_timeout: 15,212 offchain_schema_limit: 1024,213 variable_on_chain_schema_limit: 1024,214 const_on_chain_schema_limit: 1024,215 },216 },217 pallet_contracts: ContractsConfig {218 current_schedule: ContractsSchedule {219 enable_println,220 ..Default::default()221 },222 },223 pallet_evm: EVMConfig {224 accounts: BTreeMap::new(),225 },226 pallet_ethereum: EthereumConfig {},227 }228}