Forráskód Böngészése

chainspec: prepare to import channels

Mokhtar Naamani 4 éve
szülő
commit
40321c90dd

+ 2 - 0
Cargo.lock

@@ -3806,6 +3806,7 @@ version = "3.0.0"
 dependencies = [
  "frame-support",
  "frame-system",
+ "pallet-common",
  "pallet-timestamp",
  "parity-scale-codec",
  "serde",
@@ -3821,6 +3822,7 @@ version = "3.0.0"
 dependencies = [
  "frame-support",
  "frame-system",
+ "pallet-common",
  "pallet-timestamp",
  "pallet-versioned-store",
  "parity-scale-codec",

+ 36 - 12
node/src/chain_spec/content_config.rs

@@ -1,12 +1,13 @@
+use codec::Decode;
+use node_runtime::common::constraints::InputValidationLengthConstraint;
 use node_runtime::{
     data_directory::DataObject,
     primitives::{BlockNumber, Credential},
-    versioned_store::{Class, ClassId, Entity, EntityId, InputValidationLengthConstraint},
+    versioned_store::{Class, ClassId, Entity, EntityId},
     versioned_store_permissions::ClassPermissions,
-    ContentId, DataDirectoryConfig, Runtime, VersionedStoreConfig, VersionedStorePermissionsConfig,
+    ContentId, ContentWorkingGroupConfig, DataDirectoryConfig, Runtime, VersionedStoreConfig,
+    VersionedStorePermissionsConfig,
 };
-
-use codec::Decode;
 use serde::Deserialize;
 use std::{fs, path::Path};
 
@@ -190,20 +191,16 @@ pub fn versioned_store_config_from_json(data_file: &Path) -> VersionedStoreConfi
     }
 }
 
-fn new_validation(min: u16, max_min_diff: u16) -> InputValidationLengthConstraint {
-    InputValidationLengthConstraint { min, max_min_diff }
-}
-
 pub fn empty_versioned_store_config() -> VersionedStoreConfig {
     VersionedStoreConfig {
         class_by_id: vec![],
         entity_by_id: vec![],
         next_class_id: 1,
         next_entity_id: 1,
-        property_name_constraint: new_validation(1, 99),
-        property_description_constraint: new_validation(1, 999),
-        class_name_constraint: new_validation(1, 99),
-        class_description_constraint: new_validation(1, 999),
+        property_name_constraint: InputValidationLengthConstraint::new(1, 99),
+        property_description_constraint: InputValidationLengthConstraint::new(1, 999),
+        class_name_constraint: InputValidationLengthConstraint::new(1, 99),
+        class_description_constraint: InputValidationLengthConstraint::new(1, 999),
     }
 }
 
@@ -260,3 +257,30 @@ pub fn data_directory_config_from_json(data_file: &Path) -> DataDirectoryConfig
             .collect(),
     }
 }
+
+pub fn empty_content_working_group_config() -> ContentWorkingGroupConfig {
+    ContentWorkingGroupConfig {
+        mint_capacity: 100_000,
+        curator_opening_by_id: vec![],
+        next_curator_opening_id: 0,
+        curator_application_by_id: vec![],
+        next_curator_application_id: 0,
+        channel_by_id: vec![],
+        next_channel_id: 1,
+        channel_id_by_handle: vec![],
+        curator_by_id: vec![],
+        next_curator_id: 0,
+        principal_by_id: vec![],
+        next_principal_id: 0,
+        channel_creation_enabled: true, // there is no extrinsic to change it so enabling at genesis
+        unstaker_by_stake_id: vec![],
+        channel_handle_constraint: InputValidationLengthConstraint::new(5, 20),
+        channel_description_constraint: InputValidationLengthConstraint::new(1, 1024),
+        opening_human_readable_text: InputValidationLengthConstraint::new(1, 2048),
+        curator_application_human_readable_text: InputValidationLengthConstraint::new(1, 2048),
+        curator_exit_rationale_text: InputValidationLengthConstraint::new(1, 2048),
+        channel_avatar_constraint: InputValidationLengthConstraint::new(5, 1024),
+        channel_banner_constraint: InputValidationLengthConstraint::new(5, 1024),
+        channel_title_constraint: InputValidationLengthConstraint::new(5, 1024),
+    }
+}

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

@@ -50,7 +50,6 @@ type AccountPublic = <Signature as Verify>::Signer;
 /// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.
 pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig>;
 
-use node_runtime::common::constraints::InputValidationLengthConstraint;
 use sc_chain_spec::ChainType;
 
 /// The chain specification option. This is expected to come in from the CLI and
@@ -138,6 +137,7 @@ impl Alternative {
                         content_config::empty_versioned_store_config(),
                         content_config::empty_versioned_store_permissions_config(),
                         content_config::empty_data_directory_config(),
+                        content_config::empty_content_working_group_config(),
                     )
                 },
                 Vec::new(),
@@ -177,6 +177,7 @@ impl Alternative {
                         content_config::empty_versioned_store_config(),
                         content_config::empty_versioned_store_permissions_config(),
                         content_config::empty_data_directory_config(),
+                        content_config::empty_content_working_group_config(),
                     )
                 },
                 Vec::new(),
@@ -220,6 +221,7 @@ pub fn testnet_genesis(
     versioned_store_config: VersionedStoreConfig,
     versioned_store_permissions_config: VersionedStorePermissionsConfig,
     data_directory_config: DataDirectoryConfig,
+    content_working_group_config: ContentWorkingGroupConfig,
 ) -> GenesisConfig {
     const CENTS: Balance = 1;
     const DOLLARS: Balance = 100 * CENTS;
@@ -311,30 +313,7 @@ pub fn testnet_genesis(
         }),
         versioned_store: Some(versioned_store_config),
         versioned_store_permissions: Some(versioned_store_permissions_config),
-        content_wg: Some(ContentWorkingGroupConfig {
-            mint_capacity: 100_000,
-            curator_opening_by_id: vec![],
-            next_curator_opening_id: 0,
-            curator_application_by_id: vec![],
-            next_curator_application_id: 0,
-            channel_by_id: vec![],
-            next_channel_id: 1,
-            channel_id_by_handle: vec![],
-            curator_by_id: vec![],
-            next_curator_id: 0,
-            principal_by_id: vec![],
-            next_principal_id: 0,
-            channel_creation_enabled: true, // there is no extrinsic to change it so enabling at genesis
-            unstaker_by_stake_id: vec![],
-            channel_handle_constraint: InputValidationLengthConstraint::new(5, 20),
-            channel_description_constraint: InputValidationLengthConstraint::new(1, 1024),
-            opening_human_readable_text: InputValidationLengthConstraint::new(1, 2048),
-            curator_application_human_readable_text: InputValidationLengthConstraint::new(1, 2048),
-            curator_exit_rationale_text: InputValidationLengthConstraint::new(1, 2048),
-            channel_avatar_constraint: InputValidationLengthConstraint::new(5, 1024),
-            channel_banner_constraint: InputValidationLengthConstraint::new(5, 1024),
-            channel_title_constraint: InputValidationLengthConstraint::new(5, 1024),
-        }),
+        content_wg: Some(content_working_group_config),
         proposals_codex: Some(ProposalsCodexConfig {
             set_validator_count_proposal_voting_period: cpcp
                 .set_validator_count_proposal_voting_period,

+ 1 - 0
runtime-modules/versioned-store-permissions/Cargo.toml

@@ -18,6 +18,7 @@ versioned-store = { package = 'pallet-versioned-store', default-features = false
 sp-io = { package = 'sp-io', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
 sp-core = { package = 'sp-core', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
 pallet-timestamp = { package = 'pallet-timestamp', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+common = { package = 'pallet-common', default-features = false, path = '../common'}
 
 [features]
 default = ['std']

+ 1 - 1
runtime-modules/versioned-store-permissions/src/mock.rs

@@ -3,6 +3,7 @@
 use crate::*;
 use crate::{Module, Trait};
 
+use common::constraints::InputValidationLengthConstraint;
 use frame_support::{impl_outer_origin, parameter_types};
 use sp_core::H256;
 use sp_runtime::{
@@ -10,7 +11,6 @@ use sp_runtime::{
     traits::{BlakeTwo256, IdentityLookup},
     Perbill,
 };
-use versioned_store::InputValidationLengthConstraint;
 
 impl_outer_origin! {
     pub enum Origin for Runtime {}

+ 1 - 1
runtime-modules/versioned-store/Cargo.toml

@@ -10,6 +10,7 @@ codec = { package = 'parity-scale-codec', version = '1.3.1', default-features =
 sp-std = { package = 'sp-std', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
 frame-support = { package = 'frame-support', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
 system = { package = 'frame-system', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+common = { package = 'pallet-common', default-features = false, path = '../common'}
 
 [dev-dependencies]
 sp-runtime = { package = 'sp-runtime', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
@@ -17,7 +18,6 @@ sp-io = { package = 'sp-io', default-features = false, git = 'https://github.com
 sp-core = { package = 'sp-core', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
 pallet-timestamp = { package = 'pallet-timestamp', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
 
-
 [features]
 default = ['std']
 std = [

+ 1 - 37
runtime-modules/versioned-store/src/lib.rs

@@ -15,6 +15,7 @@
 use serde::{Deserialize, Serialize};
 
 use codec::{Decode, Encode};
+use common::constraints::InputValidationLengthConstraint;
 use frame_support::{decl_event, decl_module, decl_storage, ensure};
 use sp_std::collections::btree_set::BTreeSet;
 use sp_std::vec;
@@ -67,43 +68,6 @@ const ERROR_VEC_PROP_IS_TOO_LONG: &str = "Vector propery is too long";
 const ERROR_INTERNAL_RPOP_DOES_NOT_MATCH_ITS_CLASS: &str =
     "Internal property does not match its class";
 
-/// Length constraint for input validation
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Default, Clone, PartialEq, Eq, Debug)]
-pub struct InputValidationLengthConstraint {
-    /// Minimum length
-    pub min: u16,
-
-    /// Difference between minimum length and max length.
-    /// While having max would have been more direct, this
-    /// way makes max < min unrepresentable semantically,
-    /// which is safer.
-    pub max_min_diff: u16,
-}
-
-impl InputValidationLengthConstraint {
-    /// Helper for computing max
-    pub fn max(&self) -> u16 {
-        self.min + self.max_min_diff
-    }
-
-    pub fn ensure_valid(
-        &self,
-        len: usize,
-        too_short_msg: &'static str,
-        too_long_msg: &'static str,
-    ) -> Result<(), &'static str> {
-        let length = len as u16;
-        if length < self.min {
-            Err(too_short_msg)
-        } else if length > self.max() {
-            Err(too_long_msg)
-        } else {
-            Ok(())
-        }
-    }
-}
-
 pub type ClassId = u64;
 pub type EntityId = u64;
 

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

@@ -208,6 +208,7 @@ fn genesis_constructor(
         versioned_store_cfg,
         versioned_store_permissions_cfg,
         data_directory_config,
+        content_config::empty_content_working_group_config(),
     )
 }