Skip to content

Commit

Permalink
fix: too many params in constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
cuteolaf committed Mar 14, 2023
1 parent 3723c88 commit 662b582
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 30 deletions.
21 changes: 12 additions & 9 deletions pallets/voting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,18 @@ pub mod pallet {
let voting_proposal: VotingProposal<T, Box<<T as COLL::Config<Instance1>>::Proposal>> =
VotingProposal::new(
who.clone(),
proposal,
collective_passed_call,
collective_failed_call,
democracy_failed_call,
proposal_hash,
collective_index,
democracy_call_formatted.clone(),
T::Hashing::hash_of(&democracy_call_formatted),
T::Hashing::hash_of(&call_dispatch),
ProposalParams { call: proposal, hash: proposal_hash },
CollectiveParams {
call: democracy_call_formatted.clone(),
call_pass: collective_passed_call,
call_fail: collective_failed_call,
index: collective_index,
hash: T::Hashing::hash_of(&democracy_call_formatted),
},
DemocracyParams {
call_fail: democracy_failed_call,
hash: T::Hashing::hash_of(&call_dispatch),
},
);

VotingProposals::<T>::insert(proposal_hash, voting_proposal);
Expand Down
60 changes: 39 additions & 21 deletions pallets/voting/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,67 @@ pub type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
pub type BalanceOf<T> = <<T as Config>::LocalCurrency as Currency<AccountIdOf<T>>>::Balance;
pub type BlockNumberOf<T> = <T as frame_system::Config>::BlockNumber;

#[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)]
#[scale_info(skip_type_params(T))]
pub struct ProposalParams<T: Config> {
pub call: Box<<T as Config>::Call>,
pub hash: T::Hash,
}

#[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)]
#[scale_info(skip_type_params(T))]
pub struct CollectiveParams<T: Config, U> {
pub call_pass: Box<<T as Config>::Call>,
pub call_fail: Box<<T as Config>::Call>,
pub index: u32,
pub call: U,
pub hash: T::Hash,
}

#[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)]
#[scale_info(skip_type_params(T))]
pub struct DemocracyParams<T: Config> {
pub call_fail: Box<<T as Config>::Call>,
pub hash: T::Hash,
}

#[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)]
#[scale_info(skip_type_params(T))]
pub struct VotingProposal<T: Config, U> {
pub account_id: AccountIdOf<T>,
pub proposal_call: Box<<T as Config>::Call>,
pub proposal_hash: T::Hash,
pub collective_call: U,
pub collective_passed_call: Box<<T as Config>::Call>,
pub collective_failed_call: Box<<T as Config>::Call>,
pub democracy_failed_call: Box<<T as Config>::Call>,
pub proposal_hash: T::Hash,
pub collective_index: u32,
pub collective_call: U,
pub collective_hash: T::Hash,
pub collective_step: bool,
pub collective_closed: bool,
pub democracy_failed_call: Box<<T as Config>::Call>,
pub democracy_referendum_index: u32,
pub democracy_hash: T::Hash,
pub proposal_executed: bool,
}
impl<T: Config, U> VotingProposal<T, U> {
pub fn new(
account_id: AccountIdOf<T>,
proposal_call: Box<<T as Config>::Call>,
collective_passed_call: Box<<T as Config>::Call>,
collective_failed_call: Box<<T as Config>::Call>,
democracy_failed_call: Box<<T as Config>::Call>,
proposal_hash: T::Hash,
collective_index: u32,
collective_call: U,
collective_hash: T::Hash,
democracy_hash: T::Hash,
proposal: ProposalParams<T>,
collective: CollectiveParams<T, U>,
democracy: DemocracyParams<T>,
) -> VotingProposal<T, U> {
Self {
account_id,
proposal_call,
collective_passed_call,
collective_failed_call,
democracy_failed_call,
proposal_hash,
collective_index,
collective_call,
collective_hash,
proposal_call: proposal.call,
proposal_hash: proposal.hash,
collective_passed_call: collective.call_pass,
collective_failed_call: collective.call_fail,
collective_index: collective.index,
collective_call: collective.call,
collective_hash: collective.hash,
democracy_failed_call: democracy.call_fail,
democracy_hash: democracy.hash,
democracy_referendum_index: 0,
democracy_hash,
proposal_executed: false,
collective_step: false,
collective_closed: false,
Expand Down

0 comments on commit 662b582

Please sign in to comment.