Skip to content

Commit

Permalink
Added sp_genesis_builder impl to runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
fgamundi committed Feb 8, 2024
1 parent 4af7a83 commit 1b5d1a3
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 8 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ sp-consensus-slots = { git = "https://github.com/paritytech/polkadot-sdk", branc
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.6.0", default-features = false }
sp-debug-derive = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.6.0", default-features = false }
sp-externalities = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.6.0", default-features = false }
sp-genesis-builder = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.6.0", default-features = false }
sp-inherents = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.6.0", default-features = false }
sp-io = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.6.0", default-features = false }
sp-keystore = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.6.0", default-features = false }
Expand Down
36 changes: 28 additions & 8 deletions template/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,35 @@ fn testnet_genesis(
endowed_accounts: Vec<AccountId>,
id: ParaId,
) -> serde_json::Value {
serde_json::json!({
"balances": {
"balances": endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 60)).collect::<Vec<_>>(),
let g = moonkit_template_runtime::RuntimeGenesisConfig {
balances: moonkit_template_runtime::BalancesConfig {
balances: endowed_accounts
.iter()
.cloned()
.map(|k| (k, 1 << 60))
.collect(),
},
"parachainInfo": {
"parachainId": id,
parachain_info: moonkit_template_runtime::ParachainInfoConfig {
parachain_id: id,
..Default::default()
},
"potentialAuthorSet": {
"mapping": authorities,
author_filter: moonkit_template_runtime::AuthorFilterConfig {
eligible_count: moonkit_template_runtime::EligibilityValue::default(),
..Default::default()
},
})
potential_author_set: moonkit_template_runtime::PotentialAuthorSetConfig {
mapping: authorities,
},
parachain_system: Default::default(),
system: Default::default(),
};

serde_json::to_value(&g).unwrap()
}

#[test]
fn chain_spec_as_json_raw_works() {
let x = local_testnet_config();
let raw = true;
assert!(x.as_json(raw).is_ok());
}
1 change: 1 addition & 0 deletions template/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pallet-template = { path = "../pallets/template", default-features = false }
sp-api = { workspace = true }
sp-block-builder = { workspace = true }
sp-core = { workspace = true }
sp-genesis-builder = { workspace = true }
sp-inherents = { workspace = true }
sp-io = { workspace = true }
sp-offchain = { workspace = true }
Expand Down
11 changes: 11 additions & 0 deletions template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use sp_version::RuntimeVersion;
use frame_support::{
construct_runtime,
dispatch::DispatchClass,
genesis_builder_helper::{build_config, create_default_config},
match_types, parameter_types,
traits::{ConstBool, Everything, Nothing, OnInitialize, TransformOrigin},
weights::{
Expand Down Expand Up @@ -830,6 +831,16 @@ impl_runtime_apis! {
}
}

impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
fn create_default_config() -> Vec<u8> {
create_default_config::<RuntimeGenesisConfig>()
}

fn build_config(config: Vec<u8>) -> sp_genesis_builder::Result {
build_config::<RuntimeGenesisConfig>(config)
}
}

#[cfg(feature = "runtime-benchmarks")]
impl frame_benchmarking::Benchmark<Block> for Runtime {
fn benchmark_metadata(extra: bool) -> (
Expand Down

0 comments on commit 1b5d1a3

Please sign in to comment.