From 25fef8bea1c1c165a770407e071504e41b76668f Mon Sep 17 00:00:00 2001 From: Amiya Behera Date: Wed, 7 Aug 2024 19:51:00 +0530 Subject: [PATCH] departments --- Cargo.lock | 61 +++--- Cargo.toml | 45 +++-- .../create-department/src/extras.rs | 14 -- custom-pallets/department-funding/Cargo.toml | 32 +-- custom-pallets/department-funding/src/lib.rs | 3 + custom-pallets/department-funding/src/mock.rs | 7 + .../Cargo.toml | 34 ++-- .../src/benchmarking.rs | 0 custom-pallets/departments/src/extras.rs | 29 +++ .../src/lib.rs | 2 + .../src/mock.rs | 0 .../src/tests.rs | 0 .../src/types.rs | 0 .../src/weights.rs | 0 runtime/Cargo.toml | 190 +++++++++--------- runtime/src/lib.rs | 9 + traits/trait-departments/Cargo.toml | 16 ++ traits/trait-departments/src/lib.rs | 9 + 18 files changed, 266 insertions(+), 185 deletions(-) delete mode 100644 custom-pallets/create-department/src/extras.rs rename custom-pallets/{create-department => departments}/Cargo.toml (65%) rename custom-pallets/{create-department => departments}/src/benchmarking.rs (100%) create mode 100644 custom-pallets/departments/src/extras.rs rename custom-pallets/{create-department => departments}/src/lib.rs (99%) rename custom-pallets/{create-department => departments}/src/mock.rs (100%) rename custom-pallets/{create-department => departments}/src/tests.rs (100%) rename custom-pallets/{create-department => departments}/src/types.rs (100%) rename custom-pallets/{create-department => departments}/src/weights.rs (100%) create mode 100644 traits/trait-departments/Cargo.toml create mode 100644 traits/trait-departments/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 0c7013e..6043e3b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1430,30 +1430,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "create-department" -version = "0.1.0" -dependencies = [ - "frame-benchmarking", - "frame-support", - "frame-support-test", - "frame-system", - "pallet-balances", - "pallet-schelling-game-shared", - "pallet-shared-storage", - "pallet-sortition-sum-game", - "pallet-support", - "pallet-timestamp", - "parity-scale-codec", - "scale-info", - "sp-core", - "sp-io", - "sp-runtime", - "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.9.0)", - "trait-schelling-game-shared", - "trait-shared-storage", -] - [[package]] name = "crossbeam-deque" version = "0.8.5" @@ -4736,6 +4712,7 @@ dependencies = [ "pallet-aura", "pallet-balances", "pallet-department-funding", + "pallet-departments", "pallet-grandpa", "pallet-insecure-randomness-collective-flip", "pallet-positive-externality", @@ -5008,6 +4985,32 @@ dependencies = [ [[package]] name = "pallet-department-funding" version = "4.0.0-dev" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-support-test", + "frame-system", + "pallet-balances", + "pallet-departments", + "pallet-schelling-game-shared", + "pallet-shared-storage", + "pallet-sortition-sum-game", + "pallet-support", + "pallet-timestamp", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.9.0)", + "trait-departments", + "trait-schelling-game-shared", + "trait-shared-storage", +] + +[[package]] +name = "pallet-departments" +version = "0.1.0" dependencies = [ "frame-benchmarking", "frame-support", @@ -5025,6 +5028,7 @@ dependencies = [ "sp-io", "sp-runtime", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.9.0)", + "trait-departments", "trait-schelling-game-shared", "trait-shared-storage", ] @@ -9740,6 +9744,15 @@ dependencies = [ "tracing-log 0.2.0", ] +[[package]] +name = "trait-departments" +version = "0.1.0" +dependencies = [ + "frame-support", + "parity-scale-codec", + "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.9.0)", +] + [[package]] name = "trait-schelling-game-shared" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index b407f23..80d69f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,15 +10,16 @@ members = [ "node", "pallets/template", "custom-pallets/department-funding", - "custom-pallets/positive-externality", - "custom-pallets/profile-validation", - "custom-pallets/project-tips", - "custom-pallets/schelling-game-shared", - "custom-pallets/shared-storage", - "custom-pallets/sortition-sum-game", - "custom-pallets/spaces", - "custom-pallets/support", - "runtime", "custom-pallets/create-department", + "custom-pallets/positive-externality", + "custom-pallets/profile-validation", + "custom-pallets/project-tips", + "custom-pallets/schelling-game-shared", + "custom-pallets/shared-storage", + "custom-pallets/sortition-sum-game", + "custom-pallets/spaces", + "custom-pallets/support", + "custom-pallets/departments", + "runtime", ] resolver = "2" [profile.release] @@ -68,11 +69,13 @@ pallet-profile-validation = { path = "custom-pallets/profile-validation", defaul pallet-project-tips = { path = "custom-pallets/project-tips", default-features = false } pallet-positive-externality = { path = "custom-pallets/positive-externality", default-features = false } pallet-department-funding = { path = "custom-pallets/department-funding", default-features = false } +pallet-departments = { path = "custom-pallets/departments", default-features = false } ## Traits trait-sortition-sum-game = { path = "traits/trait-sortition-sum-game", default-features = false } trait-shared-storage = { path = "traits/trait-shared-storage", default-features = false } trait-schelling-game-shared = { path = "traits/trait-schelling-game-shared", default-features = false } +trait-departments = { path = "traits/trait-departments", default-features = false } ## Api profile-validation-runtime-api = { path = "custom-pallets/profile-validation/profile-validation-runtime-api", default-features = false } @@ -94,30 +97,30 @@ strum = { version = "0.26.2", default-features = false, features = ["derive"] } num-integer = { default-features = false, version = "0.1.44" } frame-support-test = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false } pallet-insecure-randomness-collective-flip = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false } -sp-npos-elections = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false} +sp-npos-elections = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false } log = { version = "0.4.17", default-features = false } jsonrpsee = { version = "0.22", features = ["client-core", "macros", "server"] } sc-rpc = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false } -sp-blockchain = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false } -hex-literal = { version= " 0.4.1" } +sp-blockchain = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false } +hex-literal = { version = " 0.4.1" } ## New end parity-scale-codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = [ - "derive", + "derive", ] } scale-info = { version = "2.10.0", default-features = false, features = [ - "derive", + "derive", ] } # frame deps -frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false} +frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false } frame-support = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false } frame-system = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false } -sp-std = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false} -pallet-timestamp = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false} -pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false} +sp-std = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false } +pallet-timestamp = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false } +pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false } -sp-core = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false } -sp-io = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false} -sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false } +sp-core = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false } +sp-io = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false } sp-api = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false } diff --git a/custom-pallets/create-department/src/extras.rs b/custom-pallets/create-department/src/extras.rs deleted file mode 100644 index 82b0b29..0000000 --- a/custom-pallets/create-department/src/extras.rs +++ /dev/null @@ -1,14 +0,0 @@ -use super::*; - -impl Pallet { - pub fn check_member_is_admin(who: T::AccountId, department_id: DepartmentId) -> DispatchResult { - match >::get(department_id) { - Some(department) => { - let admin = department.department_admin; - ensure!(admin == who, Error::::NotAdmin); - }, - None => Err(Error::::DepartmentDontExists)?, - } - Ok(()) - } -} diff --git a/custom-pallets/department-funding/Cargo.toml b/custom-pallets/department-funding/Cargo.toml index f9be831..ed58bce 100644 --- a/custom-pallets/department-funding/Cargo.toml +++ b/custom-pallets/department-funding/Cargo.toml @@ -15,18 +15,20 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] parity-scale-codec = { workspace = true } scale-info = { workspace = true } -frame-benchmarking = { workspace = true , optional = true} +frame-benchmarking = { workspace = true, optional = true } frame-support = { workspace = true } frame-system = { workspace = true } -sp-std = { workspace = true} +sp-std = { workspace = true } pallet-timestamp = { workspace = true } pallet-balances = { workspace = true } -pallet-support = { workspace = true } +pallet-support = { workspace = true } pallet-shared-storage = { workspace = true } trait-shared-storage = { workspace = true } pallet-schelling-game-shared = { workspace = true } trait-schelling-game-shared = { workspace = true } pallet-sortition-sum-game = { workspace = true } +trait-departments = { workspace = true } +pallet-departments = { workspace = true } [dev-dependencies] sp-core = { workspace = true } @@ -37,18 +39,18 @@ frame-support-test = { workspace = true } [features] default = ["std"] std = [ - "parity-scale-codec/std", - "frame-benchmarking?/std", - "frame-support/std", - "frame-system/std", - "scale-info/std", - "pallet-timestamp/std", - "pallet-balances/std", - "pallet-support/std", - "pallet-shared-storage/std", - "pallet-schelling-game-shared/std", - "pallet-sortition-sum-game/std", - "frame-support-test/std", + "parity-scale-codec/std", + "frame-benchmarking?/std", + "frame-support/std", + "frame-system/std", + "scale-info/std", + "pallet-timestamp/std", + "pallet-balances/std", + "pallet-support/std", + "pallet-shared-storage/std", + "pallet-schelling-game-shared/std", + "pallet-sortition-sum-game/std", + "frame-support-test/std", ] runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"] try-runtime = ["frame-support/try-runtime"] diff --git a/custom-pallets/department-funding/src/lib.rs b/custom-pallets/department-funding/src/lib.rs index 86f8236..8a27f93 100644 --- a/custom-pallets/department-funding/src/lib.rs +++ b/custom-pallets/department-funding/src/lib.rs @@ -42,6 +42,7 @@ use pallet_support::{ ensure_content_is_valid, new_when_details, new_who_and_when, remove_from_vec, Content, PostId, WhenDetailsOf, WhoAndWhen, WhoAndWhenOf, }; +use trait_departments::DepartmentsLink; use trait_schelling_game_shared::SchellingGameSharedLink; use trait_shared_storage::SharedStorageLink; pub use types::DEPARTMENT_REQUIRED_FUND_ID; @@ -91,6 +92,7 @@ pub mod pallet { PhaseData = PhaseData, JurorGameResult = JurorGameResult, >; + type DepartmentsSource: DepartmentsLink; type Currency: ReservableCurrency; type Reward: OnUnbalanced>; } @@ -219,6 +221,7 @@ pub mod pallet { funding_needed: BalanceOf, ) -> DispatchResult { let who = ensure_signed(origin)?; + T::DepartmentsSource::check_department_exists(department_id)?; let tipping_value = Self::value_of_tipping_name(tipping_name); let max_tipping_value = tipping_value.max_tipping_value; let stake_required = tipping_value.stake_required; diff --git a/custom-pallets/department-funding/src/mock.rs b/custom-pallets/department-funding/src/mock.rs index 3d08893..c2fb919 100644 --- a/custom-pallets/department-funding/src/mock.rs +++ b/custom-pallets/department-funding/src/mock.rs @@ -22,6 +22,7 @@ frame_support::construct_runtime!( SharedStorage:pallet_shared_storage, SchellingGameShared: pallet_schelling_game_shared, SortitionSumGame: pallet_sortition_sum_game, + Departments: pallet_departments, } ); #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] @@ -72,6 +73,7 @@ impl pallet_template::Config for Test { type SharedStorageSource = SharedStorage; type Currency = Balances; // New code type SchellingGameSharedSource = SchellingGameShared; + type DepartmentsSource = Departments; type Reward = (); } @@ -106,6 +108,11 @@ impl pallet_sortition_sum_game::Config for Test { type WeightInfo = (); } +impl pallet_departments::Config for Test { + type RuntimeEvent = RuntimeEvent; + type WeightInfo = (); +} + // Build genesis storage according to the mock runtime. pub fn new_test_ext() -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); diff --git a/custom-pallets/create-department/Cargo.toml b/custom-pallets/departments/Cargo.toml similarity index 65% rename from custom-pallets/create-department/Cargo.toml rename to custom-pallets/departments/Cargo.toml index c204931..881ef35 100644 --- a/custom-pallets/create-department/Cargo.toml +++ b/custom-pallets/departments/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "create-department" +name = "pallet-departments" version = "0.1.0" authors.workspace = true edition.workspace = true @@ -17,18 +17,19 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] parity-scale-codec = { workspace = true } scale-info = { workspace = true } -frame-benchmarking = { workspace = true , optional = true} +frame-benchmarking = { workspace = true, optional = true } frame-support = { workspace = true } frame-system = { workspace = true } -sp-std = { workspace = true} +sp-std = { workspace = true } pallet-timestamp = { workspace = true } pallet-balances = { workspace = true } -pallet-support = { workspace = true } +pallet-support = { workspace = true } pallet-shared-storage = { workspace = true } trait-shared-storage = { workspace = true } pallet-schelling-game-shared = { workspace = true } trait-schelling-game-shared = { workspace = true } pallet-sortition-sum-game = { workspace = true } +trait-departments = { workspace = true } [dev-dependencies] sp-core = { workspace = true } @@ -39,19 +40,18 @@ frame-support-test = { workspace = true } [features] default = ["std"] std = [ - "parity-scale-codec/std", - "frame-benchmarking?/std", - "frame-support/std", - "frame-system/std", - "scale-info/std", - "pallet-timestamp/std", - "pallet-balances/std", - "pallet-support/std", - "pallet-shared-storage/std", - "pallet-schelling-game-shared/std", - "pallet-sortition-sum-game/std", - "frame-support-test/std", + "parity-scale-codec/std", + "frame-benchmarking?/std", + "frame-support/std", + "frame-system/std", + "scale-info/std", + "pallet-timestamp/std", + "pallet-balances/std", + "pallet-support/std", + "pallet-shared-storage/std", + "pallet-schelling-game-shared/std", + "pallet-sortition-sum-game/std", + "frame-support-test/std", ] runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"] try-runtime = ["frame-support/try-runtime"] - diff --git a/custom-pallets/create-department/src/benchmarking.rs b/custom-pallets/departments/src/benchmarking.rs similarity index 100% rename from custom-pallets/create-department/src/benchmarking.rs rename to custom-pallets/departments/src/benchmarking.rs diff --git a/custom-pallets/departments/src/extras.rs b/custom-pallets/departments/src/extras.rs new file mode 100644 index 0000000..baa6642 --- /dev/null +++ b/custom-pallets/departments/src/extras.rs @@ -0,0 +1,29 @@ +use super::*; +use trait_departments::DepartmentsLink; + +impl DepartmentsLink for Pallet { + type DepartmentId = DepartmentId; + + fn check_department_exists(department_id: DepartmentId) -> DispatchResult { + Self::check_department_exists(department_id) + } +} + +impl Pallet { + pub fn check_member_is_admin(who: T::AccountId, department_id: DepartmentId) -> DispatchResult { + match >::get(department_id) { + Some(department) => { + let admin = department.department_admin; + ensure!(admin == who, Error::::NotAdmin); + }, + None => Err(Error::::DepartmentDontExists)?, + } + Ok(()) + } + pub fn check_department_exists(department_id: DepartmentId) -> DispatchResult { + match >::get(department_id) { + Some(_) => Ok(()), + None => Err(Error::::DepartmentDontExists)?, + } + } +} diff --git a/custom-pallets/create-department/src/lib.rs b/custom-pallets/departments/src/lib.rs similarity index 99% rename from custom-pallets/create-department/src/lib.rs rename to custom-pallets/departments/src/lib.rs index b208e8a..5ed024b 100644 --- a/custom-pallets/create-department/src/lib.rs +++ b/custom-pallets/departments/src/lib.rs @@ -70,6 +70,8 @@ use pallet_support::{ ensure_content_is_valid, new_who_and_when, remove_from_vec, Content, WhoAndWhen, WhoAndWhenOf, }; +use sp_std::vec; +use sp_std::vec::Vec; // All pallet logic is defined in its own module and must be annotated by the `pallet` attribute. #[frame_support::pallet(dev_mode)] pub mod pallet { diff --git a/custom-pallets/create-department/src/mock.rs b/custom-pallets/departments/src/mock.rs similarity index 100% rename from custom-pallets/create-department/src/mock.rs rename to custom-pallets/departments/src/mock.rs diff --git a/custom-pallets/create-department/src/tests.rs b/custom-pallets/departments/src/tests.rs similarity index 100% rename from custom-pallets/create-department/src/tests.rs rename to custom-pallets/departments/src/tests.rs diff --git a/custom-pallets/create-department/src/types.rs b/custom-pallets/departments/src/types.rs similarity index 100% rename from custom-pallets/create-department/src/types.rs rename to custom-pallets/departments/src/types.rs diff --git a/custom-pallets/create-department/src/weights.rs b/custom-pallets/departments/src/weights.rs similarity index 100% rename from custom-pallets/create-department/src/weights.rs rename to custom-pallets/departments/src/weights.rs diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index fe19176..b465148 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -17,16 +17,16 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = [ - "derive", + "derive", ] } scale-info = { version = "2.10.0", default-features = false, features = [ - "derive", - "serde", + "derive", + "serde", ] } # frame frame-support = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false, features = [ - "experimental", + "experimental", ] } frame-system = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false } frame-try-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false, optional = true } @@ -44,25 +44,25 @@ pallet-transaction-payment = { git = "https://github.com/paritytech/polkadot-sdk sp-api = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false } sp-block-builder = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false } sp-consensus-aura = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false, features = [ - "serde", + "serde", ] } sp-consensus-grandpa = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false, features = [ - "serde", + "serde", ] } sp-core = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false, features = [ - "serde", + "serde", ] } sp-inherents = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false } sp-offchain = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false } sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false, features = [ - "serde", + "serde", ] } sp-session = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false } sp-std = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false } sp-storage = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false } sp-transaction-pool = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false } sp-version = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", default-features = false, features = [ - "serde", + "serde", ] } sp-genesis-builder = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0" } @@ -92,109 +92,111 @@ pallet-shared-storage = { workspace = true } pallet-positive-externality = { workspace = true } pallet-department-funding = { workspace = true } pallet-project-tips = { workspace = true } +pallet-departments = { workspace = true } profile-validation-runtime-api = { workspace = true } positive-externality-runtime-api = { workspace = true } department-funding-runtime-api = { workspace = true } project-tips-runtime-api = { workspace = true } + [build-dependencies] substrate-wasm-builder = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.9.0", optional = true } [features] default = ["std"] std = [ - "codec/std", - "scale-info/std", - - "frame-executive/std", - "frame-support/std", - "frame-system-benchmarking?/std", - "frame-system-rpc-runtime-api/std", - "frame-system/std", - - "frame-benchmarking?/std", - "frame-try-runtime?/std", - - "pallet-aura/std", - "pallet-balances/std", - "pallet-grandpa/std", - "pallet-sudo/std", - "pallet-template/std", - "pallet-timestamp/std", - "pallet-transaction-payment-rpc-runtime-api/std", - "pallet-transaction-payment/std", - - "sp-api/std", - "sp-block-builder/std", - "sp-consensus-aura/std", - "sp-consensus-grandpa/std", - "sp-core/std", - "sp-genesis-builder/std", - "sp-inherents/std", - "sp-offchain/std", - "sp-runtime/std", - "sp-session/std", - "sp-std/std", - "sp-storage/std", - "sp-transaction-pool/std", - "sp-version/std", - - "substrate-wasm-builder", - "pallet-insecure-randomness-collective-flip/std", - "pallet-sortition-sum-game/std", - "pallet-schelling-game-shared/std", - "pallet-profile-validation/std", - "pallet-shared-storage/std", - "pallet-positive-externality/std", - "pallet-department-funding/std", - "pallet-project-tips/std", - "profile-validation-runtime-api/std", - "positive-externality-runtime-api/std", - "department-funding-runtime-api/std", - "project-tips-runtime-api/std", + "codec/std", + "scale-info/std", + + "frame-executive/std", + "frame-support/std", + "frame-system-benchmarking?/std", + "frame-system-rpc-runtime-api/std", + "frame-system/std", + + "frame-benchmarking?/std", + "frame-try-runtime?/std", + + "pallet-aura/std", + "pallet-balances/std", + "pallet-grandpa/std", + "pallet-sudo/std", + "pallet-template/std", + "pallet-timestamp/std", + "pallet-transaction-payment-rpc-runtime-api/std", + "pallet-transaction-payment/std", + + "sp-api/std", + "sp-block-builder/std", + "sp-consensus-aura/std", + "sp-consensus-grandpa/std", + "sp-core/std", + "sp-genesis-builder/std", + "sp-inherents/std", + "sp-offchain/std", + "sp-runtime/std", + "sp-session/std", + "sp-std/std", + "sp-storage/std", + "sp-transaction-pool/std", + "sp-version/std", + + "substrate-wasm-builder", + "pallet-insecure-randomness-collective-flip/std", + "pallet-sortition-sum-game/std", + "pallet-schelling-game-shared/std", + "pallet-profile-validation/std", + "pallet-shared-storage/std", + "pallet-positive-externality/std", + "pallet-department-funding/std", + "pallet-project-tips/std", + "profile-validation-runtime-api/std", + "positive-externality-runtime-api/std", + "department-funding-runtime-api/std", + "project-tips-runtime-api/std", ] runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system-benchmarking/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "pallet-balances/runtime-benchmarks", - "pallet-grandpa/runtime-benchmarks", - "pallet-sudo/runtime-benchmarks", - "pallet-template/runtime-benchmarks", - "pallet-timestamp/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", - "pallet-sortition-sum-game/runtime-benchmarks", - "pallet-schelling-game-shared/runtime-benchmarks", - "pallet-profile-validation/runtime-benchmarks", - "pallet-shared-storage/runtime-benchmarks", - "pallet-positive-externality/runtime-benchmarks", - "pallet-department-funding/runtime-benchmarks", - "pallet-project-tips/runtime-benchmarks", + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system-benchmarking/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", + "pallet-grandpa/runtime-benchmarks", + "pallet-sudo/runtime-benchmarks", + "pallet-template/runtime-benchmarks", + "pallet-timestamp/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", + "pallet-sortition-sum-game/runtime-benchmarks", + "pallet-schelling-game-shared/runtime-benchmarks", + "pallet-profile-validation/runtime-benchmarks", + "pallet-shared-storage/runtime-benchmarks", + "pallet-positive-externality/runtime-benchmarks", + "pallet-department-funding/runtime-benchmarks", + "pallet-project-tips/runtime-benchmarks", ] try-runtime = [ - "frame-executive/try-runtime", - "frame-support/try-runtime", - "frame-system/try-runtime", - "frame-try-runtime/try-runtime", - "pallet-aura/try-runtime", - "pallet-balances/try-runtime", - "pallet-grandpa/try-runtime", - "pallet-sudo/try-runtime", - "pallet-template/try-runtime", - "pallet-timestamp/try-runtime", - "pallet-transaction-payment/try-runtime", - "sp-runtime/try-runtime", - "pallet-sortition-sum-game/try-runtime", - "pallet-schelling-game-shared/try-runtime", - "pallet-profile-validation/try-runtime", - "pallet-shared-storage/try-runtime", - "pallet-positive-externality/try-runtime", - "pallet-department-funding/try-runtime", - "pallet-project-tips/try-runtime", + "frame-executive/try-runtime", + "frame-support/try-runtime", + "frame-system/try-runtime", + "frame-try-runtime/try-runtime", + "pallet-aura/try-runtime", + "pallet-balances/try-runtime", + "pallet-grandpa/try-runtime", + "pallet-sudo/try-runtime", + "pallet-template/try-runtime", + "pallet-timestamp/try-runtime", + "pallet-transaction-payment/try-runtime", + "sp-runtime/try-runtime", + "pallet-sortition-sum-game/try-runtime", + "pallet-schelling-game-shared/try-runtime", + "pallet-profile-validation/try-runtime", + "pallet-shared-storage/try-runtime", + "pallet-positive-externality/try-runtime", + "pallet-department-funding/try-runtime", + "pallet-project-tips/try-runtime", ] experimental = ["pallet-aura/experimental"] diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index bcde73f..786e941 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -297,12 +297,18 @@ impl pallet_positive_externality::Config for Runtime { type Reward = (); } +impl pallet_departments::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type WeightInfo = pallet_departments::weights::SubstrateWeight; +} + impl pallet_department_funding::Config for Runtime { type RuntimeEvent = RuntimeEvent; type WeightInfo = pallet_department_funding::weights::SubstrateWeight; type SharedStorageSource = SharedStorage; type Currency = Balances; type SchellingGameSharedSource = SchellingGameShared; + type DepartmentsSource = Departments; type Reward = (); } @@ -380,6 +386,9 @@ mod runtime { #[runtime::pallet_index(15)] pub type RandomnessCollectiveFlip = pallet_insecure_randomness_collective_flip; + + #[runtime::pallet_index(16)] + pub type Departments = pallet_departments; } /// The address format for describing accounts. diff --git a/traits/trait-departments/Cargo.toml b/traits/trait-departments/Cargo.toml new file mode 100644 index 0000000..5d2acac --- /dev/null +++ b/traits/trait-departments/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "trait-departments" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +parity-scale-codec = { workspace = true } +frame-support = { workspace = true } +sp-std = { workspace = true } + + +[features] +default = ["std"] +std = ["parity-scale-codec/std", "frame-support/std"] diff --git a/traits/trait-departments/src/lib.rs b/traits/trait-departments/src/lib.rs new file mode 100644 index 0000000..5ce4022 --- /dev/null +++ b/traits/trait-departments/src/lib.rs @@ -0,0 +1,9 @@ +#![cfg_attr(not(feature = "std"), no_std)] +use frame_support::dispatch::DispatchResult; +use frame_support::pallet_prelude::DispatchError; +use sp_std::prelude::*; + +pub trait DepartmentsLink { + type DepartmentId; + fn check_department_exists(department_id: Self::DepartmentId) -> DispatchResult; +}