Explorar o código

Remove content_config.rs, refactor chainspec

iorveth %!s(int64=4) %!d(string=hai) anos
pai
achega
bc3b516c9c

+ 0 - 139
node/src/chain_spec/content_config.rs

@@ -1,139 +0,0 @@
-#![allow(dead_code)]
-
-use codec::Decode;
-use node_runtime::{
-    content_directory::{ClassOf, EntityOf},
-    data_directory::DataObject,
-    ContentId, DataDirectoryConfig, Runtime,
-};
-use serde::Deserialize;
-use std::{fs, path::Path};
-
-// Because of the way that the @joystream/types were implemented the getters for
-// the string types return a `string` not the `Text` type so when we are serializing
-// them to json we get a string rather than an array of bytes, so deserializing them
-// is failing. So we are relying on parity codec encoding instead..
-#[derive(Decode)]
-struct DataObjectAndContentId {
-    content_id: ContentId,
-    data_object: DataObject<Runtime>,
-}
-
-#[derive(Decode)]
-struct ContentData {
-    /// classes
-    classes: Vec<ClassOf<Runtime>>,
-    /// entities
-    entities: Vec<EntityOf<Runtime>>,
-    /// DataObject(s) and ContentId
-    data_objects: Vec<DataObjectAndContentId>,
-}
-
-#[derive(Deserialize)]
-struct EncodedClass {
-    /// hex encoded Class
-    class: String,
-}
-
-impl EncodedClass {
-    fn decode(&self) -> ClassOf<Runtime> {
-        // hex string must not include '0x' prefix!
-        let encoded_class =
-            hex::decode(&self.class[2..].as_bytes()).expect("failed to parse class hex string");
-        Decode::decode(&mut encoded_class.as_slice()).unwrap()
-    }
-}
-
-#[derive(Deserialize)]
-struct EncodedEntity {
-    /// hex encoded Entity
-    entity: String,
-}
-
-impl EncodedEntity {
-    fn decode(&self) -> EntityOf<Runtime> {
-        // hex string must not include '0x' prefix!
-        let encoded_entity =
-            hex::decode(&self.entity[2..].as_bytes()).expect("failed to parse entity hex string");
-        Decode::decode(&mut encoded_entity.as_slice()).unwrap()
-    }
-}
-
-#[derive(Deserialize)]
-struct EncodedDataObjectAndContentId {
-    /// hex encoded ContentId
-    content_id: String,
-    /// hex encoded DataObject<Runtime>
-    data_object: String,
-}
-
-impl EncodedDataObjectAndContentId {
-    fn decode(&self) -> DataObjectAndContentId {
-        // hex string must not include '0x' prefix!
-        let encoded_content_id = hex::decode(&self.content_id[2..].as_bytes())
-            .expect("failed to parse content_id hex string");
-        let encoded_data_object = hex::decode(&self.data_object[2..].as_bytes())
-            .expect("failed to parse data_object hex string");
-        DataObjectAndContentId {
-            content_id: Decode::decode(&mut encoded_content_id.as_slice()).unwrap(),
-            data_object: Decode::decode(&mut encoded_data_object.as_slice()).unwrap(),
-        }
-    }
-}
-
-#[derive(Deserialize)]
-struct EncodedContentData {
-    /// classes and their associted permissions
-    classes: Vec<EncodedClass>,
-    /// entities and their associated maintainer
-    entities: Vec<EncodedEntity>,
-    /// DataObject(s) and ContentId
-    data_objects: Vec<EncodedDataObjectAndContentId>,
-}
-
-fn parse_content_data(data_file: &Path) -> EncodedContentData {
-    let data = fs::read_to_string(data_file).expect("Failed reading file");
-    serde_json::from_str(&data).expect("failed parsing content data")
-}
-
-impl EncodedContentData {
-    pub fn decode(&self) -> ContentData {
-        ContentData {
-            classes: self.classes.iter().map(|class| class.decode()).collect(),
-            entities: self.entities.iter().map(|entity| entity.decode()).collect(),
-            data_objects: self
-                .data_objects
-                .iter()
-                .map(|data_object| data_object.decode())
-                .collect(),
-        }
-    }
-}
-
-/// Generates a basic empty `DataDirectoryConfig` genesis config
-pub fn empty_data_directory_config() -> DataDirectoryConfig {
-    DataDirectoryConfig {
-        data_object_by_content_id: vec![],
-        known_content_ids: vec![],
-    }
-}
-
-/// Generates a `DataDirectoryConfig` genesis config
-/// pre-populated with data objects and known content ids parsed from
-/// a json file serialized as a `ContentData` struct
-pub fn data_directory_config_from_json(data_file: &Path) -> DataDirectoryConfig {
-    let content = parse_content_data(data_file).decode();
-
-    DataDirectoryConfig {
-        data_object_by_content_id: content
-            .data_objects
-            .iter()
-            .map(|object| (object.content_id, object.data_object.clone()))
-            .collect(),
-        known_content_ids: content
-            .data_objects
-            .into_iter()
-            .map(|object| object.content_id)
-            .collect(),
-    }
-}

+ 4 - 11
node/src/chain_spec/mod.rs

@@ -31,16 +31,15 @@ use sp_runtime::Perbill;
 use node_runtime::{
     membership, wasm_binary_unwrap, AuthorityDiscoveryConfig, BabeConfig, Balance, BalancesConfig,
     ContentDirectoryConfig, ContentDirectoryWorkingGroupConfig, CouncilConfig,
-    CouncilElectionConfig, DataDirectoryConfig, DataObjectStorageRegistryConfig,
-    DataObjectTypeRegistryConfig, ElectionParameters, ForumConfig, ForumWorkingGroupConfig,
-    GrandpaConfig, ImOnlineConfig, MembersConfig, Moment, SessionConfig, SessionKeys, Signature,
-    StakerStatus, StakingConfig, StorageWorkingGroupConfig, SudoConfig, SystemConfig, DAYS,
+    CouncilElectionConfig, DataObjectStorageRegistryConfig, DataObjectTypeRegistryConfig,
+    ElectionParameters, ForumConfig, ForumWorkingGroupConfig, GrandpaConfig, ImOnlineConfig,
+    MembersConfig, Moment, SessionConfig, SessionKeys, Signature, StakerStatus, StakingConfig,
+    StorageWorkingGroupConfig, SudoConfig, SystemConfig, DAYS,
 };
 
 // Exported to be used by chain-spec-builder
 pub use node_runtime::{AccountId, GenesisConfig};
 
-pub mod content_config;
 pub mod forum_config;
 pub mod initial_balances;
 pub mod initial_members;
@@ -133,7 +132,6 @@ impl Alternative {
                         ],
                         initial_members::none(),
                         forum_config::empty(get_account_id_from_seed::<sr25519::Public>("Alice")),
-                        content_config::empty_data_directory_config(),
                         vec![],
                     )
                 },
@@ -170,7 +168,6 @@ impl Alternative {
                         ],
                         initial_members::none(),
                         forum_config::empty(get_account_id_from_seed::<sr25519::Public>("Alice")),
-                        content_config::empty_data_directory_config(),
                         vec![],
                     )
                 },
@@ -212,7 +209,6 @@ pub fn testnet_genesis(
     endowed_accounts: Vec<AccountId>,
     members: Vec<membership::genesis::Member<u64, AccountId, Moment>>,
     forum_config: ForumConfig,
-    data_directory_config: DataDirectoryConfig,
     initial_balances: Vec<(AccountId, Balance)>,
 ) -> GenesisConfig {
     const STASH: Balance = 5_000;
@@ -293,7 +289,6 @@ pub fn testnet_genesis(
             members,
         }),
         forum: Some(forum_config),
-        data_directory: Some(data_directory_config),
         data_object_type_registry: Some(DataObjectTypeRegistryConfig {
             first_data_object_type_id: 1,
         }),
@@ -347,7 +342,6 @@ pub(crate) mod tests {
             vec![get_authority_keys_from_seed("Alice").0],
             initial_members::none(),
             forum_config::empty(get_account_id_from_seed::<sr25519::Public>("Alice")),
-            content_config::empty_data_directory_config(),
             vec![],
         )
     }
@@ -380,7 +374,6 @@ pub(crate) mod tests {
             ],
             initial_members::none(),
             forum_config::empty(get_account_id_from_seed::<sr25519::Public>("Alice")),
-            content_config::empty_data_directory_config(),
             vec![],
         )
     }

+ 1 - 1
runtime/src/lib.rs

@@ -782,7 +782,7 @@ construct_runtime!(
         Constitution: constitution::{Module, Call, Storage, Event},
         // --- Storage
         DataObjectTypeRegistry: data_object_type_registry::{Module, Call, Storage, Event<T>, Config<T>},
-        DataDirectory: data_directory::{Module, Call, Storage, Event<T>, Config<T>},
+        DataDirectory: data_directory::{Module, Call, Storage, Event<T>},
         DataObjectStorageRegistry: data_object_storage_registry::{Module, Call, Storage, Event<T>, Config<T>},
         Discovery: service_discovery::{Module, Call, Storage, Event<T>},
         // --- Proposals

+ 1 - 36
utils/chain-spec-builder/src/main.rs

@@ -24,8 +24,7 @@ use rand::{distributions::Alphanumeric, rngs::OsRng, Rng};
 use structopt::StructOpt;
 
 use joystream_node::chain_spec::{
-    self, chain_spec_properties, content_config, forum_config, initial_balances, initial_members,
-    AccountId,
+    self, chain_spec_properties, forum_config, initial_balances, initial_members, AccountId,
 };
 
 use sc_chain_spec::ChainType;
@@ -85,9 +84,6 @@ enum ChainSpecBuilder {
         /// The path to an initial forum data
         #[structopt(long, short)]
         initial_forum_path: Option<PathBuf>,
-        /// The path to an initial content directory data file
-        #[structopt(long, short)]
-        initial_content_path: Option<PathBuf>,
         /// The path to an initial balances file
         #[structopt(long, short)]
         initial_balances_path: Option<PathBuf>,
@@ -120,9 +116,6 @@ enum ChainSpecBuilder {
         /// The path to an initial forum data
         #[structopt(long, short)]
         initial_forum_path: Option<PathBuf>,
-        /// The path to an initial content directory data file
-        #[structopt(long, short)]
-        initial_content_path: Option<PathBuf>,
         /// The path to an initial balances file
         #[structopt(long, short)]
         initial_balances_path: Option<PathBuf>,
@@ -171,20 +164,6 @@ impl ChainSpecBuilder {
         }
     }
 
-    /// Returns the path to load initial platform content from
-    fn initial_content_path(&self) -> &Option<PathBuf> {
-        match self {
-            ChainSpecBuilder::New {
-                initial_content_path,
-                ..
-            } => initial_content_path,
-            ChainSpecBuilder::Generate {
-                initial_content_path,
-                ..
-            } => initial_content_path,
-        }
-    }
-
     /// Returns the path to load initial platform content from
     fn initial_balances_path(&self) -> &Option<PathBuf> {
         match self {
@@ -222,7 +201,6 @@ fn genesis_constructor(
     sudo_account: &AccountId,
     initial_members_path: &Option<PathBuf>,
     initial_forum_path: &Option<PathBuf>,
-    initial_content_path: &Option<PathBuf>,
     initial_balances_path: &Option<PathBuf>,
 ) -> chain_spec::GenesisConfig {
     let authorities = authority_seeds
@@ -241,14 +219,6 @@ fn genesis_constructor(
         .map(|path| forum_config::from_json(sudo_account.clone(), path.as_path()))
         .unwrap_or_else(|| forum_config::empty(sudo_account.clone()));
 
-    let (data_directory_config,) = if let Some(path) = initial_content_path {
-        let path = path.as_path();
-
-        (content_config::data_directory_config_from_json(path),)
-    } else {
-        (content_config::empty_data_directory_config(),)
-    };
-
     let initial_account_balances = initial_balances_path
         .as_ref()
         .map(|path| initial_balances::from_json(path.as_path()))
@@ -260,7 +230,6 @@ fn genesis_constructor(
         endowed_accounts.to_vec(),
         members,
         forum_cfg,
-        data_directory_config,
         initial_account_balances,
     )
 }
@@ -275,7 +244,6 @@ fn generate_chain_spec(
     sudo_account: String,
     initial_members_path: Option<PathBuf>,
     initial_forum_path: Option<PathBuf>,
-    initial_content_path: Option<PathBuf>,
     initial_balances_path: Option<PathBuf>,
 ) -> Result<String, String> {
     let parse_account = |address: &String| {
@@ -309,7 +277,6 @@ fn generate_chain_spec(
                 &sudo_account,
                 &initial_members_path,
                 &initial_forum_path,
-                &initial_content_path,
                 &initial_balances_path,
             )
         },
@@ -390,7 +357,6 @@ fn main() -> Result<(), String> {
     let chain_spec_path = builder.chain_spec_path().to_path_buf();
     let initial_members_path = builder.initial_members_path().clone();
     let initial_forum_path = builder.initial_forum_path().clone();
-    let initial_content_path = builder.initial_content_path().clone();
     let initial_balances_path = builder.initial_balances_path().clone();
     let deployment = builder.chain_deployment();
 
@@ -442,7 +408,6 @@ fn main() -> Result<(), String> {
         sudo_account,
         initial_members_path,
         initial_forum_path,
-        initial_content_path,
         initial_balances_path,
     )?;