Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions polkadot/service/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ impl ChainSpec {

/// Dump to json string.
pub fn to_json(self, raw: bool) -> Result<String, String> {
#[derive(Serialize, Deserialize)]
struct Container {
#[serde(flatten)]
spec: ChainSpecFile,
#[serde(flatten)]
genesis: Genesis,

};
let genesis = match (raw, self.genesis.resolve()?) {
(true, Genesis::Runtime(g)) => {
let storage = g.build_storage()?.into_iter()
Expand All @@ -124,11 +132,10 @@ impl ChainSpec {
},
(_, genesis) => genesis,
};
let mut spec = json::to_value(self.spec).map_err(|e| format!("Error generating spec json: {}", e))?;
{
let map = spec.as_object_mut().expect("spec is an object");
map.insert("genesis".to_owned(), json::to_value(genesis).map_err(|e| format!("Error generating genesis json: {}", e))?);
}
let spec = Container {
spec: self.spec,
genesis,
};
json::to_string_pretty(&spec).map_err(|e| format!("Error generating spec json: {}", e))
}

Expand Down