Run cargo fmt on the whole code base (#9394)

* Run cargo fmt on the whole code base

* Second run

* Add CI check

* Fix compilation

* More unnecessary braces

* Handle weights

* Use --all

* Use correct attributes...

* Fix UI tests

* AHHHHHHHHH

* 🤦

* Docs

* Fix compilation

* 🤷

* Please stop

* 🤦 x 2

* More

* make rustfmt.toml consistent with polkadot

Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
Bastian Köcher
2021-07-21 16:32:32 +02:00
committed by GitHub
parent d451c38c1c
commit 7b56ab15b4
1010 changed files with 53339 additions and 51208 deletions
+164 -136
View File
@@ -121,7 +121,7 @@
//! This call can only be made by the `ExternalMajorityOrigin`.
//!
//! - `external_propose_majority` - Schedules a proposal to become a majority-carries
//! referendum once it is legal for an externally proposed referendum.
//! referendum once it is legal for an externally proposed referendum.
//!
//! #### External Default Origin
//!
@@ -149,34 +149,36 @@
//! - `cancel_queued` - Cancels a proposal that is queued for enactment.
//! - `clear_public_proposal` - Removes all public proposals.
#![recursion_limit="128"]
#![recursion_limit = "128"]
#![cfg_attr(not(feature = "std"), no_std)]
use sp_std::prelude::*;
use sp_runtime::{
DispatchResult, DispatchError, ArithmeticError, RuntimeDebug,
traits::{Zero, Hash, Dispatchable, Saturating, Bounded},
};
use codec::{Encode, Decode, Input};
use codec::{Decode, Encode, Input};
use frame_support::{
ensure, weights::Weight,
ensure,
traits::{
Currency, ReservableCurrency, LockableCurrency, WithdrawReasons, LockIdentifier, Get,
OnUnbalanced, BalanceStatus, schedule::{Named as ScheduleNamed, DispatchTime},
schedule::{DispatchTime, Named as ScheduleNamed},
BalanceStatus, Currency, Get, LockIdentifier, LockableCurrency, OnUnbalanced,
ReservableCurrency, WithdrawReasons,
},
weights::Weight,
};
use sp_runtime::{
traits::{Bounded, Dispatchable, Hash, Saturating, Zero},
ArithmeticError, DispatchError, DispatchResult, RuntimeDebug,
};
use sp_std::prelude::*;
mod vote_threshold;
mod vote;
mod conviction;
mod types;
mod vote;
mod vote_threshold;
pub mod weights;
pub use weights::WeightInfo;
pub use vote_threshold::{Approved, VoteThreshold};
pub use vote::{Vote, AccountVote, Voting};
pub use conviction::Conviction;
pub use types::{ReferendumInfo, ReferendumStatus, Tally, UnvoteScope, Delegations};
pub use pallet::*;
pub use types::{Delegations, ReferendumInfo, ReferendumStatus, Tally, UnvoteScope};
pub use vote::{AccountVote, Vote, Voting};
pub use vote_threshold::{Approved, VoteThreshold};
pub use weights::WeightInfo;
#[cfg(test)]
mod tests;
@@ -197,9 +199,11 @@ pub type PropIndex = u32;
/// A referendum index.
pub type ReferendumIndex = u32;
type BalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
type NegativeImbalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance;
type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
type NegativeImbalanceOf<T> = <<T as Config>::Currency as Currency<
<T as frame_system::Config>::AccountId,
>>::NegativeImbalance;
#[derive(Clone, Encode, Decode, RuntimeDebug)]
pub enum PreimageStatus<AccountId, Balance, BlockNumber> {
@@ -235,13 +239,16 @@ enum Releases {
#[frame_support::pallet]
pub mod pallet {
use sp_runtime::DispatchResult;
use frame_support::{
pallet_prelude::*, Parameter,
weights::{DispatchClass, Pays}, traits::EnsureOrigin, dispatch::DispatchResultWithPostInfo,
};
use frame_system::{pallet_prelude::*, ensure_signed, ensure_root};
use super::*;
use frame_support::{
dispatch::DispatchResultWithPostInfo,
pallet_prelude::*,
traits::EnsureOrigin,
weights::{DispatchClass, Pays},
Parameter,
};
use frame_system::{ensure_root, ensure_signed, pallet_prelude::*};
use sp_runtime::DispatchResult;
#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
@@ -249,12 +256,12 @@ pub mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config + Sized {
type Proposal: Parameter + Dispatchable<Origin=Self::Origin> + From<Call<Self>>;
type Proposal: Parameter + Dispatchable<Origin = Self::Origin> + From<Call<Self>>;
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
/// Currency type for this pallet.
type Currency: ReservableCurrency<Self::AccountId>
+ LockableCurrency<Self::AccountId, Moment=Self::BlockNumber>;
+ LockableCurrency<Self::AccountId, Moment = Self::BlockNumber>;
/// The minimum period of locking and the period between a proposal being approved and enacted.
///
@@ -323,7 +330,7 @@ pub mod pallet {
///
/// The number of Vetoers for a proposal must be small, extrinsics are weighted according to
/// [MAX_VETOERS](./const.MAX_VETOERS.html)
type VetoOrigin: EnsureOrigin<Self::Origin, Success=Self::AccountId>;
type VetoOrigin: EnsureOrigin<Self::Origin, Success = Self::AccountId>;
/// Period in blocks where an external proposal may not be re-submitted after being vetoed.
#[pallet::constant]
@@ -334,7 +341,7 @@ pub mod pallet {
type PreimageByteDeposit: Get<BalanceOf<Self>>;
/// An origin that can provide a preimage using operational extrinsics.
type OperationalPreimageOrigin: EnsureOrigin<Self::Origin, Success=Self::AccountId>;
type OperationalPreimageOrigin: EnsureOrigin<Self::Origin, Success = Self::AccountId>;
/// Handler for the unbalanced reduction when slashing a preimage deposit.
type Slash: OnUnbalanced<NegativeImbalanceOf<Self>>;
@@ -370,18 +377,16 @@ pub mod pallet {
/// The public proposals. Unsorted. The second item is the proposal's hash.
#[pallet::storage]
#[pallet::getter(fn public_props)]
pub type PublicProps<T: Config> = StorageValue<_, Vec<(PropIndex, T::Hash, T::AccountId)>, ValueQuery>;
pub type PublicProps<T: Config> =
StorageValue<_, Vec<(PropIndex, T::Hash, T::AccountId)>, ValueQuery>;
/// Those who have locked a deposit.
///
/// TWOX-NOTE: Safe, as increasing integer keys are safe.
#[pallet::storage]
#[pallet::getter(fn deposit_of)]
pub type DepositOf<T: Config> = StorageMap<
_,
Twox64Concat, PropIndex,
(Vec<T::AccountId>, BalanceOf<T>),
>;
pub type DepositOf<T: Config> =
StorageMap<_, Twox64Concat, PropIndex, (Vec<T::AccountId>, BalanceOf<T>)>;
/// Map of hashes to the proposal preimage, along with who registered it and their deposit.
/// The block number is the block at which it was deposited.
@@ -390,7 +395,8 @@ pub mod pallet {
#[pallet::storage]
pub type Preimages<T: Config> = StorageMap<
_,
Identity, T::Hash,
Identity,
T::Hash,
PreimageStatus<T::AccountId, BalanceOf<T>, T::BlockNumber>,
>;
@@ -412,7 +418,8 @@ pub mod pallet {
#[pallet::getter(fn referendum_info)]
pub type ReferendumInfoOf<T: Config> = StorageMap<
_,
Twox64Concat, ReferendumIndex,
Twox64Concat,
ReferendumIndex,
ReferendumInfo<T::BlockNumber, T::Hash, BalanceOf<T>>,
>;
@@ -422,7 +429,9 @@ pub mod pallet {
/// TWOX-NOTE: SAFE as `AccountId`s are crypto hashes anyway.
#[pallet::storage]
pub type VotingOf<T: Config> = StorageMap<
_, Twox64Concat, T::AccountId,
_,
Twox64Concat,
T::AccountId,
Voting<BalanceOf<T>, T::AccountId, T::BlockNumber>,
ValueQuery,
>;
@@ -452,7 +461,8 @@ pub mod pallet {
/// A record of who vetoed what. Maps proposal hash to a possible existent block number
/// (until when it may not be resubmitted) and who vetoed it.
#[pallet::storage]
pub type Blacklist<T: Config> = StorageMap<_, Identity, T::Hash, (T::BlockNumber, Vec<T::AccountId>)>;
pub type Blacklist<T: Config> =
StorageMap<_, Identity, T::Hash, (T::BlockNumber, Vec<T::AccountId>)>;
/// Record of all proposals that have been subject to emergency cancellation.
#[pallet::storage]
@@ -472,9 +482,7 @@ pub mod pallet {
#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
GenesisConfig {
_phantom: Default::default(),
}
GenesisConfig { _phantom: Default::default() }
}
}
@@ -684,11 +692,10 @@ pub mod pallet {
) -> DispatchResult {
let who = ensure_signed(origin)?;
let seconds = Self::len_of_deposit_of(proposal)
.ok_or_else(|| Error::<T>::ProposalMissing)?;
let seconds =
Self::len_of_deposit_of(proposal).ok_or_else(|| Error::<T>::ProposalMissing)?;
ensure!(seconds <= seconds_upper_bound, Error::<T>::WrongUpperBound);
let mut deposit = Self::deposit_of(proposal)
.ok_or(Error::<T>::ProposalMissing)?;
let mut deposit = Self::deposit_of(proposal).ok_or(Error::<T>::ProposalMissing)?;
T::Currency::reserve(&who, deposit.1)?;
deposit.0.push(who);
<DepositOf<T>>::insert(proposal, deposit);
@@ -726,7 +733,10 @@ pub mod pallet {
///
/// Weight: `O(1)`.
#[pallet::weight((T::WeightInfo::emergency_cancel(), DispatchClass::Operational))]
pub fn emergency_cancel(origin: OriginFor<T>, ref_index: ReferendumIndex) -> DispatchResult {
pub fn emergency_cancel(
origin: OriginFor<T>,
ref_index: ReferendumIndex,
) -> DispatchResult {
T::CancellationOrigin::ensure_origin(origin)?;
let status = Self::referendum_status(ref_index)?;
@@ -842,8 +852,8 @@ pub mod pallet {
ensure!(T::InstantAllowed::get(), Error::<T>::InstantNotAllowed);
}
let (e_proposal_hash, threshold) = <NextExternal<T>>::get()
.ok_or(Error::<T>::ProposalMissing)?;
let (e_proposal_hash, threshold) =
<NextExternal<T>>::get().ok_or(Error::<T>::ProposalMissing)?;
ensure!(
threshold != VoteThreshold::SuperMajorityApprove,
Error::<T>::NotSimpleMajority,
@@ -875,11 +885,10 @@ pub mod pallet {
Err(Error::<T>::NoProposal)?;
}
let mut existing_vetoers = <Blacklist<T>>::get(&proposal_hash)
.map(|pair| pair.1)
.unwrap_or_else(Vec::new);
let insert_position = existing_vetoers.binary_search(&who)
.err().ok_or(Error::<T>::AlreadyVetoed)?;
let mut existing_vetoers =
<Blacklist<T>>::get(&proposal_hash).map(|pair| pair.1).unwrap_or_else(Vec::new);
let insert_position =
existing_vetoers.binary_search(&who).err().ok_or(Error::<T>::AlreadyVetoed)?;
existing_vetoers.insert(insert_position, who.clone());
let until = <frame_system::Pallet<T>>::block_number() + T::CooloffPeriod::get();
@@ -949,7 +958,7 @@ pub mod pallet {
origin: OriginFor<T>,
to: T::AccountId,
conviction: Conviction,
balance: BalanceOf<T>
balance: BalanceOf<T>,
) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
let votes = Self::try_delegate(who, to, conviction, balance)?;
@@ -1089,10 +1098,11 @@ pub mod pallet {
let (provider, deposit, since, expiry) = <Preimages<T>>::get(&proposal_hash)
.and_then(|m| match m {
PreimageStatus::Available { provider, deposit, since, expiry, .. }
=> Some((provider, deposit, since, expiry)),
PreimageStatus::Available { provider, deposit, since, expiry, .. } =>
Some((provider, deposit, since, expiry)),
_ => None,
}).ok_or(Error::<T>::PreimageMissing)?;
})
.ok_or(Error::<T>::PreimageMissing)?;
let now = <frame_system::Pallet<T>>::block_number();
let (voting, enactment) = (T::VotingPeriod::get(), T::EnactmentPeriod::get());
@@ -1100,7 +1110,8 @@ pub mod pallet {
ensure!(now >= since + voting + additional, Error::<T>::TooEarly);
ensure!(expiry.map_or(true, |e| now > e), Error::<T>::Imminent);
let res = T::Currency::repatriate_reserved(&provider, &who, deposit, BalanceStatus::Free);
let res =
T::Currency::repatriate_reserved(&provider, &who, deposit, BalanceStatus::Free);
debug_assert!(res.is_ok());
<Preimages<T>>::remove(&proposal_hash);
Self::deposit_event(Event::<T>::PreimageReaped(proposal_hash, provider, deposit, who));
@@ -1211,7 +1222,8 @@ pub mod pallet {
/// Weight: `O(p)` (though as this is an high-privilege dispatch, we assume it has a
/// reasonable value).
#[pallet::weight((T::WeightInfo::blacklist(T::MaxProposals::get()), DispatchClass::Operational))]
pub fn blacklist(origin: OriginFor<T>,
pub fn blacklist(
origin: OriginFor<T>,
proposal_hash: T::Hash,
maybe_ref_index: Option<ReferendumIndex>,
) -> DispatchResult {
@@ -1288,7 +1300,7 @@ impl<T: Config> Pallet<T> {
/// Get all referenda ready for tally at block `n`.
pub fn maturing_referenda_at(
n: T::BlockNumber
n: T::BlockNumber,
) -> Vec<(ReferendumIndex, ReferendumStatus<T::BlockNumber, T::Hash, BalanceOf<T>>)> {
let next = Self::lowest_unbaked();
let last = Self::referendum_count();
@@ -1299,7 +1311,8 @@ impl<T: Config> Pallet<T> {
n: T::BlockNumber,
range: core::ops::Range<PropIndex>,
) -> Vec<(ReferendumIndex, ReferendumStatus<T::BlockNumber, T::Hash, BalanceOf<T>>)> {
range.into_iter()
range
.into_iter()
.map(|i| (i, Self::referendum_info(i)))
.filter_map(|(i, maybe_info)| match maybe_info {
Some(ReferendumInfo::Ongoing(status)) => Some((i, status)),
@@ -1315,13 +1328,13 @@ impl<T: Config> Pallet<T> {
pub fn internal_start_referendum(
proposal_hash: T::Hash,
threshold: VoteThreshold,
delay: T::BlockNumber
delay: T::BlockNumber,
) -> ReferendumIndex {
<Pallet<T>>::inject_referendum(
<frame_system::Pallet<T>>::block_number() + T::VotingPeriod::get(),
proposal_hash,
threshold,
delay
delay,
)
}
@@ -1334,25 +1347,28 @@ impl<T: Config> Pallet<T> {
// private.
/// Ok if the given referendum is active, Err otherwise
fn ensure_ongoing(r: ReferendumInfo<T::BlockNumber, T::Hash, BalanceOf<T>>)
-> Result<ReferendumStatus<T::BlockNumber, T::Hash, BalanceOf<T>>, DispatchError>
{
fn ensure_ongoing(
r: ReferendumInfo<T::BlockNumber, T::Hash, BalanceOf<T>>,
) -> Result<ReferendumStatus<T::BlockNumber, T::Hash, BalanceOf<T>>, DispatchError> {
match r {
ReferendumInfo::Ongoing(s) => Ok(s),
_ => Err(Error::<T>::ReferendumInvalid.into()),
}
}
fn referendum_status(ref_index: ReferendumIndex)
-> Result<ReferendumStatus<T::BlockNumber, T::Hash, BalanceOf<T>>, DispatchError>
{
let info = ReferendumInfoOf::<T>::get(ref_index)
.ok_or(Error::<T>::ReferendumInvalid)?;
fn referendum_status(
ref_index: ReferendumIndex,
) -> Result<ReferendumStatus<T::BlockNumber, T::Hash, BalanceOf<T>>, DispatchError> {
let info = ReferendumInfoOf::<T>::get(ref_index).ok_or(Error::<T>::ReferendumInvalid)?;
Self::ensure_ongoing(info)
}
/// Actually enact a vote, if legit.
fn try_vote(who: &T::AccountId, ref_index: ReferendumIndex, vote: AccountVote<BalanceOf<T>>) -> DispatchResult {
fn try_vote(
who: &T::AccountId,
ref_index: ReferendumIndex,
vote: AccountVote<BalanceOf<T>>,
) -> DispatchResult {
let mut status = Self::referendum_status(ref_index)?;
ensure!(vote.balance() <= T::Currency::free_balance(who), Error::<T>::InsufficientFunds);
VotingOf::<T>::try_mutate(who, |voting| -> DispatchResult {
@@ -1365,11 +1381,14 @@ impl<T: Config> Pallet<T> {
status.tally.reduce(approve, *delegations);
}
votes[i].1 = vote;
}
},
Err(i) => {
ensure!(votes.len() as u32 <= T::MaxVotes::get(), Error::<T>::MaxVotesReached);
ensure!(
votes.len() as u32 <= T::MaxVotes::get(),
Error::<T>::MaxVotesReached
);
votes.insert(i, (ref_index, vote));
}
},
}
// Shouldn't be possible to fail, but we handle it gracefully.
status.tally.add(vote).ok_or(ArithmeticError::Overflow)?;
@@ -1383,12 +1402,7 @@ impl<T: Config> Pallet<T> {
})?;
// Extend the lock to `balance` (rather than setting it) since we don't know what other
// votes are in place.
T::Currency::extend_lock(
DEMOCRACY_ID,
who,
vote.balance(),
WithdrawReasons::TRANSFER
);
T::Currency::extend_lock(DEMOCRACY_ID, who, vote.balance(), WithdrawReasons::TRANSFER);
ReferendumInfoOf::<T>::insert(ref_index, ReferendumInfo::Ongoing(status));
Ok(())
}
@@ -1399,11 +1413,17 @@ impl<T: Config> Pallet<T> {
/// - The referendum has finished and the voter's lock period is up.
///
/// This will generally be combined with a call to `unlock`.
fn try_remove_vote(who: &T::AccountId, ref_index: ReferendumIndex, scope: UnvoteScope) -> DispatchResult {
fn try_remove_vote(
who: &T::AccountId,
ref_index: ReferendumIndex,
scope: UnvoteScope,
) -> DispatchResult {
let info = ReferendumInfoOf::<T>::get(ref_index);
VotingOf::<T>::try_mutate(who, |voting| -> DispatchResult {
if let Voting::Direct { ref mut votes, delegations, ref mut prior } = voting {
let i = votes.binary_search_by_key(&ref_index, |i| i.0).map_err(|_| Error::<T>::NotVoter)?;
let i = votes
.binary_search_by_key(&ref_index, |i| i.0)
.map_err(|_| Error::<T>::NotVoter)?;
match info {
Some(ReferendumInfo::Ongoing(mut status)) => {
ensure!(matches!(scope, UnvoteScope::Any), Error::<T>::NoPermission);
@@ -1413,17 +1433,20 @@ impl<T: Config> Pallet<T> {
status.tally.reduce(approve, *delegations);
}
ReferendumInfoOf::<T>::insert(ref_index, ReferendumInfo::Ongoing(status));
}
Some(ReferendumInfo::Finished{end, approved}) =>
},
Some(ReferendumInfo::Finished { end, approved }) =>
if let Some((lock_periods, balance)) = votes[i].1.locked_if(approved) {
let unlock_at = end + T::EnactmentPeriod::get() * lock_periods.into();
let now = frame_system::Pallet::<T>::block_number();
if now < unlock_at {
ensure!(matches!(scope, UnvoteScope::Any), Error::<T>::NoPermission);
ensure!(
matches!(scope, UnvoteScope::Any),
Error::<T>::NoPermission
);
prior.accumulate(unlock_at, balance)
}
},
None => {} // Referendum was cancelled.
None => {}, // Referendum was cancelled.
}
votes.remove(i);
}
@@ -1444,15 +1467,15 @@ impl<T: Config> Pallet<T> {
*delegations = delegations.saturating_add(amount);
for &(ref_index, account_vote) in votes.iter() {
if let AccountVote::Standard { vote, .. } = account_vote {
ReferendumInfoOf::<T>::mutate(ref_index, |maybe_info|
ReferendumInfoOf::<T>::mutate(ref_index, |maybe_info| {
if let Some(ReferendumInfo::Ongoing(ref mut status)) = maybe_info {
status.tally.increase(vote.aye, amount);
}
);
});
}
}
votes.len() as u32
}
},
})
}
@@ -1463,20 +1486,20 @@ impl<T: Config> Pallet<T> {
// We don't support second level delegating, so we don't need to do anything more.
*delegations = delegations.saturating_sub(amount);
1
}
},
Voting::Direct { votes, delegations, .. } => {
*delegations = delegations.saturating_sub(amount);
for &(ref_index, account_vote) in votes.iter() {
if let AccountVote::Standard { vote, .. } = account_vote {
ReferendumInfoOf::<T>::mutate(ref_index, |maybe_info|
ReferendumInfoOf::<T>::mutate(ref_index, |maybe_info| {
if let Some(ReferendumInfo::Ongoing(ref mut status)) = maybe_info {
status.tally.reduce(vote.aye, amount);
}
);
});
}
}
votes.len() as u32
}
},
})
}
@@ -1505,22 +1528,17 @@ impl<T: Config> Pallet<T> {
// remove any delegation votes to our current target.
Self::reduce_upstream_delegation(&target, conviction.votes(balance));
voting.set_common(delegations, prior);
}
},
Voting::Direct { votes, delegations, prior } => {
// here we just ensure that we're currently idling with no votes recorded.
ensure!(votes.is_empty(), Error::<T>::VotesExist);
voting.set_common(delegations, prior);
}
},
}
let votes = Self::increase_upstream_delegation(&target, conviction.votes(balance));
// Extend the lock to `balance` (rather than setting it) since we don't know what other
// votes are in place.
T::Currency::extend_lock(
DEMOCRACY_ID,
&who,
balance,
WithdrawReasons::TRANSFER
);
T::Currency::extend_lock(DEMOCRACY_ID, &who, balance, WithdrawReasons::TRANSFER);
Ok(votes)
})?;
Self::deposit_event(Event::<T>::Delegated(who, target));
@@ -1535,25 +1553,18 @@ impl<T: Config> Pallet<T> {
let mut old = Voting::default();
sp_std::mem::swap(&mut old, voting);
match old {
Voting::Delegating {
balance,
target,
conviction,
delegations,
mut prior,
} => {
Voting::Delegating { balance, target, conviction, delegations, mut prior } => {
// remove any delegation votes to our current target.
let votes = Self::reduce_upstream_delegation(&target, conviction.votes(balance));
let votes =
Self::reduce_upstream_delegation(&target, conviction.votes(balance));
let now = frame_system::Pallet::<T>::block_number();
let lock_periods = conviction.lock_periods().into();
prior.accumulate(now + T::EnactmentPeriod::get() * lock_periods, balance);
voting.set_common(delegations, prior);
Ok(votes)
}
Voting::Direct { .. } => {
Err(Error::<T>::NotDelegating.into())
}
},
Voting::Direct { .. } => Err(Error::<T>::NotDelegating.into()),
}
})?;
Self::deposit_event(Event::<T>::Undelegated(who));
@@ -1583,7 +1594,8 @@ impl<T: Config> Pallet<T> {
) -> ReferendumIndex {
let ref_index = Self::referendum_count();
ReferendumCount::<T>::put(ref_index + 1);
let status = ReferendumStatus { end, proposal_hash, threshold, delay, tally: Default::default() };
let status =
ReferendumStatus { end, proposal_hash, threshold, delay, tally: Default::default() };
let item = ReferendumInfo::Ongoing(status);
<ReferendumInfoOf<T>>::insert(ref_index, item);
Self::deposit_event(Event::<T>::Started(ref_index, threshold));
@@ -1596,7 +1608,8 @@ impl<T: Config> Pallet<T> {
Self::launch_public(now).or_else(|_| Self::launch_external(now))
} else {
Self::launch_external(now).or_else(|_| Self::launch_public(now))
}.map_err(|_| Error::<T>::NoneWaiting.into())
}
.map_err(|_| Error::<T>::NoneWaiting.into())
}
/// Table the waiting external proposal for a vote, if there is one.
@@ -1654,8 +1667,10 @@ impl<T: Config> Pallet<T> {
debug_assert!(err_amount.is_zero());
Self::deposit_event(Event::<T>::PreimageUsed(proposal_hash, provider, deposit));
let res = proposal.dispatch(frame_system::RawOrigin::Root.into())
.map(|_| ()).map_err(|e| e.error);
let res = proposal
.dispatch(frame_system::RawOrigin::Root.into())
.map(|_| ())
.map_err(|e| e.error);
Self::deposit_event(Event::<T>::Executed(index, res));
Ok(())
@@ -1685,10 +1700,14 @@ impl<T: Config> Pallet<T> {
} else {
let when = now + status.delay;
// Note that we need the preimage now.
Preimages::<T>::mutate_exists(&status.proposal_hash, |maybe_pre| match *maybe_pre {
Some(PreimageStatus::Available { ref mut expiry, .. }) => *expiry = Some(when),
ref mut a => *a = Some(PreimageStatus::Missing(when)),
});
Preimages::<T>::mutate_exists(
&status.proposal_hash,
|maybe_pre| match *maybe_pre {
Some(PreimageStatus::Available { ref mut expiry, .. }) =>
*expiry = Some(when),
ref mut a => *a = Some(PreimageStatus::Missing(when)),
},
);
if T::Scheduler::schedule_named(
(DEMOCRACY_ID, index).encode(),
@@ -1697,7 +1716,9 @@ impl<T: Config> Pallet<T> {
63,
frame_system::RawOrigin::Root.into(),
Call::enact_proposal(status.proposal_hash, index).into(),
).is_err() {
)
.is_err()
{
frame_support::print("LOGIC ERROR: bake_referendum/schedule_named failed");
}
}
@@ -1762,7 +1783,8 @@ impl<T: Config> Pallet<T> {
// To decode the enum variant we only need the first byte.
let mut buf = [0u8; 1];
let key = <Preimages<T>>::hashed_key_for(proposal_hash);
let bytes = sp_io::storage::read(&key, &mut buf, 0).ok_or_else(|| Error::<T>::NotImminent)?;
let bytes =
sp_io::storage::read(&key, &mut buf, 0).ok_or_else(|| Error::<T>::NotImminent)?;
// The value may be smaller that 1 byte.
let mut input = &buf[0..buf.len().min(bytes as usize)];
@@ -1772,7 +1794,7 @@ impl<T: Config> Pallet<T> {
_ => {
sp_runtime::print("Failed to decode `PreimageStatus` variant");
Err(Error::<T>::NotImminent.into())
}
},
}
}
@@ -1790,7 +1812,8 @@ impl<T: Config> Pallet<T> {
// * at most 5 bytes to decode a `Compact<u32>`
let mut buf = [0u8; 6];
let key = <Preimages<T>>::hashed_key_for(proposal_hash);
let bytes = sp_io::storage::read(&key, &mut buf, 0).ok_or_else(|| Error::<T>::PreimageMissing)?;
let bytes =
sp_io::storage::read(&key, &mut buf, 0).ok_or_else(|| Error::<T>::PreimageMissing)?;
// The value may be smaller that 6 bytes.
let mut input = &buf[0..buf.len().min(bytes as usize)];
@@ -1799,15 +1822,17 @@ impl<T: Config> Pallet<T> {
Ok(0) => return Err(Error::<T>::PreimageMissing.into()),
_ => {
sp_runtime::print("Failed to decode `PreimageStatus` variant");
return Err(Error::<T>::PreimageMissing.into());
}
return Err(Error::<T>::PreimageMissing.into())
},
}
// Decode the length of the vector.
let len = codec::Compact::<u32>::decode(&mut input).map_err(|_| {
sp_runtime::print("Failed to decode `PreimageStatus` variant");
DispatchError::from(Error::<T>::PreimageMissing)
})?.0;
let len = codec::Compact::<u32>::decode(&mut input)
.map_err(|_| {
sp_runtime::print("Failed to decode `PreimageStatus` variant");
DispatchError::from(Error::<T>::PreimageMissing)
})?
.0;
Ok(len)
}
@@ -1837,7 +1862,10 @@ impl<T: Config> Pallet<T> {
}
// See `note_imminent_preimage`
fn note_imminent_preimage_inner(who: T::AccountId, encoded_proposal: Vec<u8>) -> DispatchResult {
fn note_imminent_preimage_inner(
who: T::AccountId,
encoded_proposal: Vec<u8>,
) -> DispatchResult {
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);
Self::check_pre_image_is_missing(proposal_hash)?;
let status = Preimages::<T>::get(&proposal_hash).ok_or(Error::<T>::NotImminent)?;
@@ -1873,6 +1901,6 @@ fn decode_compact_u32_at(key: &[u8]) -> Option<u32> {
sp_runtime::print("Failed to decode compact u32 at:");
sp_runtime::print(key);
None
}
},
}
}