From f4340473074616278c8ef5f45ed96709d67d9232 Mon Sep 17 00:00:00 2001 From: Shaun Wang Date: Sun, 9 May 2021 13:56:37 +1200 Subject: [PATCH 1/3] Update pallet macro migrations. --- frame/babe/src/lib.rs | 10 +++++----- frame/im-online/src/lib.rs | 6 +++--- frame/im-online/src/tests.rs | 2 +- frame/nicks/src/lib.rs | 16 ++++++++-------- frame/timestamp/src/lib.rs | 4 ++-- frame/utility/src/lib.rs | 6 +++--- frame/vesting/src/lib.rs | 7 +++++-- 7 files changed, 27 insertions(+), 24 deletions(-) diff --git a/frame/babe/src/lib.rs b/frame/babe/src/lib.rs index fb1e32e5350b5..ef028a42f30ae 100644 --- a/frame/babe/src/lib.rs +++ b/frame/babe/src/lib.rs @@ -354,7 +354,7 @@ pub mod pallet { #[pallet::weight(::WeightInfo::report_equivocation( key_owner_proof.validator_count(), ))] - pub fn report_equivocation( + pub(crate) fn report_equivocation( origin: OriginFor, equivocation_proof: EquivocationProof, key_owner_proof: T::KeyOwnerProof, @@ -379,7 +379,7 @@ pub mod pallet { #[pallet::weight(::WeightInfo::report_equivocation( key_owner_proof.validator_count(), ))] - pub fn report_equivocation_unsigned( + pub(crate) fn report_equivocation_unsigned( origin: OriginFor, equivocation_proof: EquivocationProof, key_owner_proof: T::KeyOwnerProof, @@ -398,13 +398,13 @@ pub mod pallet { /// Multiple calls to this method will replace any existing planned config change that had /// not been enacted yet. #[pallet::weight(::WeightInfo::plan_config_change())] - pub fn plan_config_change( + pub(crate) fn plan_config_change( origin: OriginFor, config: NextConfigDescriptor, - ) -> DispatchResultWithPostInfo { + ) -> DispatchResult { ensure_root(origin)?; PendingEpochConfigChange::::put(config); - Ok(().into()) + Ok(()) } } } diff --git a/frame/im-online/src/lib.rs b/frame/im-online/src/lib.rs index 0290c564ec599..9a59cff6024c1 100644 --- a/frame/im-online/src/lib.rs +++ b/frame/im-online/src/lib.rs @@ -391,13 +391,13 @@ pub mod pallet { heartbeat.validators_len as u32, heartbeat.network_state.external_addresses.len() as u32, ))] - pub fn heartbeat( + pub(crate) fn heartbeat( origin: OriginFor, heartbeat: Heartbeat, // since signature verification is done in `validate_unsigned` // we can skip doing it here again. _signature: ::Signature, - ) -> DispatchResultWithPostInfo { + ) -> DispatchResult { ensure_none(origin)?; let current_session = T::ValidatorSet::session_index(); @@ -417,7 +417,7 @@ pub mod pallet { &network_state ); - Ok(().into()) + Ok(()) } else if exists { Err(Error::::DuplicatedHeartbeat)? } else { diff --git a/frame/im-online/src/tests.rs b/frame/im-online/src/tests.rs index 5ce931875b9a6..f100bd71c34f6 100644 --- a/frame/im-online/src/tests.rs +++ b/frame/im-online/src/tests.rs @@ -114,7 +114,7 @@ fn heartbeat( authority_index: u32, id: UintAuthorityId, validators: Vec, -) -> dispatch::DispatchResultWithPostInfo { +) -> dispatch::DispatchResult { use frame_support::unsigned::ValidateUnsigned; let heartbeat = Heartbeat { diff --git a/frame/nicks/src/lib.rs b/frame/nicks/src/lib.rs index a6d2415ab96ef..45a0dc477b1d9 100644 --- a/frame/nicks/src/lib.rs +++ b/frame/nicks/src/lib.rs @@ -141,7 +141,7 @@ pub mod pallet { /// - One event. /// # #[pallet::weight(50_000_000)] - pub(super) fn set_name(origin: OriginFor, name: Vec) -> DispatchResultWithPostInfo { + pub(super) fn set_name(origin: OriginFor, name: Vec) -> DispatchResult { let sender = ensure_signed(origin)?; ensure!(name.len() >= T::MinLength::get() as usize, Error::::TooShort); @@ -158,7 +158,7 @@ pub mod pallet { }; >::insert(&sender, (name, deposit)); - Ok(().into()) + Ok(()) } /// Clear an account's name and return the deposit. Fails if the account was not named. @@ -172,7 +172,7 @@ pub mod pallet { /// - One event. /// # #[pallet::weight(70_000_000)] - pub(super) fn clear_name(origin: OriginFor) -> DispatchResultWithPostInfo { + pub(super) fn clear_name(origin: OriginFor) -> DispatchResult { let sender = ensure_signed(origin)?; let deposit = >::take(&sender).ok_or(Error::::Unnamed)?.1; @@ -181,7 +181,7 @@ pub mod pallet { debug_assert!(err_amount.is_zero()); Self::deposit_event(Event::::NameCleared(sender, deposit)); - Ok(().into()) + Ok(()) } /// Remove an account's name and take charge of the deposit. @@ -201,7 +201,7 @@ pub mod pallet { pub(super) fn kill_name( origin: OriginFor, target: ::Source - ) -> DispatchResultWithPostInfo { + ) -> DispatchResult { T::ForceOrigin::ensure_origin(origin)?; // Figure out who we're meant to be clearing. @@ -212,7 +212,7 @@ pub mod pallet { T::Slashed::on_unbalanced(T::Currency::slash_reserved(&target, deposit.clone()).0); Self::deposit_event(Event::::NameKilled(target, deposit)); - Ok(().into()) + Ok(()) } /// Set a third-party account's name with no deposit. @@ -232,7 +232,7 @@ pub mod pallet { origin: OriginFor, target: ::Source, name: Vec - ) -> DispatchResultWithPostInfo { + ) -> DispatchResult { T::ForceOrigin::ensure_origin(origin)?; let target = T::Lookup::lookup(target)?; @@ -240,7 +240,7 @@ pub mod pallet { >::insert(&target, (name, deposit)); Self::deposit_event(Event::::NameForced(target)); - Ok(().into()) + Ok(()) } } } diff --git a/frame/timestamp/src/lib.rs b/frame/timestamp/src/lib.rs index 7c553b1e4b82f..dde635c6a8a30 100644 --- a/frame/timestamp/src/lib.rs +++ b/frame/timestamp/src/lib.rs @@ -183,7 +183,7 @@ pub mod pallet { T::WeightInfo::set(), DispatchClass::Mandatory ))] - pub(super) fn set(origin: OriginFor, #[pallet::compact] now: T::Moment) -> DispatchResultWithPostInfo { + pub(super) fn set(origin: OriginFor, #[pallet::compact] now: T::Moment) -> DispatchResult { ensure_none(origin)?; assert!(!DidUpdate::::exists(), "Timestamp must be updated only once in the block"); let prev = Self::now(); @@ -196,7 +196,7 @@ pub mod pallet { >::on_timestamp_set(now); - Ok(().into()) + Ok(()) } } diff --git a/frame/utility/src/lib.rs b/frame/utility/src/lib.rs index 983d24c74dbee..a0269b59165b2 100644 --- a/frame/utility/src/lib.rs +++ b/frame/utility/src/lib.rs @@ -148,7 +148,7 @@ pub mod pallet { }; (dispatch_weight, dispatch_class) })] - pub fn batch( + pub(crate) fn batch( origin: OriginFor, calls: Vec<::Call>, ) -> DispatchResultWithPostInfo { @@ -202,7 +202,7 @@ pub mod pallet { dispatch_info.class, ) })] - pub fn as_derivative( + pub(crate) fn as_derivative( origin: OriginFor, index: u16, call: Box<::Call>, @@ -255,7 +255,7 @@ pub mod pallet { (dispatch_weight, dispatch_class) })] #[transactional] - pub fn batch_all( + pub(crate) fn batch_all( origin: OriginFor, calls: Vec<::Call>, ) -> DispatchResultWithPostInfo { diff --git a/frame/vesting/src/lib.rs b/frame/vesting/src/lib.rs index e5e6cb5069b82..8fcb90a8c1405 100644 --- a/frame/vesting/src/lib.rs +++ b/frame/vesting/src/lib.rs @@ -224,7 +224,7 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::vest_locked(MaxLocksOf::::get()) .max(T::WeightInfo::vest_unlocked(MaxLocksOf::::get())) )] - pub fn vest(origin: OriginFor) -> DispatchResult { + pub(crate) fn vest(origin: OriginFor) -> DispatchResult { let who = ensure_signed(origin)?; Self::update_lock(who) } @@ -247,7 +247,10 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::vest_other_locked(MaxLocksOf::::get()) .max(T::WeightInfo::vest_other_unlocked(MaxLocksOf::::get())) )] - pub fn vest_other(origin: OriginFor, target: ::Source) -> DispatchResult { + pub(crate) fn vest_other( + origin: OriginFor, + target: ::Source, + ) -> DispatchResult { ensure_signed(origin)?; Self::update_lock(T::Lookup::lookup(target)?) } From a6721bcbf92f74f8d664d733e134f1cfabc76647 Mon Sep 17 00:00:00 2001 From: Shaun Wang Date: Mon, 10 May 2021 22:31:51 +1200 Subject: [PATCH 2/3] Revert dispatchable call visibility changes. --- frame/babe/src/lib.rs | 6 +++--- frame/im-online/src/lib.rs | 2 +- frame/utility/src/lib.rs | 6 +++--- frame/vesting/src/lib.rs | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/frame/babe/src/lib.rs b/frame/babe/src/lib.rs index ef028a42f30ae..6eecf2675291c 100644 --- a/frame/babe/src/lib.rs +++ b/frame/babe/src/lib.rs @@ -354,7 +354,7 @@ pub mod pallet { #[pallet::weight(::WeightInfo::report_equivocation( key_owner_proof.validator_count(), ))] - pub(crate) fn report_equivocation( + pub fn report_equivocation( origin: OriginFor, equivocation_proof: EquivocationProof, key_owner_proof: T::KeyOwnerProof, @@ -379,7 +379,7 @@ pub mod pallet { #[pallet::weight(::WeightInfo::report_equivocation( key_owner_proof.validator_count(), ))] - pub(crate) fn report_equivocation_unsigned( + pub fn report_equivocation_unsigned( origin: OriginFor, equivocation_proof: EquivocationProof, key_owner_proof: T::KeyOwnerProof, @@ -398,7 +398,7 @@ pub mod pallet { /// Multiple calls to this method will replace any existing planned config change that had /// not been enacted yet. #[pallet::weight(::WeightInfo::plan_config_change())] - pub(crate) fn plan_config_change( + pub fn plan_config_change( origin: OriginFor, config: NextConfigDescriptor, ) -> DispatchResult { diff --git a/frame/im-online/src/lib.rs b/frame/im-online/src/lib.rs index 9a59cff6024c1..bddb286fad739 100644 --- a/frame/im-online/src/lib.rs +++ b/frame/im-online/src/lib.rs @@ -391,7 +391,7 @@ pub mod pallet { heartbeat.validators_len as u32, heartbeat.network_state.external_addresses.len() as u32, ))] - pub(crate) fn heartbeat( + pub fn heartbeat( origin: OriginFor, heartbeat: Heartbeat, // since signature verification is done in `validate_unsigned` diff --git a/frame/utility/src/lib.rs b/frame/utility/src/lib.rs index a0269b59165b2..983d24c74dbee 100644 --- a/frame/utility/src/lib.rs +++ b/frame/utility/src/lib.rs @@ -148,7 +148,7 @@ pub mod pallet { }; (dispatch_weight, dispatch_class) })] - pub(crate) fn batch( + pub fn batch( origin: OriginFor, calls: Vec<::Call>, ) -> DispatchResultWithPostInfo { @@ -202,7 +202,7 @@ pub mod pallet { dispatch_info.class, ) })] - pub(crate) fn as_derivative( + pub fn as_derivative( origin: OriginFor, index: u16, call: Box<::Call>, @@ -255,7 +255,7 @@ pub mod pallet { (dispatch_weight, dispatch_class) })] #[transactional] - pub(crate) fn batch_all( + pub fn batch_all( origin: OriginFor, calls: Vec<::Call>, ) -> DispatchResultWithPostInfo { diff --git a/frame/vesting/src/lib.rs b/frame/vesting/src/lib.rs index 8fcb90a8c1405..47c50deaf093c 100644 --- a/frame/vesting/src/lib.rs +++ b/frame/vesting/src/lib.rs @@ -224,7 +224,7 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::vest_locked(MaxLocksOf::::get()) .max(T::WeightInfo::vest_unlocked(MaxLocksOf::::get())) )] - pub(crate) fn vest(origin: OriginFor) -> DispatchResult { + pub fn vest(origin: OriginFor) -> DispatchResult { let who = ensure_signed(origin)?; Self::update_lock(who) } @@ -247,7 +247,7 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::vest_other_locked(MaxLocksOf::::get()) .max(T::WeightInfo::vest_other_unlocked(MaxLocksOf::::get())) )] - pub(crate) fn vest_other( + pub fn vest_other( origin: OriginFor, target: ::Source, ) -> DispatchResult { From 27d93e6fe8f48c5026b4f6d67c48850d21b081b9 Mon Sep 17 00:00:00 2001 From: Shaun Wang Date: Mon, 10 May 2021 22:33:11 +1200 Subject: [PATCH 3/3] fmt --- frame/vesting/src/lib.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/frame/vesting/src/lib.rs b/frame/vesting/src/lib.rs index 47c50deaf093c..e5e6cb5069b82 100644 --- a/frame/vesting/src/lib.rs +++ b/frame/vesting/src/lib.rs @@ -247,10 +247,7 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::vest_other_locked(MaxLocksOf::::get()) .max(T::WeightInfo::vest_other_unlocked(MaxLocksOf::::get())) )] - pub fn vest_other( - origin: OriginFor, - target: ::Source, - ) -> DispatchResult { + pub fn vest_other(origin: OriginFor, target: ::Source) -> DispatchResult { ensure_signed(origin)?; Self::update_lock(T::Lookup::lookup(target)?) }