mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 22:11:02 +00:00
Avoid serializing into json::Value (#313)
This commit is contained in:
committed by
Gav Wood
parent
0929e45320
commit
b1327624cd
@@ -114,6 +114,14 @@ impl ChainSpec {
|
|||||||
|
|
||||||
/// Dump to json string.
|
/// Dump to json string.
|
||||||
pub fn to_json(self, raw: bool) -> Result<String, 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()?) {
|
let genesis = match (raw, self.genesis.resolve()?) {
|
||||||
(true, Genesis::Runtime(g)) => {
|
(true, Genesis::Runtime(g)) => {
|
||||||
let storage = g.build_storage()?.into_iter()
|
let storage = g.build_storage()?.into_iter()
|
||||||
@@ -124,11 +132,10 @@ impl ChainSpec {
|
|||||||
},
|
},
|
||||||
(_, genesis) => genesis,
|
(_, genesis) => genesis,
|
||||||
};
|
};
|
||||||
let mut spec = json::to_value(self.spec).map_err(|e| format!("Error generating spec json: {}", e))?;
|
let spec = Container {
|
||||||
{
|
spec: self.spec,
|
||||||
let map = spec.as_object_mut().expect("spec is an object");
|
genesis,
|
||||||
map.insert("genesis".to_owned(), json::to_value(genesis).map_err(|e| format!("Error generating genesis json: {}", e))?);
|
};
|
||||||
}
|
|
||||||
json::to_string_pretty(&spec).map_err(|e| format!("Error generating spec json: {}", e))
|
json::to_string_pretty(&spec).map_err(|e| format!("Error generating spec json: {}", e))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user