// This file is part of Bizinikiwi. // Copyright (C) Parity Technologies (UK) Ltd. and Dijital Kurdistan Tech Institute // SPDX-License-Identifier: Apache-2.0 // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. use crate::{AccountId, BalancesConfig, RuntimeGenesisConfig, SudoConfig}; use alloc::{vec, vec::Vec}; use pezframe_support::build_struct_json_patch; use pezsp_consensus_aura::sr25519::AuthorityId as AuraId; use pezsp_consensus_grandpa::AuthorityId as GrandpaId; use pezsp_genesis_builder::{self, PresetId}; use pezsp_keyring::Sr25519Keyring; use serde_json::Value; // Returns the genesis config presets populated with given parameters. fn testnet_genesis( initial_authorities: Vec<(AuraId, GrandpaId)>, endowed_accounts: Vec, root: AccountId, ) -> Value { build_struct_json_patch!(RuntimeGenesisConfig { balances: BalancesConfig { balances: endowed_accounts .iter() .cloned() .map(|k| (k, 1u128 << 60)) .collect::>(), }, aura: pezpallet_aura::GenesisConfig { authorities: initial_authorities.iter().map(|x| x.0.clone()).collect::>(), }, grandpa: pezpallet_grandpa::GenesisConfig { authorities: initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect::>(), }, sudo: SudoConfig { key: Some(root) }, }) } /// Return the development genesis config. pub fn development_config_genesis() -> Value { testnet_genesis( vec![( pezsp_keyring::Sr25519Keyring::Alice.public().into(), pezsp_keyring::Ed25519Keyring::Alice.public().into(), )], vec![ Sr25519Keyring::Alice.to_account_id(), Sr25519Keyring::Bob.to_account_id(), Sr25519Keyring::AliceStash.to_account_id(), Sr25519Keyring::BobStash.to_account_id(), ], pezsp_keyring::Sr25519Keyring::Alice.to_account_id(), ) } /// Return the local genesis config preset. pub fn local_config_genesis() -> Value { testnet_genesis( vec![ ( pezsp_keyring::Sr25519Keyring::Alice.public().into(), pezsp_keyring::Ed25519Keyring::Alice.public().into(), ), ( pezsp_keyring::Sr25519Keyring::Bob.public().into(), pezsp_keyring::Ed25519Keyring::Bob.public().into(), ), ], Sr25519Keyring::iter() .filter(|v| v != &Sr25519Keyring::One && v != &Sr25519Keyring::Two) .map(|v| v.to_account_id()) .collect::>(), Sr25519Keyring::Alice.to_account_id(), ) } /// Provides the JSON representation of predefined genesis config for given `id`. pub fn get_preset(id: &PresetId) -> Option> { let patch = match id.as_ref() { pezsp_genesis_builder::DEV_RUNTIME_PRESET => development_config_genesis(), pezsp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET => local_config_genesis(), _ => return None, }; Some( serde_json::to_string(&patch) .expect("serialization to json is expected to work. qed.") .into_bytes(), ) } /// List of supported presets. pub fn preset_names() -> Vec { vec![ PresetId::from(pezsp_genesis_builder::DEV_RUNTIME_PRESET), PresetId::from(pezsp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET), ] }