mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-21 01:41:03 +00:00
Migrate away from SimpleDispatchInfo (#5686)
* Migrate away from SimpleDispatchInfo * Fix imports * Better doc * Update lib.rs Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
@@ -171,7 +171,7 @@ use sp_runtime::{
|
||||
use codec::{Ref, Encode, Decode};
|
||||
use frame_support::{
|
||||
decl_module, decl_storage, decl_event, decl_error, ensure, Parameter,
|
||||
weights::{SimpleDispatchInfo, Weight, MINIMUM_WEIGHT},
|
||||
weights::{Weight, MINIMUM_WEIGHT, DispatchClass},
|
||||
traits::{
|
||||
Currency, ReservableCurrency, LockableCurrency, WithdrawReason, LockIdentifier, Get,
|
||||
OnUnbalanced, BalanceStatus, schedule::Named as ScheduleNamed, EnsureOrigin
|
||||
@@ -546,7 +546,7 @@ decl_module! {
|
||||
/// - P is the number proposals in the `PublicProps` vec.
|
||||
/// - Two DB changes, one DB entry.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(5_000_000_000)]
|
||||
#[weight = 5_000_000_000]
|
||||
fn propose(origin,
|
||||
proposal_hash: T::Hash,
|
||||
#[compact] value: BalanceOf<T>
|
||||
@@ -577,7 +577,7 @@ decl_module! {
|
||||
/// - S is the number of seconds a proposal already has.
|
||||
/// - One DB entry.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(5_000_000_000)]
|
||||
#[weight = 5_000_000_000]
|
||||
fn second(origin, #[compact] proposal: PropIndex) {
|
||||
let who = ensure_signed(origin)?;
|
||||
let mut deposit = Self::deposit_of(proposal)
|
||||
@@ -600,7 +600,7 @@ decl_module! {
|
||||
/// - R is the number of referendums the voter has voted on.
|
||||
/// - One DB change, one DB entry.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(200_000_000)]
|
||||
#[weight = 200_000_000]
|
||||
fn vote(origin,
|
||||
#[compact] ref_index: ReferendumIndex,
|
||||
vote: AccountVote<BalanceOf<T>>,
|
||||
@@ -621,7 +621,7 @@ decl_module! {
|
||||
/// - `O(1)`.
|
||||
/// - One DB change, one DB entry.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(200_000_000)]
|
||||
#[weight = 200_000_000]
|
||||
fn proxy_vote(origin,
|
||||
#[compact] ref_index: ReferendumIndex,
|
||||
vote: AccountVote<BalanceOf<T>>,
|
||||
@@ -641,7 +641,7 @@ decl_module! {
|
||||
/// # <weight>
|
||||
/// - `O(1)`.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedOperational(500_000_000)]
|
||||
#[weight = (500_000_000, DispatchClass::Operational)]
|
||||
fn emergency_cancel(origin, ref_index: ReferendumIndex) {
|
||||
T::CancellationOrigin::ensure_origin(origin)?;
|
||||
|
||||
@@ -664,7 +664,7 @@ decl_module! {
|
||||
/// - `O(1)`.
|
||||
/// - One DB change.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(5_000_000_000)]
|
||||
#[weight = 5_000_000_000]
|
||||
fn external_propose(origin, proposal_hash: T::Hash) {
|
||||
T::ExternalOrigin::ensure_origin(origin)?;
|
||||
ensure!(!<NextExternal<T>>::exists(), Error::<T>::DuplicateProposal);
|
||||
@@ -691,7 +691,7 @@ decl_module! {
|
||||
/// - `O(1)`.
|
||||
/// - One DB change.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(5_000_000_000)]
|
||||
#[weight = 5_000_000_000]
|
||||
fn external_propose_majority(origin, proposal_hash: T::Hash) {
|
||||
T::ExternalMajorityOrigin::ensure_origin(origin)?;
|
||||
<NextExternal<T>>::put((proposal_hash, VoteThreshold::SimpleMajority));
|
||||
@@ -711,7 +711,7 @@ decl_module! {
|
||||
/// - `O(1)`.
|
||||
/// - One DB change.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(5_000_000_000)]
|
||||
#[weight = 5_000_000_000]
|
||||
fn external_propose_default(origin, proposal_hash: T::Hash) {
|
||||
T::ExternalDefaultOrigin::ensure_origin(origin)?;
|
||||
<NextExternal<T>>::put((proposal_hash, VoteThreshold::SuperMajorityAgainst));
|
||||
@@ -736,7 +736,7 @@ decl_module! {
|
||||
/// - One DB change.
|
||||
/// - One extra DB entry.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(200_000_000)]
|
||||
#[weight = 200_000_000]
|
||||
fn fast_track(origin,
|
||||
proposal_hash: T::Hash,
|
||||
voting_period: T::BlockNumber,
|
||||
@@ -787,7 +787,7 @@ decl_module! {
|
||||
/// be very large.
|
||||
/// - O(log v), v is number of `existing_vetoers`
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(200_000_000)]
|
||||
#[weight = 200_000_000]
|
||||
fn veto_external(origin, proposal_hash: T::Hash) {
|
||||
let who = T::VetoOrigin::ensure_origin(origin)?;
|
||||
|
||||
@@ -820,7 +820,7 @@ decl_module! {
|
||||
/// # <weight>
|
||||
/// - `O(1)`.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedOperational(MINIMUM_WEIGHT)]
|
||||
#[weight = (MINIMUM_WEIGHT, DispatchClass::Operational)]
|
||||
fn cancel_referendum(origin, #[compact] ref_index: ReferendumIndex) {
|
||||
ensure_root(origin)?;
|
||||
Self::internal_cancel_referendum(ref_index);
|
||||
@@ -836,7 +836,7 @@ decl_module! {
|
||||
/// - One DB change.
|
||||
/// - O(d) where d is the items in the dispatch queue.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedOperational(MINIMUM_WEIGHT)]
|
||||
#[weight = (MINIMUM_WEIGHT, DispatchClass::Operational)]
|
||||
fn cancel_queued(origin, which: ReferendumIndex) {
|
||||
ensure_root(origin)?;
|
||||
T::Scheduler::cancel_named((DEMOCRACY_ID, which))
|
||||
@@ -862,7 +862,7 @@ decl_module! {
|
||||
/// # <weight>
|
||||
/// - One extra DB entry.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(100_000_000)]
|
||||
#[weight = 100_000_000]
|
||||
fn activate_proxy(origin, proxy: T::AccountId) {
|
||||
let who = ensure_signed(origin)?;
|
||||
Proxy::<T>::try_mutate(&proxy, |a| match a.take() {
|
||||
@@ -885,7 +885,7 @@ decl_module! {
|
||||
/// # <weight>
|
||||
/// - One DB clear.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(100_000_000)]
|
||||
#[weight = 100_000_000]
|
||||
fn close_proxy(origin) {
|
||||
let who = ensure_signed(origin)?;
|
||||
Proxy::<T>::mutate(&who, |a| {
|
||||
@@ -909,7 +909,7 @@ decl_module! {
|
||||
/// # <weight>
|
||||
/// - One DB clear.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(100_000_000)]
|
||||
#[weight = 100_000_000]
|
||||
fn deactivate_proxy(origin, proxy: T::AccountId) {
|
||||
let who = ensure_signed(origin)?;
|
||||
Proxy::<T>::try_mutate(&proxy, |a| match a.take() {
|
||||
@@ -942,7 +942,7 @@ decl_module! {
|
||||
///
|
||||
/// # <weight>
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(500_000_000)]
|
||||
#[weight = 500_000_000]
|
||||
pub fn delegate(origin, to: T::AccountId, conviction: Conviction, balance: BalanceOf<T>) {
|
||||
let who = ensure_signed(origin)?;
|
||||
Self::try_delegate(who, to, conviction, balance)?;
|
||||
@@ -961,7 +961,7 @@ decl_module! {
|
||||
/// # <weight>
|
||||
/// - O(1).
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(500_000_000)]
|
||||
#[weight = 500_000_000]
|
||||
fn undelegate(origin) {
|
||||
let who = ensure_signed(origin)?;
|
||||
Self::try_undelegate(who)?;
|
||||
@@ -975,7 +975,7 @@ decl_module! {
|
||||
/// - `O(1)`.
|
||||
/// - One DB clear.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
|
||||
#[weight = MINIMUM_WEIGHT]
|
||||
fn clear_public_proposals(origin) {
|
||||
ensure_root(origin)?;
|
||||
|
||||
@@ -995,7 +995,7 @@ decl_module! {
|
||||
/// - Dependent on the size of `encoded_proposal` but protected by a
|
||||
/// required deposit.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(100_000_000)]
|
||||
#[weight = 100_000_000]
|
||||
fn note_preimage(origin, encoded_proposal: Vec<u8>) {
|
||||
let who = ensure_signed(origin)?;
|
||||
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);
|
||||
@@ -1030,7 +1030,7 @@ decl_module! {
|
||||
/// # <weight>
|
||||
/// - Dependent on the size of `encoded_proposal` and length of dispatch queue.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(100_000_000)]
|
||||
#[weight = 100_000_000]
|
||||
fn note_imminent_preimage(origin, encoded_proposal: Vec<u8>) {
|
||||
let who = ensure_signed(origin)?;
|
||||
let proposal_hash = T::Hashing::hash(&encoded_proposal[..]);
|
||||
@@ -1066,7 +1066,7 @@ decl_module! {
|
||||
/// # <weight>
|
||||
/// - One DB clear.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
|
||||
#[weight = MINIMUM_WEIGHT]
|
||||
fn reap_preimage(origin, proposal_hash: T::Hash) {
|
||||
let who = ensure_signed(origin)?;
|
||||
let (provider, deposit, since, expiry) = <Preimages<T>>::get(&proposal_hash)
|
||||
@@ -1096,7 +1096,7 @@ decl_module! {
|
||||
/// # <weight>
|
||||
/// - `O(1)`.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
|
||||
#[weight = MINIMUM_WEIGHT]
|
||||
fn unlock(origin, target: T::AccountId) {
|
||||
ensure_signed(origin)?;
|
||||
Self::update_lock(&target);
|
||||
@@ -1115,7 +1115,7 @@ decl_module! {
|
||||
/// # <weight>
|
||||
/// - One extra DB entry.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(100_000_000)]
|
||||
#[weight = 100_000_000]
|
||||
fn open_proxy(origin, target: T::AccountId) {
|
||||
let who = ensure_signed(origin)?;
|
||||
Proxy::<T>::mutate(&who, |a| {
|
||||
@@ -1154,7 +1154,7 @@ decl_module! {
|
||||
/// # <weight>
|
||||
/// - `O(R + log R)` where R is the number of referenda that `target` has voted on.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
|
||||
#[weight = MINIMUM_WEIGHT]
|
||||
fn remove_vote(origin, index: ReferendumIndex) -> DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
Self::try_remove_vote(&who, index, UnvoteScope::Any)
|
||||
@@ -1176,7 +1176,7 @@ decl_module! {
|
||||
/// # <weight>
|
||||
/// - `O(R + log R)` where R is the number of referenda that `target` has voted on.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
|
||||
#[weight = MINIMUM_WEIGHT]
|
||||
fn remove_other_vote(origin, target: T::AccountId, index: ReferendumIndex) -> DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
let scope = if target == who { UnvoteScope::Any } else { UnvoteScope::OnlyExpired };
|
||||
@@ -1207,7 +1207,7 @@ decl_module! {
|
||||
///
|
||||
/// # <weight>
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(500_000_000)]
|
||||
#[weight = 500_000_000]
|
||||
pub fn proxy_delegate(origin,
|
||||
to: T::AccountId,
|
||||
conviction: Conviction,
|
||||
@@ -1231,7 +1231,7 @@ decl_module! {
|
||||
/// # <weight>
|
||||
/// - O(1).
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(500_000_000)]
|
||||
#[weight = 500_000_000]
|
||||
fn proxy_undelegate(origin) {
|
||||
let who = ensure_signed(origin)?;
|
||||
let target = Self::proxy(who).and_then(|a| a.as_active()).ok_or(Error::<T>::NotProxy)?;
|
||||
@@ -1251,7 +1251,7 @@ decl_module! {
|
||||
/// # <weight>
|
||||
/// - `O(R + log R)` where R is the number of referenda that `target` has voted on.
|
||||
/// # </weight>
|
||||
#[weight = SimpleDispatchInfo::FixedNormal(MINIMUM_WEIGHT)]
|
||||
#[weight = MINIMUM_WEIGHT]
|
||||
fn proxy_remove_vote(origin, index: ReferendumIndex) -> DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
let target = Self::proxy(who).and_then(|a| a.as_active()).ok_or(Error::<T>::NotProxy)?;
|
||||
@@ -1259,7 +1259,7 @@ decl_module! {
|
||||
}
|
||||
|
||||
/// Enact a proposal from a referendum. For now we just make the weight be the maximum.
|
||||
#[weight = SimpleDispatchInfo::MaxNormal]
|
||||
#[weight = Weight::max_value()]
|
||||
fn enact_proposal(origin, proposal_hash: T::Hash, index: ReferendumIndex) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
Self::do_enact_proposal(proposal_hash, index)
|
||||
|
||||
Reference in New Issue
Block a user