Pārlūkot izejas kodu

runtime: Add constitution pallet.

Shamil Gadelshin 4 gadi atpakaļ
vecāks
revīzija
11a1dc3723

+ 11 - 0
Cargo.lock

@@ -3306,6 +3306,17 @@ dependencies = [
  "strum_macros 0.19.2",
 ]
 
+[[package]]
+name = "pallet-constitution"
+version = "1.0.0"
+dependencies = [
+ "frame-support",
+ "frame-system",
+ "parity-scale-codec",
+ "serde",
+ "sp-std",
+]
+
 [[package]]
 name = "pallet-content-directory"
 version = "3.0.0"

+ 1 - 0
Cargo.toml

@@ -20,6 +20,7 @@ members = [
 	"runtime-modules/versioned-store-permissions",
 	"runtime-modules/working-group",
 	"runtime-modules/content-directory",
+	"runtime-modules/constitution",
 	"node",
 	"utils/chain-spec-builder/"
 ]

+ 22 - 0
runtime-modules/constitution/Cargo.toml

@@ -0,0 +1,22 @@
+[package]
+name = 'pallet-constitution'
+version = '1.0.0'
+authors = ['Joystream contributors']
+edition = '2018'
+
+[dependencies]
+serde = { version = "1.0.101", optional = true, features = ["derive"] }
+codec = { package = 'parity-scale-codec', version = '1.3.1', default-features = false, features = ['derive'] }
+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'}
+
+[features]
+default = ['std']
+std = [
+    'serde',
+    'codec/std',
+    'sp-std/std',
+    'frame-support/std',
+    'system/std',
+]

+ 55 - 0
runtime-modules/constitution/src/lib.rs

@@ -0,0 +1,55 @@
+// Ensure we're `no_std` when compiling for Wasm.
+#![cfg_attr(not(feature = "std"), no_std)]
+
+use codec::{Decode, Encode};
+use frame_support::{decl_event, decl_module, decl_storage};
+#[cfg(feature = "std")]
+use serde::{Deserialize, Serialize};
+use sp_std::vec::Vec;
+use system::ensure_root;
+
+pub trait Trait: system::Trait {
+    type Event: From<Event> + Into<<Self as system::Trait>::Event>;
+}
+
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
+#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug, Default)]
+pub struct ConstitutionInfo {
+    pub text_hash: Vec<u8>,
+    pub amendment_number: u32,
+}
+
+decl_storage! {
+    trait Store for Module<T: Trait> as Memo {
+        Constitution get(fn constitution) : ConstitutionInfo;
+        NextAmendmentNumber get(fn next_amendment_number) : u32 = 0;
+    }
+}
+
+decl_event! {
+    pub enum Event {
+        ConstutionAmended(Vec<u8>, u32),
+    }
+}
+
+decl_module! {
+    pub struct Module<T: Trait> for enum Call where origin: T::Origin {
+        fn deposit_event() = default;
+
+        #[weight = 10_000_000] // TODO: adjust weight
+        fn amend_contitution(origin, constitution_text: Vec<u8>) {
+            ensure_root(origin)?;
+
+            let hash = Vec::new();
+            let amendment_number = Self::next_amendment_number();
+
+            let constitution = ConstitutionInfo{
+                text_hash: hash.clone(),
+                amendment_number
+            };
+
+            Constitution::put(constitution);
+            Self::deposit_event(Event::ConstutionAmended(hash, amendment_number));
+        }
+    }
+}