Skip to content

Commit

Permalink
feat: implement on runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
devwckd committed Dec 16, 2024
1 parent db3e224 commit 9c75e5d
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pallets/governance/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn submit_application<T: crate::Config>(
if data_len < T::MinApplicationDataLength::get()
|| data_len > T::MaxApplicationDataLength::get()
{
return Err(crate::Error::<T>::InvalidApplicationDataLength)?;
return Err(crate::Error::<T>::InvalidApplicationDataLength.into());
}

let current_block: u64 =
Expand Down
2 changes: 1 addition & 1 deletion pallets/governance/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub(super) fn remove_balance<T: crate::Config>(
}

pub(super) fn add_balance<T: crate::Config>(key: &AccountIdOf<T>, amount: BalanceOf<T>) {
let _ = <T as crate::Config>::Currency::deposit_creating(&key, amount);
let _ = <T as crate::Config>::Currency::deposit_creating(key, amount);
}

pub(super) fn transfer_balance<T: crate::Config>(
Expand Down
1 change: 1 addition & 0 deletions pallets/governance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use polkadot_sdk::sp_std::vec::Vec;

#[frame::pallet(dev_mode)]
pub mod pallet {
#![allow(clippy::too_many_arguments)]

use super::*;

Expand Down
5 changes: 3 additions & 2 deletions pallets/governance/src/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::BoundedVec;
use crate::DebugNoBound;
use crate::TypeInfo;
use crate::{
get_balance, transfer_balance, AccountIdOf, BalanceOf, Block, DaoTreasuryAddress, Error, Event,
get_balance, transfer_balance, AccountIdOf, BalanceOf, Block, DaoTreasuryAddress, Error,
GlobalGovernanceConfig, Proposals, UnrewardedProposals,
};
use crate::{GovernanceConfiguration, NotDelegatingVotingPower};
Expand Down Expand Up @@ -194,6 +194,7 @@ pub struct UnrewardedProposal<T: crate::Config> {
pub votes_against: BoundedBTreeMap<AccountIdOf<T>, BalanceOf<T>, ConstU32<{ u32::MAX }>>,
}

#[allow(clippy::too_many_arguments)]
pub fn add_global_params_proposal<T: crate::Config>(
proposer: AccountIdOf<T>,
min_name_length: u16,
Expand Down Expand Up @@ -262,7 +263,7 @@ fn add_proposal<T: crate::Config>(

let proposal = Proposal::<T> {
id: proposal_id,
proposer: proposer,
proposer,
expiration_block: current_block + config.proposal_expiration,
data,
status: ProposalStatus::Open {
Expand Down
16 changes: 2 additions & 14 deletions pallets/governance/src/voting.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
use crate::{
get_balance,
proposal::{Proposal, ProposalStatus, UnrewardedProposal},
transfer_balance, AccountIdOf, BalanceOf, Block, DaoTreasuryAddress, Error, Event,
GlobalGovernanceConfig, Proposals, UnrewardedProposals,
};
use crate::{GovernanceConfiguration, NotDelegatingVotingPower};
use polkadot_sdk::sp_std::{collections::btree_set::BTreeSet, vec::Vec};
use polkadot_sdk::{frame_support::traits::tokens::Balance, sp_runtime::SaturatedConversion};
use crate::{proposal::ProposalStatus, AccountIdOf, Error, Event, Proposals};
use polkadot_sdk::{
frame_support::{dispatch::DispatchResult, ensure, storage::with_storage_layer},
frame_support::{dispatch::DispatchResult, ensure},
polkadot_sdk_frame::prelude::OriginFor,
sc_telemetry::log,
sp_core::ConstU32,
sp_runtime::{BoundedBTreeMap, DispatchError, Percent},
};
use substrate_fixed::types::I92F36;

pub fn add_vote<T: crate::Config>(
voter: AccountIdOf<T>,
Expand Down
10 changes: 10 additions & 0 deletions runtime/src/configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,5 +333,15 @@ parameter_types! {
impl pallet_governance::Config for Runtime {
type PalletId = GovernancePalletId;

type MinApplicationDataLength = ConstU32<2>;

type MaxApplicationDataLength = ConstU32<256>;

type ApplicationExpiration = ConstU64<2000>;

type MaxPenaltyPercentage = ConstU8<20>;

type RuntimeEvent = RuntimeEvent;

type Currency = Balances;
}
3 changes: 3 additions & 0 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ mod runtime {

#[runtime::pallet_index(11)]
pub type Torus0 = pallet_torus0::Pallet<Runtime>;

#[runtime::pallet_index(12)]
pub type Governance = pallet_governance::Pallet<Runtime>;
}

parameter_types! {
Expand Down

0 comments on commit 9c75e5d

Please sign in to comment.