Explorar o código

runtime: Upgrace ‘version-store’ pallet.

Shamil Gadelshin %!s(int64=4) %!d(string=hai) anos
pai
achega
d19453ad63

+ 14 - 5
Cargo.lock

@@ -940,7 +940,6 @@ dependencies = [
  "pallet-timestamp",
  "parity-scale-codec",
  "serde",
- "sp-arithmetic",
  "sp-runtime",
 ]
 
@@ -953,7 +952,6 @@ dependencies = [
  "pallet-common",
  "parity-scale-codec",
  "sp-arithmetic",
- "sp-runtime",
 ]
 
 [[package]]
@@ -969,8 +967,6 @@ dependencies = [
  "sp-core",
  "sp-io",
  "sp-runtime",
- "sp-std",
- "sp-timestamp",
 ]
 
 [[package]]
@@ -1002,8 +998,21 @@ dependencies = [
  "sp-core",
  "sp-io",
  "sp-runtime",
+]
+
+[[package]]
+name = "pallet-versioned-store"
+version = "3.0.0"
+dependencies = [
+ "frame-support",
+ "frame-system",
+ "pallet-timestamp",
+ "parity-scale-codec",
+ "serde",
+ "sp-core",
+ "sp-io",
+ "sp-runtime",
  "sp-std",
- "sp-timestamp",
 ]
 
 [[package]]

+ 1 - 1
Cargo.toml

@@ -16,7 +16,7 @@ members = [
 #	"runtime-modules/stake",
 #	"runtime-modules/storage",
 	"runtime-modules/token-minting",
-#	"runtime-modules/versioned-store",
+	"runtime-modules/versioned-store",
 #	"runtime-modules/versioned-store-permissions",
 #	"runtime-modules/working-group",
 #	"node",

+ 14 - 35
runtime-modules/versioned-store/Cargo.toml

@@ -1,50 +1,29 @@
 [package]
-name = 'substrate-versioned-store'
-version = '1.0.1'
+name = 'pallet-versioned-store'
+version = '3.0.0'
 authors = ['Joystream contributors']
 edition = '2018'
 
 [dependencies]
-hex-literal = '0.1.0'
-serde = { version = '1.0', optional = true }
-serde_derive = { version = '1.0', optional = true }
-rstd = { package = 'sr-std', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-runtime-primitives = { package = 'sr-primitives', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-srml-support = { package = 'srml-support', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-srml-support-procedural = { package = 'srml-support-procedural', git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-system = { package = 'srml-system', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-balances = { package = 'srml-balances', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-codec = { package = 'parity-scale-codec', version = '1.0.0', default-features = false, features = ['derive'] }
-# https://users.rust-lang.org/t/failure-derive-compilation-error/39062
-quote = '<=1.0.2'
-
-[dependencies.timestamp]
-default_features = false
-git = 'https://github.com/paritytech/substrate.git'
-package = 'srml-timestamp'
-rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'
-
-[dependencies.runtime-io]
-default_features = false
-git = 'https://github.com/paritytech/substrate.git'
-package = 'sr-io'
-rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'
+serde = { version = "1.0.101", optional = true, features = ["derive"] }
+codec = { package = 'parity-scale-codec', version = '1.3.1', default-features = false, features = ['derive'] }
+rstd = { 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'}
 
 [dev-dependencies]
-runtime-io = { package = 'sr-io', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-primitives = { package = 'substrate-primitives', git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
+sp-runtime = { package = 'sp-runtime', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+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'}
+timestamp = { package = 'pallet-timestamp', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+
 
 [features]
 default = ['std']
 std = [
 	'serde',
-	'serde_derive',
 	'codec/std',
 	'rstd/std',
-	'runtime-io/std',
-	'runtime-primitives/std',
-	'srml-support/std',
+	'frame-support/std',
 	'system/std',
-	'balances/std',
-	'timestamp/std',
-]
+]

+ 1 - 1
runtime-modules/versioned-store/src/example.rs

@@ -3,7 +3,7 @@
 use super::*;
 use crate::mock::*;
 
-use srml_support::assert_ok;
+use frame_support::assert_ok;
 
 /// This example uses Class, Properties, Schema and Entity structures
 /// to describe the Staked podcast channel and its second episode.

+ 33 - 34
runtime-modules/versioned-store/src/lib.rs

@@ -12,17 +12,20 @@
 #![cfg_attr(not(feature = "std"), no_std)]
 
 #[cfg(feature = "std")]
-use serde_derive::{Deserialize, Serialize};
+use serde::{Deserialize, Serialize};
 
 use codec::{Decode, Encode};
+use frame_support::{decl_event, decl_module, decl_storage, ensure};
 use rstd::collections::btree_set::BTreeSet;
-use rstd::prelude::*;
-use srml_support::{decl_event, decl_module, decl_storage, dispatch, ensure};
 
 mod example;
 mod mock;
 mod tests;
 
+//TODO: Convert errors to the Substrate decl_error! macro.
+/// Result with string error message. This exists for backward compatibility purpose.
+pub type DispatchResult = Result<(), &'static str>;
+
 // Validation errors
 // --------------------------------------
 
@@ -135,7 +138,6 @@ pub struct Entity {
     /// Values for properties on class that are used by some schema used by this entity!
     /// Length is no more than Class.properties.
     pub values: Vec<ClassPropertyValue>,
-    // pub deleted: bool,
 }
 
 /// A schema defines what properties describe an entity
@@ -253,24 +255,24 @@ decl_storage! {
 
     trait Store for Module<T: Trait> as VersionedStore {
 
-        pub ClassById get(class_by_id) config(): map ClassId => Class;
+        pub ClassById get(fn class_by_id) config(): map hasher(blake2_128_concat) ClassId => Class;
 
-        pub EntityById get(entity_by_id) config(): map EntityId => Entity;
+        pub EntityById get(fn entity_by_id) config(): map hasher(blake2_128_concat) EntityId => Entity;
 
-        pub NextClassId get(next_class_id) config(): ClassId;
+        pub NextClassId get(fn next_class_id) config(): ClassId;
 
-        pub NextEntityId get(next_entity_id) config(): EntityId;
+        pub NextEntityId get(fn next_entity_id) config(): EntityId;
 
-        pub PropertyNameConstraint get(property_name_constraint)
+        pub PropertyNameConstraint get(fn property_name_constraint)
             config(): InputValidationLengthConstraint;
 
-        pub PropertyDescriptionConstraint get(property_description_constraint)
+        pub PropertyDescriptionConstraint get(fn property_description_constraint)
             config(): InputValidationLengthConstraint;
 
-        pub ClassNameConstraint get(class_name_constraint)
+        pub ClassNameConstraint get(fn class_name_constraint)
             config(): InputValidationLengthConstraint;
 
-        pub ClassDescriptionConstraint get(class_description_constraint)
+        pub ClassDescriptionConstraint get(fn class_description_constraint)
             config(): InputValidationLengthConstraint;
     }
 }
@@ -375,7 +377,7 @@ impl<T: Trait> Module<T> {
 
         // Check validity of Internal(ClassId) for new_properties.
         let has_unknown_internal_id = new_properties.iter().any(|prop| match prop.prop_type {
-            PropertyType::Internal(other_class_id) => !ClassById::exists(other_class_id),
+            PropertyType::Internal(other_class_id) => !ClassById::contains_key(other_class_id),
             _ => false,
         });
         ensure!(
@@ -434,7 +436,7 @@ impl<T: Trait> Module<T> {
         entity_id: EntityId,
         schema_id: u16,
         property_values: Vec<ClassPropertyValue>,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         Self::ensure_known_entity_id(entity_id)?;
 
         let (entity, class) = Self::get_entity_and_class(entity_id);
@@ -521,7 +523,7 @@ impl<T: Trait> Module<T> {
     pub fn update_entity_property_values(
         entity_id: EntityId,
         new_property_values: Vec<ClassPropertyValue>,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         Self::ensure_known_entity_id(entity_id)?;
 
         let (entity, class) = Self::get_entity_and_class(entity_id);
@@ -580,7 +582,7 @@ impl<T: Trait> Module<T> {
     }
 
     // Commented out for now <- requested by Bedeho.
-    // pub fn delete_entity(entity_id: EntityId) -> dispatch::Result {
+    // pub fn delete_entity(entity_id: EntityId) -> DispatchResult {
     //     Self::ensure_known_entity_id(entity_id)?;
 
     //     let is_deleted = EntityById::get(entity_id).deleted;
@@ -597,17 +599,17 @@ impl<T: Trait> Module<T> {
     // Helper functions:
     // ----------------------------------------------------------------
 
-    pub fn ensure_known_class_id(class_id: ClassId) -> dispatch::Result {
-        ensure!(ClassById::exists(class_id), ERROR_CLASS_NOT_FOUND);
+    pub fn ensure_known_class_id(class_id: ClassId) -> DispatchResult {
+        ensure!(ClassById::contains_key(class_id), ERROR_CLASS_NOT_FOUND);
         Ok(())
     }
 
-    pub fn ensure_known_entity_id(entity_id: EntityId) -> dispatch::Result {
-        ensure!(EntityById::exists(entity_id), ERROR_ENTITY_NOT_FOUND);
+    pub fn ensure_known_entity_id(entity_id: EntityId) -> DispatchResult {
+        ensure!(EntityById::contains_key(entity_id), ERROR_ENTITY_NOT_FOUND);
         Ok(())
     }
 
-    pub fn ensure_valid_internal_prop(value: PropertyValue, prop: Property) -> dispatch::Result {
+    pub fn ensure_valid_internal_prop(value: PropertyValue, prop: Property) -> DispatchResult {
         match (value, prop.prop_type) {
             (PV::Internal(entity_id), PT::Internal(class_id)) => {
                 Self::ensure_known_class_id(class_id)?;
@@ -625,7 +627,7 @@ impl<T: Trait> Module<T> {
 
     pub fn is_unknown_internal_entity_id(id: PropertyValue) -> bool {
         if let PropertyValue::Internal(entity_id) = id {
-            !EntityById::exists(entity_id)
+            !EntityById::contains_key(entity_id)
         } else {
             false
         }
@@ -637,10 +639,7 @@ impl<T: Trait> Module<T> {
         (entity, class)
     }
 
-    pub fn ensure_property_value_is_valid(
-        value: PropertyValue,
-        prop: Property,
-    ) -> dispatch::Result {
+    pub fn ensure_property_value_is_valid(value: PropertyValue, prop: Property) -> DispatchResult {
         Self::ensure_prop_value_matches_its_type(value.clone(), prop.clone())?;
         Self::ensure_valid_internal_prop(value.clone(), prop.clone())?;
         Self::validate_max_len_if_text_prop(value.clone(), prop.clone())?;
@@ -648,14 +647,14 @@ impl<T: Trait> Module<T> {
         Ok(())
     }
 
-    pub fn validate_max_len_if_text_prop(value: PropertyValue, prop: Property) -> dispatch::Result {
+    pub fn validate_max_len_if_text_prop(value: PropertyValue, prop: Property) -> DispatchResult {
         match (value, prop.prop_type) {
             (PV::Text(text), PT::Text(max_len)) => Self::validate_max_len_of_text(text, max_len),
             _ => Ok(()),
         }
     }
 
-    pub fn validate_max_len_of_text(text: Vec<u8>, max_len: u16) -> dispatch::Result {
+    pub fn validate_max_len_of_text(text: Vec<u8>, max_len: u16) -> DispatchResult {
         if text.len() <= max_len as usize {
             Ok(())
         } else {
@@ -667,7 +666,7 @@ impl<T: Trait> Module<T> {
     pub fn validate_max_len_if_vec_prop(
         value: PropertyValue,
         prop: Property,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
 
         fn validate_vec_len<T>(vec: Vec<T>, max_len: u16) -> bool {
             vec.len() <= max_len as usize
@@ -724,7 +723,7 @@ impl<T: Trait> Module<T> {
     pub fn ensure_prop_value_matches_its_type(
         value: PropertyValue,
         prop: Property,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         if Self::does_prop_value_match_type(value, prop) {
             Ok(())
         } else {
@@ -774,7 +773,7 @@ impl<T: Trait> Module<T> {
         }
     }
 
-    pub fn ensure_property_name_is_valid(text: &[u8]) -> dispatch::Result {
+    pub fn ensure_property_name_is_valid(text: &[u8]) -> DispatchResult {
         PropertyNameConstraint::get().ensure_valid(
             text.len(),
             ERROR_PROPERTY_NAME_TOO_SHORT,
@@ -782,7 +781,7 @@ impl<T: Trait> Module<T> {
         )
     }
 
-    pub fn ensure_property_description_is_valid(text: &[u8]) -> dispatch::Result {
+    pub fn ensure_property_description_is_valid(text: &[u8]) -> DispatchResult {
         PropertyDescriptionConstraint::get().ensure_valid(
             text.len(),
             ERROR_PROPERTY_DESCRIPTION_TOO_SHORT,
@@ -790,7 +789,7 @@ impl<T: Trait> Module<T> {
         )
     }
 
-    pub fn ensure_class_name_is_valid(text: &[u8]) -> dispatch::Result {
+    pub fn ensure_class_name_is_valid(text: &[u8]) -> DispatchResult {
         ClassNameConstraint::get().ensure_valid(
             text.len(),
             ERROR_CLASS_NAME_TOO_SHORT,
@@ -798,7 +797,7 @@ impl<T: Trait> Module<T> {
         )
     }
 
-    pub fn ensure_class_description_is_valid(text: &[u8]) -> dispatch::Result {
+    pub fn ensure_class_description_is_valid(text: &[u8]) -> DispatchResult {
         ClassDescriptionConstraint::get().ensure_valid(
             text.len(),
             ERROR_CLASS_DESCRIPTION_TOO_SHORT,

+ 15 - 14
runtime-modules/versioned-store/src/mock.rs

@@ -3,13 +3,13 @@
 use crate::*;
 use crate::{GenesisConfig, Module, Trait};
 
-use primitives::H256;
-use runtime_primitives::{
+use frame_support::{assert_err, assert_ok, impl_outer_origin, parameter_types};
+use sp_core::H256;
+use sp_runtime::{
     testing::Header,
     traits::{BlakeTwo256, IdentityLookup},
     Perbill,
 };
-use srml_support::{assert_err, assert_ok, impl_outer_origin, parameter_types};
 
 impl_outer_origin! {
     pub enum Origin for Runtime {}
@@ -27,10 +27,11 @@ parameter_types! {
 }
 
 impl system::Trait for Runtime {
+    type BaseCallFilter = ();
     type Origin = Origin;
+    type Call = ();
     type Index = u64;
     type BlockNumber = u64;
-    type Call = ();
     type Hash = H256;
     type Hashing = BlakeTwo256;
     type AccountId = u64;
@@ -39,9 +40,17 @@ impl system::Trait for Runtime {
     type Event = ();
     type BlockHashCount = BlockHashCount;
     type MaximumBlockWeight = MaximumBlockWeight;
+    type DbWeight = ();
+    type BlockExecutionWeight = ();
+    type ExtrinsicBaseWeight = ();
+    type MaximumExtrinsicWeight = ();
     type MaximumBlockLength = MaximumBlockLength;
     type AvailableBlockRatio = AvailableBlockRatio;
     type Version = ();
+    type ModuleToIndex = ();
+    type AccountData = ();
+    type OnNewAccount = ();
+    type OnKilledAccount = ();
 }
 
 impl timestamp::Trait for Runtime {
@@ -60,15 +69,9 @@ pub const UNKNOWN_ENTITY_ID: EntityId = 222;
 
 pub const UNKNOWN_PROP_ID: u16 = 333;
 
-// pub const UNKNOWN_SCHEMA_ID: u16 = 444;
-
 pub const SCHEMA_ID_0: u16 = 0;
 pub const SCHEMA_ID_1: u16 = 1;
 
-// pub fn generate_text(len: usize) -> Vec<u8> {
-//     vec![b'x'; len]
-// }
-
 pub fn good_class_name() -> Vec<u8> {
     b"Name of a class".to_vec()
 }
@@ -206,7 +209,7 @@ pub fn assert_class_schemas(class_id: ClassId, expected_schema_prop_ids: Vec<Vec
     assert_eq!(class.schemas, schemas);
 }
 
-pub fn assert_entity_not_found(result: dispatch::Result) {
+pub fn assert_entity_not_found(result: crate::DispatchResult) {
     assert_err!(result, ERROR_ENTITY_NOT_FOUND);
 }
 
@@ -238,7 +241,7 @@ pub fn default_genesis_config() -> GenesisConfig {
     }
 }
 
-fn build_test_externalities(config: GenesisConfig) -> runtime_io::TestExternalities {
+fn build_test_externalities(config: GenesisConfig) -> sp_io::TestExternalities {
     let mut t = system::GenesisConfig::default()
         .build_storage::<Runtime>()
         .unwrap();
@@ -253,7 +256,5 @@ pub fn with_test_externalities<R, F: FnOnce() -> R>(f: F) -> R {
     build_test_externalities(config).execute_with(f)
 }
 
-// pub type System = system::Module;
-
 /// Export module on a test runtime
 pub type TestModule = Module<Runtime>;

+ 1 - 1
runtime-modules/versioned-store/src/tests.rs

@@ -3,7 +3,7 @@
 use super::*;
 use crate::mock::*;
 
-use srml_support::{assert_err, assert_ok};
+use frame_support::{assert_err, assert_ok};
 
 // Create class
 // --------------------------------------