Skip to content

Commit

Permalink
Use pallet-referenda and PolkadotSDK form workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
olanod committed Nov 21, 2023
1 parent a4d74f6 commit 14ecf35
Show file tree
Hide file tree
Showing 8 changed files with 568 additions and 613 deletions.
927 changes: 482 additions & 445 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,22 @@ pallet-contracts = { default-features = false, git = "https://github.com/virto-
pallet-contracts-primitives = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-democracy = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-identity = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-insecure-randomness-collective-flip = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-multisig = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-proxy = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-preimage = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-insecure-randomness-collective-flip = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-referenda = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-referenda-tracks = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-remark = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-session = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-scheduler = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-sudo = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-remark = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-timestamp = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-transaction-payment = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-transaction-payment-rpc-runtime-api = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-treasury = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-uniques = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-utility = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
pallet-treasury = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }

# Cumulus client dependencies
cumulus-client-cli = { git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" }
Expand Down
33 changes: 17 additions & 16 deletions pallets/communities/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,33 @@ targets = ["x86_64-unknown-linux-gnu"]
parity-scale-codec = { workspace = true, features = ["derive"] }
scale-info = { workspace = true, features = ["derive"] }

frame-benchmarking = { git = "https://github.com/olanod/polkadot-sdk.git", branch = "olanod-referenda-owned-tracks", optional = true }
frame-support = { git = "https://github.com/olanod/polkadot-sdk.git", branch = "olanod-referenda-owned-tracks" }
frame-system = { git = "https://github.com/olanod/polkadot-sdk.git", branch = "olanod-referenda-owned-tracks" }
sp-runtime = { git = "https://github.com/olanod/polkadot-sdk.git", branch = "olanod-referenda-owned-tracks" }
sp-std = { git = "https://github.com/olanod/polkadot-sdk.git", branch = "olanod-referenda-owned-tracks" }

pallet-referenda = { default-features = false, git = "https://github.com/olanod/polkadot-sdk.git", branch = "olanod-referenda-owned-tracks", optional = true }
frame-benchmarking = { workspace = true, optional = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }

[dev-dependencies]
sp-core = { git = "https://github.com/olanod/polkadot-sdk.git", branch = "olanod-referenda-owned-tracks" }
sp-io = { git = "https://github.com/olanod/polkadot-sdk.git", branch = "olanod-referenda-owned-tracks" }
sp-core = { workspace = true }
sp-io = { workspace = true }

pallet-assets = { git = "https://github.com/olanod/polkadot-sdk.git", branch = "olanod-referenda-owned-tracks" }
pallet-balances = { git = "https://github.com/olanod/polkadot-sdk.git", branch = "olanod-referenda-owned-tracks" }
pallet-preimage = { git = "https://github.com/olanod/polkadot-sdk.git", branch = "olanod-referenda-owned-tracks" }
pallet-scheduler = { git = "https://github.com/olanod/polkadot-sdk.git", branch = "olanod-referenda-owned-tracks" }
pallet-assets = { workspace = true }
pallet-balances = { workspace = true }
pallet-preimage = { workspace = true }
pallet-referenda = { workspace = true }
pallet-referenda-tracks = { workspace = true }
pallet-scheduler = { workspace = true }

[features]
default = ["std", "referenda"]
referenda = ["dep:pallet-referenda"]
default = ["std"]
std = [
"parity-scale-codec/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"pallet-referenda?/std",
"pallet-assets/std",
"pallet-balances/std",
"pallet-referenda/std",
"scale-info/std",
"sp-runtime/std",
"sp-std/std",
Expand Down
22 changes: 11 additions & 11 deletions pallets/communities/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,16 +448,16 @@ pub mod pallet {

// === Governance ===

///
#[pallet::call_index(4)]
pub fn vote(
origin: OriginFor<T>,
#[pallet::compact] poll_index: PollIndexOf<T>,
_vote: VoteOf<T>,
) -> DispatchResult {
let _ = ensure_signed(origin)?;
// TODO
Ok(())
}
// ///
// #[pallet::call_index(4)]
// pub fn vote(
// origin: OriginFor<T>,
// #[pallet::compact] poll_index: PollIndexOf<T>,
// _vote: VoteOf<T>,
// ) -> DispatchResult {
// let _ = ensure_signed(origin)?;
// // TODO
// Ok(())
// }
}
}
51 changes: 42 additions & 9 deletions pallets/communities/src/tests/mock.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
use frame_support::{
parameter_types,
ord_parameter_types, parameter_types,
traits::{
fungible::HoldConsideration, AsEnsureOriginWithArg, ConstU128, ConstU16, ConstU32, ConstU64,
EqualPrivilegeOnly, Footprint,
},
weights::Weight,
PalletId,
};
use frame_system::{EnsureRoot, EnsureSigned};
use frame_system::{EnsureRoot, EnsureSigned, EnsureSignedBy};
use parity_scale_codec::Compact;
use sp_core::H256;
use sp_runtime::{
traits::{BlakeTwo256, Convert, IdentityLookup},
BuildStorage,
};

use crate as pallet_communities;

use super::mock_poll::TestPolls;
use crate::{
self as pallet_communities,
types::{Tally, VoteWeight},
};

type Block = frame_system::mocking::MockBlock<Test>;
type WeightInfo = ();
Expand All @@ -42,6 +43,8 @@ frame_support::construct_runtime!(
Balances: pallet_balances,
Communities: pallet_communities,
Preimage: pallet_preimage,
Referenda: pallet_referenda,
Tracks: pallet_referenda_tracks,
Scheduler: pallet_scheduler,
System: frame_system,
}
Expand Down Expand Up @@ -92,6 +95,8 @@ impl pallet_assets::Config for Test {
type CallbackHandle = ();
type WeightInfo = WeightInfo;
type RemoveItemsLimit = ConstU32<1000>;
type RuntimeHoldReason = RuntimeHoldReason;
type MaxHolds = ();
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}
Expand All @@ -110,21 +115,49 @@ impl pallet_balances::Config for Test {
type FreezeIdentifier = ();
type MaxHolds = ConstU32<10>;
type MaxFreezes = ConstU32<10>;
type RuntimeFreezeReason = ();
}

parameter_types! {
pub static AlarmInterval: u64 = 1;
}
ord_parameter_types! {
pub const One: u64 = 1;
}
impl pallet_referenda::Config for Test {
type WeightInfo = ();
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type Scheduler = Scheduler;
type Currency = pallet_balances::Pallet<Self>;
type SubmitOrigin = frame_system::EnsureSigned<u64>;
type CancelOrigin = EnsureSignedBy<One, u64>;
type KillOrigin = EnsureRoot<u64>;
type Slash = ();
type Votes = VoteWeight;
type Tally = Tally<Test>;
type SubmissionDeposit = ConstU128<2>;
type MaxQueued = ConstU32<3>;
type UndecidingTimeout = ConstU64<20>;
type AlarmInterval = AlarmInterval;
type Tracks = Tracks;
type Preimages = Preimage;
}
impl pallet_referenda_tracks::Config for Test {
type RuntimeEvent = RuntimeEvent;
type TrackId = CommunityId;
type MaxTracks = ConstU32<2>;
}

parameter_types! {
pub MaximumSchedulerWeight: Weight = Weight::from_parts(1_000_000_000, 1_048_576);
pub const MaxScheduledPerBlock: u32 = 512;
}

pub struct ConvertDeposit;
impl Convert<Footprint, u128> for ConvertDeposit {
fn convert(a: Footprint) -> u128 {
(a.count * 2 + a.size).into()
}
}

impl pallet_preimage::Config for Test {
type WeightInfo = ();
type RuntimeEvent = RuntimeEvent;
Expand Down Expand Up @@ -160,7 +193,7 @@ impl pallet_communities::Config for Test {
type CommunityId = CommunityId;
type Membership = MembershipPassport;
type PalletId = CommunitiesPalletId;
type Polls = TestPolls;
type Polls = Referenda;
}

// Build genesis storage according to the mock runtime.
Expand Down
93 changes: 0 additions & 93 deletions pallets/communities/src/tests/mock_poll.rs

This file was deleted.

1 change: 0 additions & 1 deletion pallets/communities/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const COMMUNITY: CommunityId = 1;
const COMMUNITY_ADMIN: AccountId = 42;

mod membership;
mod mock_poll;
mod registry;

fn setup() {
Expand Down
46 changes: 11 additions & 35 deletions pallets/communities/src/types/governance.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
use core::marker::PhantomData;

use frame_support::traits::VoteTally;
use frame_system::pallet_prelude::BlockNumberFor;
use pallet_referenda::{Track, TracksInfo};
use sp_std::borrow::Cow;

use super::*;

pub type VoteWeight = sp_runtime::Perbill;

pub type VoteWeight = u32;
/// This structure holds a governance strategy. This defines how to behave
/// when ensuring privileged calls and deciding executing
/// calls
Expand Down Expand Up @@ -51,49 +45,31 @@ pub enum Vote<AssetId, AssetBalance> {
}

impl<A, B> From<Vote<A, B>> for VoteWeight {
fn from(value: Vote<A, B>) -> Self {
fn from(_value: Vote<A, B>) -> Self {
todo!()
}
}

///
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Tally<T> {
_dummy: PhantomData<T>,
}
#[derive(Debug, Clone, Eq, PartialEq, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[scale_info(skip_type_params(T))]
#[codec(mel_bound(T: Config))]
pub struct Tally<T>(core::marker::PhantomData<T>);

impl<T: Config> VoteTally<VoteWeight, CommunityIdOf<T>> for Tally<T> {
fn new(_: CommunityIdOf<T>) -> Self {
impl<T: Config> VoteTally<VoteWeight, T::CommunityId> for Tally<T> {
fn new(_: T::CommunityId) -> Self {
todo!()
}

fn ayes(&self, _cid: CommunityIdOf<T>) -> VoteWeight {
fn ayes(&self, _cid: T::CommunityId) -> VoteWeight {
todo!()
}

fn support(&self, _cid: CommunityIdOf<T>) -> sp_runtime::Perbill {
todo!()
}

fn approval(&self, _cid: CommunityIdOf<T>) -> sp_runtime::Perbill {
todo!()
}
}

///
// #[cfg(feature = "referenda")]
pub struct CommunityTracks<T>(PhantomData<T>);

// #[cfg(feature = "referenda")]
impl<T: Config> TracksInfo<VoteWeight, BlockNumberFor<T>> for CommunityTracks<T> {
type Id = u16;
type RuntimeOrigin = RuntimeOriginOf<T>;

fn tracks() -> impl Iterator<Item = Cow<'static, Track<Self::Id, VoteWeight, BlockNumberFor<T>>>> {
fn support(&self, _cid: T::CommunityId) -> sp_runtime::Perbill {
todo!()
}

fn track_for(origin: &Self::RuntimeOrigin) -> Result<Self::Id, ()> {
fn approval(&self, _cid: T::CommunityId) -> sp_runtime::Perbill {
todo!()
}
}

0 comments on commit 14ecf35

Please sign in to comment.