mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 12:37:57 +00:00
pallet alliance (#11112)
* Add pallet-alliance Signed-off-by: koushiro <koushiro.cqx@gmail.com> * Update multihash/cid and format Signed-off-by: koushiro <koushiro.cqx@gmail.com> * Remove useless deps Signed-off-by: koushiro <koushiro.cqx@gmail.com> * Add pallet-alliance into node runtime Signed-off-by: koushiro <koushiro.cqx@gmail.com> * Fix has_identity Signed-off-by: koushiro <koushiro.cqx@gmail.com> * Add TooMantBlacklist Error Signed-off-by: koushiro <koushiro.cqx@gmail.com> * Add TooLongWebsiteUrlLength Error Signed-off-by: koushiro <koushiro.cqx@gmail.com> * Add remove_announcement Signed-off-by: koushiro <koushiro.cqx@gmail.com> * Derive pallet_identity::Config and Fix test/benchmarking Signed-off-by: koushiro <koushiro.cqx@gmail.com> * Add part weight for call of pallet-alliance Signed-off-by: koushiro <koushiro.cqx@gmail.com> * Remove pallet_identity Config trait Signed-off-by: koushiro <koushiro.cqx@gmail.com> * Fix propose arguments Signed-off-by: koushiro <koushiro.cqx@gmail.com> * Some nits Signed-off-by: koushiro <koushiro.cqx@gmail.com> * cargo fmt Signed-off-by: koushiro <koushiro.cqx@gmail.com> * Fix benchmarking of add_blacklist/remove_blacklist Signed-off-by: koushiro <koushiro.cqx@gmail.com> * Some nits Signed-off-by: koushiro <koushiro.cqx@gmail.com> * Add benchmarking for init_members Signed-off-by: koushiro <koushiro.cqx@gmail.com> * Add benchmarking for propose/vote/veto Signed-off-by: koushiro <koushiro.cqx@gmail.com> * Fix benchmarking Signed-off-by: koushiro <koushiro.cqx@gmail.com> * Remove some useless Signed-off-by: koushiro <koushiro.cqx@gmail.com> * fix some compile issue * more fix * all checks * refactor * refactor event * refactor * cleanup * cleanup * fix benchmarking * fix warning * fmt * fix benchmarks * with storage info * fmt * add new config * fix benchmarks * fix * fmt * Apply suggestions from code review Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * improvements * fix * update docs * rename events, errors, and functions * make kicking events clearer * fix * fix tests * fix tests * fix runtime * fix build * remove unneeded change * remove Candidate role from Alliance * fmt grumbles * update lock * update recursion limit * benchmarks * convert-try * benchmark assertions * fmt , * cargo lock * Update frame/alliance/src/benchmarking.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * add docs to public interfaces * Apply suggestions from code review Co-authored-by: Squirrel <gilescope@gmail.com> * fix build (node) * review * use EitherOfDiverse * update cargo toml * make all dispatch class Normal * change blacklist to unscrupulous * formatting * fmt oops * rename benchmarking unscrupulous account creator Co-authored-by: koushiro <koushiro.cqx@gmail.com> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: joepetrowski <joe@parity.io> Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> Co-authored-by: Squirrel <gilescope@gmail.com>
This commit is contained in:
@@ -17,12 +17,19 @@
|
||||
|
||||
//! Some configurable implementations as associated type for the substrate runtime.
|
||||
|
||||
use crate::{AccountId, Assets, Authorship, Balances, NegativeImbalance, Runtime};
|
||||
use frame_support::traits::{
|
||||
fungibles::{Balanced, CreditOf},
|
||||
Currency, OnUnbalanced,
|
||||
use crate::{
|
||||
AccountId, AllianceMotion, Assets, Authorship, Balances, Call, Hash, NegativeImbalance, Runtime,
|
||||
};
|
||||
use frame_support::{
|
||||
pallet_prelude::*,
|
||||
traits::{
|
||||
fungibles::{Balanced, CreditOf},
|
||||
Currency, OnUnbalanced,
|
||||
},
|
||||
};
|
||||
use pallet_alliance::{IdentityVerifier, ProposalIndex, ProposalProvider};
|
||||
use pallet_asset_tx_payment::HandleCredit;
|
||||
use sp_std::prelude::*;
|
||||
|
||||
pub struct Author;
|
||||
impl OnUnbalanced<NegativeImbalance> for Author {
|
||||
@@ -45,6 +52,68 @@ impl HandleCredit<AccountId, Assets> for CreditToBlockAuthor {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AllianceIdentityVerifier;
|
||||
impl IdentityVerifier<AccountId> for AllianceIdentityVerifier {
|
||||
fn has_identity(who: &AccountId, fields: u64) -> bool {
|
||||
crate::Identity::has_identity(who, fields)
|
||||
}
|
||||
|
||||
fn has_good_judgement(who: &AccountId) -> bool {
|
||||
use pallet_identity::Judgement;
|
||||
if let Some(judgements) =
|
||||
crate::Identity::identity(who).map(|registration| registration.judgements)
|
||||
{
|
||||
judgements
|
||||
.iter()
|
||||
.any(|(_, j)| matches!(j, Judgement::KnownGood | Judgement::Reasonable))
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fn super_account_id(who: &AccountId) -> Option<AccountId> {
|
||||
crate::Identity::super_of(who).map(|parent| parent.0)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AllianceProposalProvider;
|
||||
impl ProposalProvider<AccountId, Hash, Call> for AllianceProposalProvider {
|
||||
fn propose_proposal(
|
||||
who: AccountId,
|
||||
threshold: u32,
|
||||
proposal: Box<Call>,
|
||||
length_bound: u32,
|
||||
) -> Result<(u32, u32), DispatchError> {
|
||||
AllianceMotion::do_propose_proposed(who, threshold, proposal, length_bound)
|
||||
}
|
||||
|
||||
fn vote_proposal(
|
||||
who: AccountId,
|
||||
proposal: Hash,
|
||||
index: ProposalIndex,
|
||||
approve: bool,
|
||||
) -> Result<bool, DispatchError> {
|
||||
AllianceMotion::do_vote(who, proposal, index, approve)
|
||||
}
|
||||
|
||||
fn veto_proposal(proposal_hash: Hash) -> u32 {
|
||||
AllianceMotion::do_disapprove_proposal(proposal_hash)
|
||||
}
|
||||
|
||||
fn close_proposal(
|
||||
proposal_hash: Hash,
|
||||
proposal_index: ProposalIndex,
|
||||
proposal_weight_bound: Weight,
|
||||
length_bound: u32,
|
||||
) -> DispatchResultWithPostInfo {
|
||||
AllianceMotion::do_close(proposal_hash, proposal_index, proposal_weight_bound, length_bound)
|
||||
}
|
||||
|
||||
fn proposal_of(proposal_hash: Hash) -> Option<Call> {
|
||||
AllianceMotion::proposal_of(proposal_hash)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod multiplier_tests {
|
||||
use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment};
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
//! The Substrate runtime. This can be compiled with `#[no_std]`, ready for Wasm.
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
|
||||
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 512.
|
||||
#![recursion_limit = "512"]
|
||||
|
||||
use codec::{Decode, Encode, MaxEncodedLen};
|
||||
@@ -90,7 +90,9 @@ pub use sp_runtime::BuildStorage;
|
||||
|
||||
/// Implementations of some helper traits passed into runtime modules as associated types.
|
||||
pub mod impls;
|
||||
use impls::{Author, CreditToBlockAuthor};
|
||||
#[cfg(not(feature = "runtime-benchmarks"))]
|
||||
use impls::AllianceIdentityVerifier;
|
||||
use impls::{AllianceProposalProvider, Author, CreditToBlockAuthor};
|
||||
|
||||
/// Constant values used within the runtime.
|
||||
pub mod constants;
|
||||
@@ -1506,6 +1508,67 @@ impl pallet_state_trie_migration::Config for Runtime {
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const AllianceMotionDuration: BlockNumber = 5 * DAYS;
|
||||
pub const AllianceMaxProposals: u32 = 100;
|
||||
pub const AllianceMaxMembers: u32 = 100;
|
||||
}
|
||||
|
||||
type AllianceCollective = pallet_collective::Instance3;
|
||||
impl pallet_collective::Config<AllianceCollective> for Runtime {
|
||||
type Origin = Origin;
|
||||
type Proposal = Call;
|
||||
type Event = Event;
|
||||
type MotionDuration = AllianceMotionDuration;
|
||||
type MaxProposals = AllianceMaxProposals;
|
||||
type MaxMembers = AllianceMaxMembers;
|
||||
type DefaultVote = pallet_collective::PrimeDefaultVote;
|
||||
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const MaxFounders: u32 = 10;
|
||||
pub const MaxFellows: u32 = AllianceMaxMembers::get() - MaxFounders::get();
|
||||
pub const MaxAllies: u32 = 100;
|
||||
pub const AllyDeposit: Balance = 10 * DOLLARS;
|
||||
}
|
||||
|
||||
impl pallet_alliance::Config for Runtime {
|
||||
type Event = Event;
|
||||
type Proposal = Call;
|
||||
type AdminOrigin = EitherOfDiverse<
|
||||
EnsureRoot<AccountId>,
|
||||
pallet_collective::EnsureProportionMoreThan<AccountId, AllianceCollective, 2, 3>,
|
||||
>;
|
||||
type MembershipManager = EitherOfDiverse<
|
||||
EnsureRoot<AccountId>,
|
||||
pallet_collective::EnsureProportionMoreThan<AccountId, AllianceCollective, 2, 3>,
|
||||
>;
|
||||
type AnnouncementOrigin = EitherOfDiverse<
|
||||
EnsureRoot<AccountId>,
|
||||
pallet_collective::EnsureProportionMoreThan<AccountId, AllianceCollective, 2, 3>,
|
||||
>;
|
||||
type Currency = Balances;
|
||||
type Slashed = Treasury;
|
||||
type InitializeMembers = AllianceMotion;
|
||||
type MembershipChanged = AllianceMotion;
|
||||
#[cfg(not(feature = "runtime-benchmarks"))]
|
||||
type IdentityVerifier = AllianceIdentityVerifier;
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
type IdentityVerifier = ();
|
||||
type ProposalProvider = AllianceProposalProvider;
|
||||
type MaxProposals = AllianceMaxProposals;
|
||||
type MaxFounders = MaxFounders;
|
||||
type MaxFellows = MaxFellows;
|
||||
type MaxAllies = MaxAllies;
|
||||
type MaxUnscrupulousItems = ConstU32<100>;
|
||||
type MaxWebsiteUrlLength = ConstU32<255>;
|
||||
type MaxAnnouncementsCount = ConstU32<100>;
|
||||
type MaxMembersCount = AllianceMaxMembers;
|
||||
type AllyDeposit = AllyDeposit;
|
||||
type WeightInfo = pallet_alliance::weights::SubstrateWeight<Runtime>;
|
||||
}
|
||||
|
||||
construct_runtime!(
|
||||
pub enum Runtime where
|
||||
Block = Block,
|
||||
@@ -1563,6 +1626,8 @@ construct_runtime!(
|
||||
Remark: pallet_remark,
|
||||
ConvictionVoting: pallet_conviction_voting,
|
||||
Whitelist: pallet_whitelist,
|
||||
AllianceMotion: pallet_collective::<Instance3>,
|
||||
Alliance: pallet_alliance,
|
||||
NominationPools: pallet_nomination_pools,
|
||||
RankedPolls: pallet_referenda::<Instance2>,
|
||||
RankedCollective: pallet_ranked_collective,
|
||||
@@ -2049,7 +2114,6 @@ impl_runtime_apis! {
|
||||
let mut batches = Vec::<BenchmarkBatch>::new();
|
||||
let params = (&config, &whitelist);
|
||||
add_benchmarks!(params, batches);
|
||||
|
||||
Ok(batches)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user