Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
iStrike7 committed Dec 8, 2022
1 parent 17c9384 commit b340f09
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 70 deletions.
76 changes: 33 additions & 43 deletions frame/collective-mangata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@

use scale_info::TypeInfo;
use sp_io::storage;
use sp_runtime::{traits::{Hash, Saturating}, RuntimeDebug};
use sp_runtime::{
traits::{Hash, Saturating},
RuntimeDebug,
};
use sp_std::{marker::PhantomData, prelude::*, result, vec};

use frame_support::{
Expand Down Expand Up @@ -329,9 +332,9 @@ pub mod pallet {
/// A proposal was closed because its threshold was reached or after its duration was up.
Closed { proposal_hash: T::Hash, yes: MemberCount, no: MemberCount },
/// The members have been changed
MembersChanged {new_members: Vec<T::AccountId>},
MembersChanged { new_members: Vec<T::AccountId> },
/// The Prime member has been set
PrimeSet {new_prime: Option<T::AccountId>},
PrimeSet { new_prime: Option<T::AccountId> },
}

#[pallet::error]
Expand All @@ -350,7 +353,8 @@ pub mod pallet {
AlreadyInitialized,
/// The close call was made too early, before the end of the voting.
TooEarly,
/// To early to close the proposal, can only close ProposalCloseDelay blocks after proposal was proposed
/// To early to close the proposal, can only close ProposalCloseDelay blocks after proposal
/// was proposed
TooEarlyToClose,
/// There can only be a maximum of `MaxProposals` active proposals.
TooManyProposals,
Expand Down Expand Up @@ -727,12 +731,8 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
proposal_hash,
result: result.map(|_| ()).map_err(|e| e.error),
});

alert_log!(
info,
"A member has executed a proposal! Proposal: {:?}",
proposal
);

alert_log!(info, "A member has executed a proposal! Proposal: {:?}", proposal);

Ok((proposal_len as u32, result))
}
Expand All @@ -759,7 +759,10 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
let index = Self::proposal_count();
<ProposalCount<T, I>>::mutate(|i| *i += 1);
<ProposalOf<T, I>>::insert(proposal_hash, proposal.clone());
<ProposalProposedTime<T, I>>::insert(proposal_hash, frame_system::Pallet::<T>::block_number());
<ProposalProposedTime<T, I>>::insert(
proposal_hash,
frame_system::Pallet::<T>::block_number(),
);

let votes = {
let end = frame_system::Pallet::<T>::block_number() + T::MotionDuration::get();
Expand All @@ -773,12 +776,8 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
proposal_hash,
threshold,
});

alert_log!(
info,
"A proposal has been proposed! Proposal: {:?}",
proposal
);

alert_log!(info, "A proposal has been proposed! Proposal: {:?}", proposal);

Ok((proposal_len as u32, active_proposals as u32))
}
Expand Down Expand Up @@ -855,9 +854,14 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {

// To allow previously existing proposals to be executed we use unwrap_or_default
// This can be removed later on when no proposals are without a proposed time in storage.
let proposal_proposed_time = Self::proposal_proposed_time(&proposal_hash).unwrap_or_default();
let proposal_proposed_time =
Self::proposal_proposed_time(&proposal_hash).unwrap_or_default();
// Only allow actual closing of the proposal after the voting period has ended.
ensure!(frame_system::Pallet::<T>::block_number() >= proposal_proposed_time.saturating_add(T::ProposalCloseDelay::get()), Error::<T, I>::TooEarlyToClose);
ensure!(
frame_system::Pallet::<T>::block_number() >=
proposal_proposed_time.saturating_add(T::ProposalCloseDelay::get()),
Error::<T, I>::TooEarlyToClose
);

let mut no_votes = voting.nays.len() as MemberCount;
let mut yes_votes = voting.ayes.len() as MemberCount;
Expand All @@ -872,7 +876,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
proposal_weight_bound,
)?;
Self::deposit_event(Event::Closed { proposal_hash, yes: yes_votes, no: no_votes });

alert_log!(
info,
"A proposal has been closed! Proposal Hash: {:?}",
Expand All @@ -891,7 +895,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
.into())
} else if disapproved {
Self::deposit_event(Event::Closed { proposal_hash, yes: yes_votes, no: no_votes });

alert_log!(
info,
"A proposal has been closed! Proposal Hash: {:?}",
Expand Down Expand Up @@ -928,7 +932,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
proposal_weight_bound,
)?;
Self::deposit_event(Event::Closed { proposal_hash, yes: yes_votes, no: no_votes });

alert_log!(
info,
"A proposal has been closed! Proposal Hash: {:?}",
Expand All @@ -947,7 +951,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
.into())
} else {
Self::deposit_event(Event::Closed { proposal_hash, yes: yes_votes, no: no_votes });

alert_log!(
info,
"A proposal has been closed! Proposal Hash: {:?}",
Expand Down Expand Up @@ -1000,7 +1004,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
proposal: <T as Config<I>>::Proposal,
) -> (Weight, u32) {
Self::deposit_event(Event::Approved { proposal_hash });

alert_log!(
info,
"A proposal has been approved! Proposal Hash: {:?}, Proposal: {:?}",
Expand All @@ -1015,7 +1019,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
proposal_hash,
result: result.map(|_| ()).map_err(|e| e.error),
});

alert_log!(
info,
"A proposal has been executed! Proposal Hash: {:?}, Proposal: {:?}",
Expand Down Expand Up @@ -1112,30 +1116,16 @@ impl<T: Config<I>, I: 'static> ChangeMembers<T::AccountId> for Pallet<T, I> {
Members::<T, I>::put(new);
Prime::<T, I>::kill();

Pallet::<T, I>::deposit_event(Event::MembersChanged {
new_members: new.to_vec()
});

alert_log!(
info,
"Collective members have changed!!! New Members: {:?}",
new.to_vec(),
);
Pallet::<T, I>::deposit_event(Event::MembersChanged { new_members: new.to_vec() });

alert_log!(info, "Collective members have changed!!! New Members: {:?}", new.to_vec(),);
}

fn set_prime(prime: Option<T::AccountId>) {
Prime::<T, I>::set(prime.clone());
Pallet::<T, I>::deposit_event(Event::PrimeSet {
new_prime: prime.clone()
});

alert_log!(
info,
"Prime member has changed! New Prime: {:?}",
prime,
);
Pallet::<T, I>::deposit_event(Event::PrimeSet { new_prime: prime.clone() });

alert_log!(info, "Prime member has changed! New Prime: {:?}", prime,);
}

fn get_prime() -> Option<T::AccountId> {
Expand Down
20 changes: 7 additions & 13 deletions frame/collective-mangata/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,7 @@ fn close_with_prime_works() {
record(Event::Collective(CollectiveEvent::MembersChanged {
new_members: vec![1, 2, 3]
})),
record(Event::Collective(CollectiveEvent::PrimeSet {
new_prime: Some(3),
})),
record(Event::Collective(CollectiveEvent::PrimeSet { new_prime: Some(3) })),
record(Event::Collective(CollectiveEvent::Proposed {
account: 1,
proposal_index: 0,
Expand Down Expand Up @@ -473,9 +471,7 @@ fn close_with_voting_prime_works() {
record(Event::Collective(CollectiveEvent::MembersChanged {
new_members: vec![1, 2, 3]
})),
record(Event::Collective(CollectiveEvent::PrimeSet {
new_prime: Some(1),
})),
record(Event::Collective(CollectiveEvent::PrimeSet { new_prime: Some(1) })),
record(Event::Collective(CollectiveEvent::Proposed {
account: 1,
proposal_index: 0,
Expand Down Expand Up @@ -550,9 +546,7 @@ fn close_with_no_prime_but_majority_works() {
record(Event::CollectiveMajority(CollectiveEvent::MembersChanged {
new_members: vec![1, 2, 3, 4, 5]
})),
record(Event::CollectiveMajority(CollectiveEvent::PrimeSet {
new_prime: Some(5),
})),
record(Event::CollectiveMajority(CollectiveEvent::PrimeSet { new_prime: Some(5) })),
record(Event::CollectiveMajority(CollectiveEvent::Proposed {
account: 1,
proposal_index: 0,
Expand Down Expand Up @@ -952,7 +946,7 @@ fn motions_all_first_vote_free_works() {
assert_eq!(vote_rval.unwrap().pays_fee, Pays::Yes);

// Test close() Extrincis | Check DispatchResultWithPostInfo with Pay Info

System::set_block_number(3);

let proposal_weight = proposal.get_dispatch_info().weight;
Expand Down Expand Up @@ -982,7 +976,7 @@ fn motions_reproposing_disapproved_works() {
proposal_len
));
assert_ok!(Collective::vote(Origin::signed(2), hash, 0, false));

System::set_block_number(3);
assert_ok!(Collective::close(Origin::signed(2), hash, 0, proposal_weight, proposal_len));
assert_eq!(*Collective::proposals(), vec![]);
Expand Down Expand Up @@ -1016,7 +1010,7 @@ fn motions_approval_with_enough_votes_and_lower_voting_threshold_works() {
));
assert_ok!(Collective::vote(Origin::signed(1), hash, 0, true));
assert_ok!(Collective::vote(Origin::signed(2), hash, 0, true));

System::set_block_number(3);
assert_ok!(Collective::close(Origin::signed(2), hash, 0, proposal_weight, proposal_len));
assert_eq!(
Expand Down Expand Up @@ -1131,7 +1125,7 @@ fn motions_disapproval_works() {
));
assert_ok!(Collective::vote(Origin::signed(1), hash, 0, true));
assert_ok!(Collective::vote(Origin::signed(2), hash, 0, false));

System::set_block_number(3);
assert_ok!(Collective::close(Origin::signed(2), hash, 0, proposal_weight, proposal_len));

Expand Down
25 changes: 11 additions & 14 deletions frame/sudo-mangata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,10 @@ pub mod pallet {
ensure!(Self::key().map_or(false, |k| sender == k), Error::<T>::RequireSudo);

let res = call.clone().dispatch_bypass_filter(frame_system::RawOrigin::Root.into());
Self::deposit_event(Event::Sudid { sudo_result: res.clone().map(|_| ()).map_err(|e| e.error) });
alert_log!(
info,
"A sudo action was performed: Call - {:?}, Result - {:?}!",
call,
res
);
Self::deposit_event(Event::Sudid {
sudo_result: res.clone().map(|_| ()).map_err(|e| e.error),
});
alert_log!(info, "A sudo action was performed: Call - {:?}, Result - {:?}!", call, res);
// Sudo user does not pay a fee.
Ok(Pays::No.into())
}
Expand All @@ -196,7 +193,9 @@ pub mod pallet {
ensure!(Self::key().map_or(false, |k| sender == k), Error::<T>::RequireSudo);

let res = call.clone().dispatch_bypass_filter(frame_system::RawOrigin::Root.into());
Self::deposit_event(Event::Sudid { sudo_result: res.clone().map(|_| ()).map_err(|e| e.error) });
Self::deposit_event(Event::Sudid {
sudo_result: res.clone().map(|_| ()).map_err(|e| e.error),
});
alert_log!(
info,
"A sudo action was performed with unchecked weight: Call - {:?}, Result - {:?}!",
Expand Down Expand Up @@ -228,11 +227,7 @@ pub mod pallet {
let new = T::Lookup::lookup(new)?;

Self::deposit_event(Event::KeyChanged { old_sudoer: Key::<T>::get() });
alert_log!(
info,
"sudo key was changed: New Key - {:?}!",
new.clone(),
);
alert_log!(info, "sudo key was changed: New Key - {:?}!", new.clone(),);
Key::<T>::put(&new);
// Sudo user does not pay a fee.
Ok(Pays::No.into())
Expand Down Expand Up @@ -269,7 +264,9 @@ pub mod pallet {

let who = T::Lookup::lookup(who)?;

let res = call.clone().dispatch_bypass_filter(frame_system::RawOrigin::Signed(who.clone()).into());
let res = call
.clone()
.dispatch_bypass_filter(frame_system::RawOrigin::Signed(who.clone()).into());

Self::deposit_event(Event::SudoAsDone {
sudo_result: res.clone().map(|_| ()).map_err(|e| e.error),
Expand Down

0 comments on commit b340f09

Please sign in to comment.