File tree Expand file tree Collapse file tree 3 files changed +18
-8
lines changed
sc-subspace-chain-specs/src Expand file tree Collapse file tree 3 files changed +18
-8
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ use std::fmt;
1515use std:: marker:: PhantomData ;
1616use std:: path:: PathBuf ;
1717
18+ /// Serializes chain spec to a string, note that when serialized with `serde_json` it'll end up
19+ /// being serialized twice, hence it will be JSON-encoded string.
1820pub struct SerializableChainSpec < GenesisConfig , Extensions = NoExtension > {
1921 chain_spec : GenericChainSpec < GenesisConfig , Extensions > ,
2022}
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ use sc_executor::{NativeExecutionDispatch, RuntimeVersion};
2929use sc_service:: ChainSpec ;
3030use sc_subspace_chain_specs:: ConsensusChainSpec ;
3131use sc_telemetry:: serde_json;
32+ use serde_json:: Value ;
3233use std:: io:: Write ;
3334use std:: { fs, io} ;
3435
@@ -229,15 +230,18 @@ impl SubstrateCli for Cli {
229230 // In case there are bootstrap nodes specified explicitly, ignore those that are in the
230231 // chain spec
231232 if !self . run . network_params . bootnodes . is_empty ( ) {
232- let mut chain_spec_value =
233- serde_json :: to_value ( & chain_spec ) . map_err ( |error| error. to_string ( ) ) ?;
233+ let mut chain_spec_value: Value = serde_json :: from_str ( & chain_spec . as_json ( true ) ? )
234+ . map_err ( |error| error. to_string ( ) ) ?;
234235 if let Some ( boot_nodes) = chain_spec_value. get_mut ( "bootNodes" ) {
235236 if let Some ( boot_nodes) = boot_nodes. as_array_mut ( ) {
236237 boot_nodes. clear ( ) ;
237238 }
238239 }
239- chain_spec =
240- serde_json:: from_value ( chain_spec_value) . map_err ( |error| error. to_string ( ) ) ?;
240+ // Such mess because native serialization of the chain spec serializes it twice, see
241+ // docs on `sc_subspace_chain_specs::utils::SerializableChainSpec`.
242+ chain_spec = serde_json:: to_string ( & chain_spec_value. to_string ( ) )
243+ . and_then ( |chain_spec_string| serde_json:: from_str ( & chain_spec_string) )
244+ . map_err ( |error| error. to_string ( ) ) ?;
241245 }
242246 Ok ( Box :: new ( chain_spec) )
243247 }
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ use sc_cli::{
2323use sc_service:: config:: PrometheusConfig ;
2424use sc_service:: BasePath ;
2525use sc_subspace_chain_specs:: ExecutionChainSpec ;
26+ use serde_json:: Value ;
2627use std:: net:: SocketAddr ;
2728use std:: path:: PathBuf ;
2829
@@ -105,15 +106,18 @@ impl SubstrateCli for SecondaryChainCli {
105106 // In case there are bootstrap nodes specified explicitly, ignore those that are in the
106107 // chain spec
107108 if !self . run . network_params . bootnodes . is_empty ( ) {
108- let mut chain_spec_value =
109- serde_json :: to_value ( & chain_spec ) . map_err ( |error| error. to_string ( ) ) ?;
109+ let mut chain_spec_value: Value = serde_json :: from_str ( & chain_spec . as_json ( true ) ? )
110+ . map_err ( |error| error. to_string ( ) ) ?;
110111 if let Some ( boot_nodes) = chain_spec_value. get_mut ( "bootNodes" ) {
111112 if let Some ( boot_nodes) = boot_nodes. as_array_mut ( ) {
112113 boot_nodes. clear ( ) ;
113114 }
114115 }
115- chain_spec =
116- serde_json:: from_value ( chain_spec_value) . map_err ( |error| error. to_string ( ) ) ?;
116+ // Such mess because native serialization of the chain spec serializes it twice, see
117+ // docs on `sc_subspace_chain_specs::utils::SerializableChainSpec`.
118+ chain_spec = serde_json:: to_string ( & chain_spec_value. to_string ( ) )
119+ . and_then ( |chain_spec_string| serde_json:: from_str ( & chain_spec_string) )
120+ . map_err ( |error| error. to_string ( ) ) ?;
117121 }
118122
119123 Ok ( Box :: new ( chain_spec) )
You can’t perform that action at this time.
0 commit comments