From 662b582ef1c342fa91a2d116a1c4aba59cec1081 Mon Sep 17 00:00:00 2001 From: cuteolaf Date: Tue, 14 Mar 2023 10:11:34 -0700 Subject: [PATCH] fix: too many params in constructor --- pallets/voting/src/lib.rs | 21 ++++++------ pallets/voting/src/structs.rs | 60 +++++++++++++++++++++++------------ 2 files changed, 51 insertions(+), 30 deletions(-) diff --git a/pallets/voting/src/lib.rs b/pallets/voting/src/lib.rs index 1f60c8e5..a8538797 100644 --- a/pallets/voting/src/lib.rs +++ b/pallets/voting/src/lib.rs @@ -238,15 +238,18 @@ pub mod pallet { let voting_proposal: VotingProposal>::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::::insert(proposal_hash, voting_proposal); diff --git a/pallets/voting/src/structs.rs b/pallets/voting/src/structs.rs index e423cfad..a197fdf3 100644 --- a/pallets/voting/src/structs.rs +++ b/pallets/voting/src/structs.rs @@ -12,20 +12,44 @@ pub type AccountIdOf = ::AccountId; pub type BalanceOf = <::LocalCurrency as Currency>>::Balance; pub type BlockNumberOf = ::BlockNumber; +#[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[scale_info(skip_type_params(T))] +pub struct ProposalParams { + pub call: Box<::Call>, + pub hash: T::Hash, +} + +#[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[scale_info(skip_type_params(T))] +pub struct CollectiveParams { + pub call_pass: Box<::Call>, + pub call_fail: Box<::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 { + pub call_fail: Box<::Call>, + pub hash: T::Hash, +} + #[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] #[scale_info(skip_type_params(T))] pub struct VotingProposal { pub account_id: AccountIdOf, pub proposal_call: Box<::Call>, + pub proposal_hash: T::Hash, + pub collective_call: U, pub collective_passed_call: Box<::Call>, pub collective_failed_call: Box<::Call>, - pub democracy_failed_call: Box<::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<::Call>, pub democracy_referendum_index: u32, pub democracy_hash: T::Hash, pub proposal_executed: bool, @@ -33,28 +57,22 @@ pub struct VotingProposal { impl VotingProposal { pub fn new( account_id: AccountIdOf, - proposal_call: Box<::Call>, - collective_passed_call: Box<::Call>, - collective_failed_call: Box<::Call>, - democracy_failed_call: Box<::Call>, - proposal_hash: T::Hash, - collective_index: u32, - collective_call: U, - collective_hash: T::Hash, - democracy_hash: T::Hash, + proposal: ProposalParams, + collective: CollectiveParams, + democracy: DemocracyParams, ) -> VotingProposal { 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,