Browse Source

Add StorageSystem trait implementation, move types to the common crate

iorveth 4 years ago
parent
commit
f045fa5c86

+ 119 - 90
Cargo.lock

@@ -1115,7 +1115,7 @@ dependencies = [
  "sp-io",
  "sp-runtime",
  "sp-runtime-interface",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -1147,7 +1147,7 @@ dependencies = [
  "serde",
  "sp-io",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
  "sp-tracing",
 ]
 
@@ -1159,7 +1159,7 @@ dependencies = [
  "parity-scale-codec",
  "serde",
  "sp-core",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -1177,13 +1177,13 @@ dependencies = [
  "paste",
  "serde",
  "smallvec 1.4.1",
- "sp-arithmetic",
+ "sp-arithmetic 2.0.0-rc4",
  "sp-core",
  "sp-inherents",
  "sp-io",
  "sp-runtime",
  "sp-state-machine",
- "sp-std",
+ "sp-std 2.0.0-rc4",
  "sp-tracing",
 ]
 
@@ -1232,7 +1232,7 @@ dependencies = [
  "sp-core",
  "sp-io",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
  "sp-version",
 ]
 
@@ -1247,7 +1247,7 @@ dependencies = [
  "parity-scale-codec",
  "sp-core",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -2101,7 +2101,7 @@ dependencies = [
  "serde",
  "sp-api",
  "sp-application-crypto",
- "sp-arithmetic",
+ "sp-arithmetic 2.0.0-rc4",
  "sp-authority-discovery",
  "sp-block-builder",
  "sp-consensus-babe",
@@ -2111,7 +2111,7 @@ dependencies = [
  "sp-runtime",
  "sp-session",
  "sp-staking",
- "sp-std",
+ "sp-std 2.0.0-rc4",
  "sp-transaction-pool",
  "sp-version",
  "strum 0.19.2",
@@ -3219,7 +3219,7 @@ dependencies = [
  "sp-application-crypto",
  "sp-authority-discovery",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -3234,7 +3234,7 @@ dependencies = [
  "sp-authorship",
  "sp-inherents",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -3255,7 +3255,7 @@ dependencies = [
  "sp-io",
  "sp-runtime",
  "sp-staking",
- "sp-std",
+ "sp-std 2.0.0-rc4",
  "sp-timestamp",
 ]
 
@@ -3270,7 +3270,7 @@ dependencies = [
  "parity-scale-codec",
  "serde",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -3286,7 +3286,7 @@ dependencies = [
  "sp-core",
  "sp-io",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -3298,6 +3298,7 @@ dependencies = [
  "pallet-timestamp",
  "parity-scale-codec",
  "serde",
+ "sp-arithmetic 2.0.0",
  "sp-runtime",
  "strum 0.19.2",
  "strum_macros 0.19.2",
@@ -3311,11 +3312,11 @@ dependencies = [
  "frame-system",
  "parity-scale-codec",
  "serde",
- "sp-arithmetic",
+ "sp-arithmetic 2.0.0-rc4",
  "sp-core",
  "sp-io",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -3331,7 +3332,7 @@ dependencies = [
  "sp-finality-tracker",
  "sp-inherents",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -3344,11 +3345,11 @@ dependencies = [
  "pallet-timestamp",
  "parity-scale-codec",
  "serde",
- "sp-arithmetic",
+ "sp-arithmetic 2.0.0-rc4",
  "sp-core",
  "sp-io",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -3365,11 +3366,11 @@ dependencies = [
  "pallet-token-mint",
  "parity-scale-codec",
  "serde",
- "sp-arithmetic",
+ "sp-arithmetic 2.0.0-rc4",
  "sp-core",
  "sp-io",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -3389,7 +3390,7 @@ dependencies = [
  "sp-runtime",
  "sp-session",
  "sp-staking",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -3403,11 +3404,11 @@ dependencies = [
  "pallet-stake",
  "parity-scale-codec",
  "serde",
- "sp-arithmetic",
+ "sp-arithmetic 2.0.0-rc4",
  "sp-core",
  "sp-io",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -3427,7 +3428,7 @@ dependencies = [
  "sp-io",
  "sp-runtime",
  "sp-staking",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -3441,11 +3442,11 @@ dependencies = [
  "pallet-timestamp",
  "parity-scale-codec",
  "serde",
- "sp-arithmetic",
+ "sp-arithmetic 2.0.0-rc4",
  "sp-core",
  "sp-io",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -3456,8 +3457,8 @@ dependencies = [
  "frame-system",
  "pallet-common",
  "parity-scale-codec",
- "sp-arithmetic",
- "sp-std",
+ "sp-arithmetic 2.0.0-rc4",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -3472,7 +3473,7 @@ dependencies = [
  "serde",
  "sp-runtime",
  "sp-staking",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -3493,7 +3494,7 @@ dependencies = [
  "parity-scale-codec",
  "sp-runtime",
  "sp-staking",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -3518,12 +3519,12 @@ dependencies = [
  "pallet-working-group",
  "parity-scale-codec",
  "serde",
- "sp-arithmetic",
+ "sp-arithmetic 2.0.0-rc4",
  "sp-core",
  "sp-io",
  "sp-runtime",
  "sp-staking",
- "sp-std",
+ "sp-std 2.0.0-rc4",
  "strum 0.19.2",
 ]
 
@@ -3542,7 +3543,7 @@ dependencies = [
  "sp-core",
  "sp-io",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -3559,11 +3560,11 @@ dependencies = [
  "pallet-timestamp",
  "parity-scale-codec",
  "serde",
- "sp-arithmetic",
+ "sp-arithmetic 2.0.0-rc4",
  "sp-core",
  "sp-io",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -3576,7 +3577,7 @@ dependencies = [
  "parity-scale-codec",
  "safe-mix",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -3588,7 +3589,7 @@ dependencies = [
  "pallet-balances",
  "pallet-token-mint",
  "parity-scale-codec",
- "sp-arithmetic",
+ "sp-arithmetic 2.0.0-rc4",
  "sp-core",
  "sp-io",
  "sp-runtime",
@@ -3614,7 +3615,7 @@ dependencies = [
  "sp-core",
  "sp-io",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -3633,7 +3634,7 @@ dependencies = [
  "sp-runtime",
  "sp-session",
  "sp-staking",
- "sp-std",
+ "sp-std 2.0.0-rc4",
  "sp-trie",
 ]
 
@@ -3648,7 +3649,7 @@ dependencies = [
  "pallet-session",
  "pallet-staking",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -3660,11 +3661,11 @@ dependencies = [
  "pallet-balances",
  "pallet-timestamp",
  "parity-scale-codec",
- "sp-arithmetic",
+ "sp-arithmetic 2.0.0-rc4",
  "sp-core",
  "sp-io",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -3685,7 +3686,7 @@ dependencies = [
  "sp-npos-elections",
  "sp-runtime",
  "sp-staking",
- "sp-std",
+ "sp-std 2.0.0-rc4",
  "static_assertions",
 ]
 
@@ -3717,11 +3718,11 @@ dependencies = [
  "pallet-working-group",
  "parity-scale-codec",
  "serde",
- "sp-arithmetic",
+ "sp-arithmetic 2.0.0-rc4",
  "sp-core",
  "sp-io",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -3735,7 +3736,7 @@ dependencies = [
  "serde",
  "sp-io",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -3752,7 +3753,7 @@ dependencies = [
  "sp-inherents",
  "sp-io",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
  "sp-timestamp",
 ]
 
@@ -3764,7 +3765,7 @@ dependencies = [
  "frame-system",
  "pallet-balances",
  "parity-scale-codec",
- "sp-arithmetic",
+ "sp-arithmetic 2.0.0-rc4",
  "sp-core",
  "sp-io",
  "sp-runtime",
@@ -3782,7 +3783,7 @@ dependencies = [
  "serde",
  "smallvec 1.4.1",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -3813,7 +3814,7 @@ dependencies = [
  "serde",
  "sp-api",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -3829,7 +3830,7 @@ dependencies = [
  "sp-core",
  "sp-io",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -3848,11 +3849,11 @@ dependencies = [
  "pallet-token-mint",
  "parity-scale-codec",
  "serde",
- "sp-arithmetic",
+ "sp-arithmetic 2.0.0-rc4",
  "sp-core",
  "sp-io",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -5019,7 +5020,7 @@ dependencies = [
  "sp-keyring",
  "sp-runtime",
  "sp-state-machine",
- "sp-std",
+ "sp-std 2.0.0-rc4",
  "sp-storage",
  "sp-transaction-pool",
  "sp-trie",
@@ -5268,7 +5269,7 @@ dependencies = [
  "serde_json",
  "sp-api",
  "sp-application-crypto",
- "sp-arithmetic",
+ "sp-arithmetic 2.0.0-rc4",
  "sp-blockchain",
  "sp-consensus",
  "sp-core",
@@ -5389,7 +5390,7 @@ dependencies = [
  "slog",
  "slog_derive",
  "smallvec 0.6.13",
- "sp-arithmetic",
+ "sp-arithmetic 2.0.0-rc4",
  "sp-blockchain",
  "sp-consensus",
  "sp-core",
@@ -6075,7 +6076,7 @@ dependencies = [
  "derive_more",
  "log",
  "sp-core",
- "sp-std",
+ "sp-std 2.0.0-rc4",
  "sp-wasm-interface",
 ]
 
@@ -6090,7 +6091,7 @@ dependencies = [
  "sp-core",
  "sp-runtime",
  "sp-state-machine",
- "sp-std",
+ "sp-std 2.0.0-rc4",
  "sp-version",
 ]
 
@@ -6115,7 +6116,7 @@ dependencies = [
  "serde",
  "sp-core",
  "sp-io",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -6127,8 +6128,21 @@ dependencies = [
  "num-traits 0.2.11",
  "parity-scale-codec",
  "serde",
- "sp-debug-derive",
- "sp-std",
+ "sp-debug-derive 2.0.0-rc4",
+ "sp-std 2.0.0-rc4",
+]
+
+[[package]]
+name = "sp-arithmetic"
+version = "2.0.0"
+source = "git+https://github.com/paritytech/substrate.git?rev=a200cdb93c6af5763b9c7bf313fa708764ac88ca#a200cdb93c6af5763b9c7bf313fa708764ac88ca"
+dependencies = [
+ "integer-sqrt",
+ "num-traits 0.2.11",
+ "parity-scale-codec",
+ "serde",
+ "sp-debug-derive 2.0.0",
+ "sp-std 2.0.0",
 ]
 
 [[package]]
@@ -6140,7 +6154,7 @@ dependencies = [
  "sp-api",
  "sp-application-crypto",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -6151,7 +6165,7 @@ dependencies = [
  "parity-scale-codec",
  "sp-inherents",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -6163,7 +6177,7 @@ dependencies = [
  "sp-api",
  "sp-inherents",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -6208,7 +6222,7 @@ dependencies = [
  "sp-inherents",
  "sp-runtime",
  "sp-state-machine",
- "sp-std",
+ "sp-std 2.0.0-rc4",
  "sp-utils",
  "sp-version",
  "substrate-prometheus-endpoint",
@@ -6225,7 +6239,7 @@ dependencies = [
  "sp-application-crypto",
  "sp-inherents",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
  "sp-timestamp",
 ]
 
@@ -6243,7 +6257,7 @@ dependencies = [
  "sp-core",
  "sp-inherents",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
  "sp-timestamp",
 ]
 
@@ -6256,7 +6270,7 @@ dependencies = [
  "schnorrkel",
  "sp-core",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -6288,10 +6302,10 @@ dependencies = [
  "schnorrkel",
  "serde",
  "sha2 0.8.1",
- "sp-debug-derive",
+ "sp-debug-derive 2.0.0-rc4",
  "sp-externalities",
  "sp-runtime-interface",
- "sp-std",
+ "sp-std 2.0.0-rc4",
  "sp-storage",
  "substrate-bip39",
  "tiny-bip39",
@@ -6320,6 +6334,16 @@ dependencies = [
  "syn 1.0.17",
 ]
 
+[[package]]
+name = "sp-debug-derive"
+version = "2.0.0"
+source = "git+https://github.com/paritytech/substrate.git?rev=a200cdb93c6af5763b9c7bf313fa708764ac88ca#a200cdb93c6af5763b9c7bf313fa708764ac88ca"
+dependencies = [
+ "proc-macro2",
+ "quote 1.0.7",
+ "syn 1.0.17",
+]
+
 [[package]]
 name = "sp-externalities"
 version = "0.8.0-rc4"
@@ -6327,7 +6351,7 @@ source = "git+https://github.com/paritytech/substrate.git?rev=00768a1f21a579c478
 dependencies = [
  "environmental",
  "parity-scale-codec",
- "sp-std",
+ "sp-std 2.0.0-rc4",
  "sp-storage",
 ]
 
@@ -6344,7 +6368,7 @@ dependencies = [
  "sp-application-crypto",
  "sp-core",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -6354,7 +6378,7 @@ source = "git+https://github.com/paritytech/substrate.git?rev=00768a1f21a579c478
 dependencies = [
  "parity-scale-codec",
  "sp-inherents",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -6366,7 +6390,7 @@ dependencies = [
  "parity-scale-codec",
  "parking_lot 0.10.2",
  "sp-core",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -6384,7 +6408,7 @@ dependencies = [
  "sp-externalities",
  "sp-runtime-interface",
  "sp-state-machine",
- "sp-std",
+ "sp-std 2.0.0-rc4",
  "sp-tracing",
  "sp-trie",
  "sp-wasm-interface",
@@ -6408,9 +6432,9 @@ source = "git+https://github.com/paritytech/substrate.git?rev=00768a1f21a579c478
 dependencies = [
  "parity-scale-codec",
  "serde",
- "sp-arithmetic",
+ "sp-arithmetic 2.0.0-rc4",
  "sp-npos-elections-compact",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -6467,11 +6491,11 @@ dependencies = [
  "rand 0.7.3",
  "serde",
  "sp-application-crypto",
- "sp-arithmetic",
+ "sp-arithmetic 2.0.0-rc4",
  "sp-core",
  "sp-inherents",
  "sp-io",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -6483,7 +6507,7 @@ dependencies = [
  "primitive-types",
  "sp-externalities",
  "sp-runtime-interface-proc-macro",
- "sp-std",
+ "sp-std 2.0.0-rc4",
  "sp-tracing",
  "sp-wasm-interface",
  "static_assertions",
@@ -6520,7 +6544,7 @@ dependencies = [
  "sp-core",
  "sp-runtime",
  "sp-staking",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -6530,7 +6554,7 @@ source = "git+https://github.com/paritytech/substrate.git?rev=00768a1f21a579c478
 dependencies = [
  "parity-scale-codec",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -6559,6 +6583,11 @@ name = "sp-std"
 version = "2.0.0-rc4"
 source = "git+https://github.com/paritytech/substrate.git?rev=00768a1f21a579c478fe5d4f51e1fa71f7db9fd4#00768a1f21a579c478fe5d4f51e1fa71f7db9fd4"
 
+[[package]]
+name = "sp-std"
+version = "2.0.0"
+source = "git+https://github.com/paritytech/substrate.git?rev=a200cdb93c6af5763b9c7bf313fa708764ac88ca#a200cdb93c6af5763b9c7bf313fa708764ac88ca"
+
 [[package]]
 name = "sp-storage"
 version = "2.0.0-rc4"
@@ -6567,8 +6596,8 @@ dependencies = [
  "impl-serde 0.2.3",
  "ref-cast",
  "serde",
- "sp-debug-derive",
- "sp-std",
+ "sp-debug-derive 2.0.0-rc4",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -6581,7 +6610,7 @@ dependencies = [
  "sp-api",
  "sp-inherents",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
  "wasm-timer",
 ]
 
@@ -6620,7 +6649,7 @@ dependencies = [
  "memory-db",
  "parity-scale-codec",
  "sp-core",
- "sp-std",
+ "sp-std 2.0.0-rc4",
  "trie-db",
  "trie-root",
 ]
@@ -6646,7 +6675,7 @@ dependencies = [
  "parity-scale-codec",
  "serde",
  "sp-runtime",
- "sp-std",
+ "sp-std 2.0.0-rc4",
 ]
 
 [[package]]
@@ -6656,7 +6685,7 @@ source = "git+https://github.com/paritytech/substrate.git?rev=00768a1f21a579c478
 dependencies = [
  "impl-trait-for-tuples",
  "parity-scale-codec",
- "sp-std",
+ "sp-std 2.0.0-rc4",
  "wasmi",
 ]
 
@@ -6912,7 +6941,7 @@ dependencies = [
  "sp-runtime",
  "sp-runtime-interface",
  "sp-session",
- "sp-std",
+ "sp-std 2.0.0-rc4",
  "sp-transaction-pool",
  "sp-trie",
  "sp-version",

+ 2 - 0
runtime-modules/common/Cargo.toml

@@ -13,6 +13,7 @@ sp-runtime = { package = 'sp-runtime', default-features = false, git = 'https://
 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'}
 pallet-timestamp = { package = 'pallet-timestamp', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+sp-arithmetic = { package = 'sp-arithmetic', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'a200cdb93c6af5763b9c7bf313fa708764ac88ca'}
 
 [features]
 default = ['std']
@@ -22,6 +23,7 @@ std = [
 	'strum_macros',
 	'codec/std',
 	'sp-runtime/std',
+	'sp-arithmetic/std',
 	'frame-support/std',
 	'system/std',
 	'pallet-timestamp/std',

+ 81 - 1
runtime-modules/common/src/lib.rs

@@ -5,11 +5,91 @@ pub mod constraints;
 pub mod currency;
 pub mod origin;
 pub mod working_group;
+pub mod storage;
 
-use codec::{Decode, Encode};
+use codec::{Decode, Codec, Encode};
 #[cfg(feature = "std")]
 use serde::{Deserialize, Serialize};
 
+use frame_support::Parameter;
+use sp_arithmetic::traits::BaseArithmetic;
+use sp_runtime::traits::{MaybeSerialize, Member};
+
+/// Member id type alias
+pub type MemberId<T> = <T as Trait>::MemberId;
+
+/// Actor id type alias
+pub type ActorId<T> = <T as Trait>::ActorId;
+
+/// Generic trait for membership dependent pallets.
+pub trait Trait: system::Trait {
+    /// Describes the common type for the members.
+    type MemberId: Parameter
+        + Member
+        + BaseArithmetic
+        + Codec
+        + Default
+        + Copy
+        + MaybeSerialize
+        + Ord
+        + PartialEq;
+
+    /// Describes the common type for the working group members (workers).
+    type ActorId: Parameter
+        + Member
+        + BaseArithmetic
+        + Codec
+        + Default
+        + Copy
+        + MaybeSerialize
+        + Ord
+        + PartialEq;
+
+    /// Channel id representation
+    type ChannelId: Parameter
+        + Member
+        + BaseArithmetic
+        + Codec
+        + Default
+        + Copy
+        + MaybeSerialize
+        + Ord
+        + PartialEq;
+
+    /// DAO id.
+    type DAOId: Parameter
+        + Member
+        + BaseArithmetic
+        + Codec
+        + Default
+        + Copy
+        + MaybeSerialize
+        + Ord
+        + PartialEq;
+        
+    /// Content id.
+    type ContentId: Parameter
+        + Member
+        + BaseArithmetic
+        + Codec
+        + Default
+        + Copy
+        + MaybeSerialize
+        + Ord
+        + PartialEq;
+
+    /// DAO object type id.
+    type DataObjectTypeId: Parameter
+        + Member
+        + BaseArithmetic
+        + Codec
+        + Default
+        + Copy
+        + MaybeSerialize
+        + Ord
+        + PartialEq;
+}
+
 /// Defines time in both block number and substrate time abstraction.
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
 #[derive(Clone, Encode, Decode, PartialEq, Eq, Debug, Default)]

+ 34 - 69
runtime-modules/storage/src/data_directory.rs

@@ -24,8 +24,7 @@
 use codec::{Decode, Encode};
 use frame_support::dispatch::DispatchResult;
 use frame_support::traits::Get;
-use frame_support::{decl_error, decl_event, decl_module, decl_storage, ensure, Parameter};
-use sp_runtime::traits::{MaybeSerialize, Member};
+use frame_support::{decl_error, decl_event, decl_module, decl_storage, ensure};
 use sp_std::collections::btree_map::BTreeMap;
 use sp_std::vec::Vec;
 use system::ensure_root;
@@ -34,17 +33,12 @@ use system::ensure_root;
 use serde::{Deserialize, Serialize};
 
 use common::origin::ActorOriginValidator;
+pub use common::storage::{AbstractStorageObjectOwner, ContentParameters, StorageObjectOwner};
 pub(crate) use common::BlockAndTime;
 
 use crate::data_object_type_registry;
 use crate::data_object_type_registry::IsActiveDataObjectType;
-use crate::{MemberId, StorageProviderId, StorageWorkingGroup, StorageWorkingGroupInstance};
-
-// Temporary representation.
-type ChannelId = u64;
-
-// Temporary representation.
-type DAOId = u64;
+use crate::*;
 
 /// The _Data directory_ main _Trait_.
 pub trait Trait:
@@ -53,13 +47,11 @@ pub trait Trait:
     + data_object_type_registry::Trait
     + membership::Trait
     + working_group::Trait<StorageWorkingGroupInstance>
+    + common::Trait
 {
     /// _Data directory_ event type.
     type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
 
-    /// Content id.
-    type ContentId: Parameter + Member + MaybeSerialize + Copy + Ord + Default;
-
     /// Provides random storage provider id.
     type StorageProviderHelper: StorageProviderHelper<Self>;
 
@@ -95,31 +87,6 @@ decl_error! {
     }
 }
 
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Clone, Encode, Decode, PartialEq, Eq, Debug)]
-pub enum WorkinGroupType {
-    ContentDirectory,
-    Builders,
-    StorageProviders,
-}
-
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Clone, Encode, Decode, PartialEq, Eq, Debug)]
-pub enum AbstractStorageObjectOwner<ChannelId, DAOId> {
-    Channel(ChannelId), // acts through content directory module, where again DAOs can own channels for example
-    DAO(DAOId),         // acts through upcoming `content_finance` module
-    Council,            // acts through proposal system
-    WorkingGroup(WorkinGroupType), // acts through new extrinsic in working group
-}
-
-// New owner type for storage object struct
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Clone, Encode, Decode, PartialEq, Eq, Debug)]
-pub enum StorageObjectOwner<MemberId, ChannelId, DAOId> {
-    Member(MemberId),
-    AbstractStorageObjectOwner(AbstractStorageObjectOwner<ChannelId, DAOId>),
-}
-
 /// The decision of the storage provider when it acts as liaison.
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
 #[derive(Clone, Encode, Decode, PartialEq, Debug)]
@@ -143,11 +110,11 @@ impl Default for LiaisonJudgement {
 /// Alias for DataObjectInternal
 pub type DataObject<T> = DataObjectInternal<
     MemberId<T>,
-    ChannelId,
-    DAOId,
+    ChannelId<T>,
+    DAOId<T>,
     <T as system::Trait>::BlockNumber,
     <T as pallet_timestamp::Trait>::Moment,
-    <T as data_object_type_registry::Trait>::DataObjectTypeId,
+    DataObjectTypeId<T>,
     StorageProviderId<T>,
 >;
 
@@ -185,21 +152,13 @@ pub struct DataObjectInternal<
     pub ipfs_content_id: Vec<u8>,
 }
 
-#[derive(Clone, Encode, Decode, PartialEq, Eq, Debug)]
-pub struct ContentParameters<ContentId, DataObjectTypeId> {
-    pub content_id: ContentId,
-    pub type_id: DataObjectTypeId,
-    pub size: u64,
-    pub ipfs_content_id: Vec<u8>,
-}
-
 /// A map collection of unique DataObjects keyed by the ContentId
-pub type DataObjectsMap<T> = BTreeMap<<T as Trait>::ContentId, DataObject<T>>;
+pub type DataObjectsMap<T> = BTreeMap<ContentId<T>, DataObject<T>>;
 
 decl_storage! {
     trait Store for Module<T: Trait> as DataDirectory {
         /// List of ids known to the system.
-        pub KnownContentIds get(fn known_content_ids) config(): Vec<T::ContentId> = Vec::new();
+        pub KnownContentIds get(fn known_content_ids) config(): Vec<ContentId<T>> = Vec::new();
 
         /// Maps data objects by their content id.
         pub DataObjectByContentId get(fn data_object_by_content_id) config():
@@ -210,10 +169,10 @@ decl_storage! {
 decl_event! {
     /// _Data directory_ events
     pub enum Event<T> where
-        <T as Trait>::ContentId,
-        StorageObjectOwner = StorageObjectOwner<MemberId<T>, ChannelId, DAOId>,
+        StorageObjectOwner = StorageObjectOwner<MemberId<T>, ChannelId<T>, DAOId<T>>,
         StorageProviderId = StorageProviderId<T>,
-        Content = Vec<ContentParameters<<T as Trait>::ContentId, <T as data_object_type_registry::Trait>::DataObjectTypeId>>,
+        Content = Vec<ContentParameters<ContentId<T>, DataObjectTypeId<T>>>,
+        ContentId = ContentId<T>,
     {
         /// Emits on adding of the content.
         /// Params:
@@ -253,17 +212,17 @@ decl_module! {
         pub fn add_content_as_member(
             origin,
             member_id: MemberId<T>,
-            content: Vec<ContentParameters<T::ContentId, <T as data_object_type_registry::Trait>::DataObjectTypeId>>
+            content: Vec<ContentParameters<T::ContentId, DataObjectTypeId<T>>>
         ) {
             T::MemberOriginValidator::ensure_actor_origin(
                 origin,
                 member_id,
             )?;
 
-            Self::ensure_content_is_valid(&content)?;
-
             let owner = StorageObjectOwner::Member(member_id);
 
+            Self::ensure_content_is_valid(&content)?;
+
             let liaison = T::StorageProviderHelper::get_random_storage_provider()?;
 
             //
@@ -281,8 +240,8 @@ decl_module! {
         #[weight = 10_000_000] // TODO: adjust weight
         pub fn add_content(
             origin,
-            abstract_owner: AbstractStorageObjectOwner<ChannelId, DAOId>,
-            content: Vec<ContentParameters<T::ContentId, <T as data_object_type_registry::Trait>::DataObjectTypeId>>
+            abstract_owner: AbstractStorageObjectOwner<ChannelId<T>, DAOId<T>>,
+            content: Vec<ContentParameters<ContentId<T>, DataObjectTypeId<T>>>
         ) {
             ensure_root(origin)?;
 
@@ -384,13 +343,8 @@ decl_module! {
 impl<T: Trait> Module<T> {
     fn upload_content(
         liaison: StorageProviderId<T>,
-        multi_content: Vec<
-            ContentParameters<
-                T::ContentId,
-                <T as data_object_type_registry::Trait>::DataObjectTypeId,
-            >,
-        >,
-        owner: StorageObjectOwner<MemberId<T>, ChannelId, DAOId>,
+        multi_content: Vec<ContentParameters<T::ContentId, DataObjectTypeId<T>>>,
+        owner: StorageObjectOwner<MemberId<T>, ChannelId<T>, DAOId<T>>,
     ) {
         for content in multi_content {
             let data: DataObject<T> = DataObjectInternal {
@@ -408,10 +362,7 @@ impl<T: Trait> Module<T> {
     }
 
     fn ensure_content_is_valid(
-        multi_content: &[ContentParameters<
-            T::ContentId,
-            <T as data_object_type_registry::Trait>::DataObjectTypeId,
-        >],
+        multi_content: &[ContentParameters<T::ContentId, DataObjectTypeId<T>>],
     ) -> DispatchResult {
         for content in multi_content {
             ensure!(
@@ -475,3 +426,17 @@ impl<T: Trait> ContentIdExists<T> for Module<T> {
         }
     }
 }
+
+impl<T: Trait> common::storage::StorageSystem<T> for Module<T> {
+    fn atomically_add_content(
+        owner: StorageObjectOwner<MemberId<T>, ChannelId<T>, DAOId<T>>,
+        content: Vec<ContentParameters<T::ContentId, DataObjectTypeId<T>>>,
+    ) -> DispatchResult {
+        Self::ensure_content_is_valid(&content)?;
+
+        let liaison = T::StorageProviderHelper::get_random_storage_provider()?;
+
+        Self::upload_content(liaison, content, owner);
+        Ok(())
+    }
+}

+ 3 - 3
runtime-modules/storage/src/data_object_storage_registry.rs

@@ -30,7 +30,7 @@ use sp_runtime::traits::{MaybeSerialize, Member};
 use sp_std::vec::Vec;
 
 use crate::data_directory::{self, ContentIdExists};
-use crate::{StorageProviderId, StorageWorkingGroup, StorageWorkingGroupInstance};
+use crate::*;
 
 const DEFAULT_FIRST_RELATIONSHIP_ID: u8 = 1;
 
@@ -79,7 +79,7 @@ decl_error! {
 #[derive(Clone, Encode, Decode, PartialEq, Debug)]
 pub struct DataObjectStorageRelationship<T: Trait> {
     /// Content id.
-    pub content_id: <T as data_directory::Trait>::ContentId,
+    pub content_id: <T as common::Trait>::ContentId,
 
     /// Storge provider id.
     pub storage_provider_id: StorageProviderId<T>,
@@ -111,7 +111,7 @@ decl_storage! {
 decl_event! {
     /// _Data object storage registry_ events
     pub enum Event<T> where
-        <T as data_directory::Trait>::ContentId,
+        <T as common::Trait>::ContentId,
         <T as Trait>::DataObjectStorageRelationshipId,
         StorageProviderId = StorageProviderId<T>
     {

+ 11 - 20
runtime-modules/storage/src/data_object_type_registry.rs

@@ -22,33 +22,23 @@
 // Do not delete! Cannot be uncommented by default, because of Parity decl_module! issue.
 //#![warn(missing_docs)]
 
-use codec::{Codec, Decode, Encode};
+use codec::{Decode, Encode};
 use frame_support::dispatch::DispatchError;
 use frame_support::weights::Weight;
-use frame_support::{decl_error, decl_event, decl_module, decl_storage, Parameter};
-use sp_arithmetic::traits::BaseArithmetic;
-use sp_runtime::traits::{MaybeSerialize, Member};
+use frame_support::{decl_error, decl_event, decl_module, decl_storage};
 use sp_std::vec::Vec;
 
-use crate::{StorageWorkingGroup, StorageWorkingGroupInstance};
+use crate::{DataObjectTypeId, StorageWorkingGroup, StorageWorkingGroupInstance};
 
 const DEFAULT_TYPE_DESCRIPTION: &str = "Default data object type for audio and video content.";
 const DEFAULT_FIRST_DATA_OBJECT_TYPE_ID: u8 = 1;
 
 /// The _Data object type registry_ main _Trait_.
-pub trait Trait: system::Trait + working_group::Trait<StorageWorkingGroupInstance> {
+pub trait Trait:
+    system::Trait + working_group::Trait<StorageWorkingGroupInstance> + common::Trait
+{
     /// _Data object type registry_ event type.
     type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
-
-    /// _Data object type id_ type
-    type DataObjectTypeId: Parameter
-        + Member
-        + BaseArithmetic
-        + Codec
-        + Default
-        + Copy
-        + MaybeSerialize
-        + PartialEq;
 }
 
 decl_error! {
@@ -85,22 +75,23 @@ decl_storage! {
     trait Store for Module<T: Trait> as DataObjectTypeRegistry {
         /// Data object type ids should start at this value.
         pub FirstDataObjectTypeId get(fn first_data_object_type_id) config(first_data_object_type_id):
-            T::DataObjectTypeId = T::DataObjectTypeId::from(DEFAULT_FIRST_DATA_OBJECT_TYPE_ID);
+            DataObjectTypeId<T> = DataObjectTypeId::<T>::from(DEFAULT_FIRST_DATA_OBJECT_TYPE_ID);
 
         /// Provides id counter for the data object types.
         pub NextDataObjectTypeId get(fn next_data_object_type_id) build(|config: &GenesisConfig<T>|
-            config.first_data_object_type_id): T::DataObjectTypeId = T::DataObjectTypeId::from(DEFAULT_FIRST_DATA_OBJECT_TYPE_ID);
+            config.first_data_object_type_id): DataObjectTypeId<T> = DataObjectTypeId::<T>::from(DEFAULT_FIRST_DATA_OBJECT_TYPE_ID);
 
         /// Mapping of Data object types.
         pub DataObjectTypes get(fn data_object_types): map hasher(blake2_128_concat)
-            T::DataObjectTypeId => Option<DataObjectType>;
+            DataObjectTypeId<T> => Option<DataObjectType>;
     }
 }
 
 decl_event! {
     /// _Data object type registry_ events
     pub enum Event<T> where
-        <T as Trait>::DataObjectTypeId {
+        DataObjectTypeId = DataObjectTypeId<T>
+    {
         /// Emits on the data object type registration.
         /// Params:
         /// - Id of the new data object type.

+ 13 - 1
runtime-modules/storage/src/lib.rs

@@ -14,7 +14,19 @@ pub type StorageWorkingGroupInstance = working_group::Instance2;
 pub(crate) type StorageWorkingGroup<T> = working_group::Module<T, StorageWorkingGroupInstance>;
 
 // Alias for the member id.
-pub(crate) type MemberId<T> = <T as membership::Trait>::MemberId;
+pub(crate) type MemberId<T> = <T as common::Trait>::MemberId;
+
+// Alias for the content id.
+pub(crate) type ContentId<T> = <T as common::Trait>::ContentId;
+
+/// Channel id representation
+pub(crate) type ChannelId<T> = <T as common::Trait>::ChannelId;
+
+/// DAO id.
+pub(crate) type DAOId<T> = <T as common::Trait>::DAOId;
+
+/// DAO object type id.
+pub(crate) type DataObjectTypeId<T> = <T as common::Trait>::DataObjectTypeId;
 
 /// Storage provider is a worker from the working group module.
 pub type StorageProviderId<T> = working_group::WorkerId<T>;

+ 12 - 4
runtime-modules/storage/src/tests/mock.rs

@@ -13,6 +13,7 @@ use sp_runtime::{
 use crate::data_directory::ContentIdExists;
 pub use crate::data_directory::{ContentParameters, StorageObjectOwner};
 use crate::data_object_type_registry::IsActiveDataObjectType;
+use crate::ContentId;
 pub use crate::StorageWorkingGroupInstance;
 pub use crate::{data_directory, data_object_storage_registry, data_object_type_registry};
 use common::currency::GovernanceCurrency;
@@ -60,12 +61,12 @@ impl<T: data_object_type_registry::Trait> IsActiveDataObjectType<T> for AnyDataO
 
 pub struct MockContent {}
 impl ContentIdExists<Test> for MockContent {
-    fn has_content(which: &<Test as data_directory::Trait>::ContentId) -> bool {
+    fn has_content(which: &ContentId<Test>) -> bool {
         *which == TEST_MOCK_EXISTING_CID
     }
 
     fn get_data_object(
-        which: &<Test as data_directory::Trait>::ContentId,
+        which: &ContentId<Test>,
     ) -> Result<data_directory::DataObject<Test>, &'static str> {
         match *which {
             TEST_MOCK_EXISTING_CID => Ok(data_directory::DataObjectInternal {
@@ -130,6 +131,15 @@ impl pallet_timestamp::Trait for Test {
     type MinimumPeriod = MinimumPeriod;
 }
 
+impl common::Trait for Test {
+    type MemberId = u64;
+    type ActorId = u64;
+    type ChannelId = u64;
+    type DAOId = u64;
+    type ContentId = u64;
+    type DataObjectTypeId = u64;
+}
+
 parameter_types! {
     pub const ExistentialDeposit: u32 = 0;
     pub const StakePoolId: [u8; 8] = *b"joystake";
@@ -158,12 +168,10 @@ impl working_group::Trait<StorageWorkingGroupInstance> for Test {
 
 impl data_object_type_registry::Trait for Test {
     type Event = MetaEvent;
-    type DataObjectTypeId = u64;
 }
 
 impl data_directory::Trait for Test {
     type Event = MetaEvent;
-    type ContentId = u64;
     type StorageProviderHelper = ();
     type IsActiveDataObjectType = AnyDataObjectTypeIsActive;
     type MemberOriginValidator = ();