Skip to content

Commit

Permalink
departments
Browse files Browse the repository at this point in the history
  • Loading branch information
amiyatulu committed Aug 7, 2024
1 parent a4ffc03 commit 25fef8b
Show file tree
Hide file tree
Showing 18 changed files with 266 additions and 185 deletions.
61 changes: 37 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 24 additions & 21 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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 }
Expand All @@ -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 }
14 changes: 0 additions & 14 deletions custom-pallets/create-department/src/extras.rs

This file was deleted.

32 changes: 17 additions & 15 deletions custom-pallets/department-funding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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"]
3 changes: 3 additions & 0 deletions custom-pallets/department-funding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -91,6 +92,7 @@ pub mod pallet {
PhaseData = PhaseData<Self>,
JurorGameResult = JurorGameResult,
>;
type DepartmentsSource: DepartmentsLink<DepartmentId = DepartmentId>;
type Currency: ReservableCurrency<Self::AccountId>;
type Reward: OnUnbalanced<PositiveImbalanceOf<Self>>;
}
Expand Down Expand Up @@ -219,6 +221,7 @@ pub mod pallet {
funding_needed: BalanceOf<T>,
) -> 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;
Expand Down
7 changes: 7 additions & 0 deletions custom-pallets/department-funding/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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 = ();
}

Expand Down Expand Up @@ -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::<Test>::default().build_storage().unwrap();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "create-department"
name = "pallet-departments"
version = "0.1.0"
authors.workspace = true
edition.workspace = true
Expand All @@ -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 }
Expand All @@ -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"]

29 changes: 29 additions & 0 deletions custom-pallets/departments/src/extras.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use super::*;
use trait_departments::DepartmentsLink;

impl<T: Config> DepartmentsLink for Pallet<T> {
type DepartmentId = DepartmentId;

fn check_department_exists(department_id: DepartmentId) -> DispatchResult {
Self::check_department_exists(department_id)
}
}

impl<T: Config> Pallet<T> {
pub fn check_member_is_admin(who: T::AccountId, department_id: DepartmentId) -> DispatchResult {
match <Departments<T>>::get(department_id) {
Some(department) => {
let admin = department.department_admin;
ensure!(admin == who, Error::<T>::NotAdmin);
},
None => Err(Error::<T>::DepartmentDontExists)?,
}
Ok(())
}
pub fn check_department_exists(department_id: DepartmentId) -> DispatchResult {
match <Departments<T>>::get(department_id) {
Some(_) => Ok(()),
None => Err(Error::<T>::DepartmentDontExists)?,
}
}
}
Loading

0 comments on commit 25fef8b

Please sign in to comment.