Skip to content

Commit dc112d9

Browse files
committed
refactor
1 parent 9916a84 commit dc112d9

File tree

2 files changed

+65
-60
lines changed

2 files changed

+65
-60
lines changed

polkadot/runtime/rococo/src/lib.rs

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ use governance::{
125125
TreasurySpender,
126126
};
127127
use xcm_executor::traits::WeightBounds;
128-
use xcm_payment_runtime_api::Error as XcmPaymentError;
128+
use xcm_payment_runtime_api::Error as XcmPaymentApiError;
129129

130130
#[cfg(test)]
131131
mod tests;
@@ -219,7 +219,7 @@ pub struct OriginPrivilegeCmp;
219219
impl PrivilegeCmp<OriginCaller> for OriginPrivilegeCmp {
220220
fn cmp_privilege(left: &OriginCaller, right: &OriginCaller) -> Option<Ordering> {
221221
if left == right {
222-
return Some(Ordering::Equal)
222+
return Some(Ordering::Equal);
223223
}
224224

225225
match (left, right) {
@@ -379,10 +379,12 @@ impl OpaqueKeys for OldSessionKeys {
379379
<<Babe as BoundToRuntimeAppPublic>::Public>::ID => self.babe.as_ref(),
380380
sp_core::crypto::key_types::IM_ONLINE => self.im_online.as_ref(),
381381
<<Initializer as BoundToRuntimeAppPublic>::Public>::ID => self.para_validator.as_ref(),
382-
<<ParaSessionInfo as BoundToRuntimeAppPublic>::Public>::ID =>
383-
self.para_assignment.as_ref(),
384-
<<AuthorityDiscovery as BoundToRuntimeAppPublic>::Public>::ID =>
385-
self.authority_discovery.as_ref(),
382+
<<ParaSessionInfo as BoundToRuntimeAppPublic>::Public>::ID => {
383+
self.para_assignment.as_ref()
384+
},
385+
<<AuthorityDiscovery as BoundToRuntimeAppPublic>::Public>::ID => {
386+
self.authority_discovery.as_ref()
387+
},
386388
<<Beefy as BoundToRuntimeAppPublic>::Public>::ID => self.beefy.as_ref(),
387389
_ => &[],
388390
}
@@ -860,19 +862,19 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
860862
),
861863
ProxyType::IdentityJudgement => matches!(
862864
c,
863-
RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) |
864-
RuntimeCall::Utility(..)
865+
RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. })
866+
| RuntimeCall::Utility(..)
865867
),
866868
ProxyType::CancelProxy => {
867869
matches!(c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }))
868870
},
869871
ProxyType::Auction => matches!(
870872
c,
871-
RuntimeCall::Auctions { .. } |
872-
RuntimeCall::Crowdloan { .. } |
873-
RuntimeCall::Registrar { .. } |
874-
RuntimeCall::Multisig(..) |
875-
RuntimeCall::Slots { .. }
873+
RuntimeCall::Auctions { .. }
874+
| RuntimeCall::Crowdloan { .. }
875+
| RuntimeCall::Registrar { .. }
876+
| RuntimeCall::Multisig(..)
877+
| RuntimeCall::Slots { .. }
876878
),
877879
ProxyType::Society => matches!(c, RuntimeCall::Society(..)),
878880
ProxyType::OnDemandOrdering => matches!(c, RuntimeCall::OnDemandAssignmentProvider(..)),
@@ -1491,11 +1493,11 @@ pub mod migrations {
14911493
let now = frame_system::Pallet::<Runtime>::block_number();
14921494
let lease = slots::Pallet::<Runtime>::lease(para);
14931495
if lease.is_empty() {
1494-
return None
1496+
return None;
14951497
}
14961498
// Lease not yet started, ignore:
14971499
if lease.iter().any(Option::is_none) {
1498-
return None
1500+
return None;
14991501
}
15001502
let (index, _) =
15011503
<slots::Pallet<Runtime> as Leaser<BlockNumber>>::lease_period_index(now)?;
@@ -1557,7 +1559,7 @@ pub mod migrations {
15571559
fn pre_upgrade() -> Result<sp_std::vec::Vec<u8>, sp_runtime::TryRuntimeError> {
15581560
if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC {
15591561
log::warn!(target: "runtime::session_keys", "Skipping session keys migration pre-upgrade check due to spec version (already applied?)");
1560-
return Ok(Vec::new())
1562+
return Ok(Vec::new());
15611563
}
15621564

15631565
log::info!(target: "runtime::session_keys", "Collecting pre-upgrade session keys state");
@@ -1586,7 +1588,7 @@ pub mod migrations {
15861588
fn on_runtime_upgrade() -> Weight {
15871589
if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC {
15881590
log::info!("Skipping session keys upgrade: already applied");
1589-
return <Runtime as frame_system::Config>::DbWeight::get().reads(1)
1591+
return <Runtime as frame_system::Config>::DbWeight::get().reads(1);
15901592
}
15911593
log::trace!("Upgrading session keys");
15921594
Session::upgrade_keys::<OldSessionKeys, _>(transform_session_keys);
@@ -1599,7 +1601,7 @@ pub mod migrations {
15991601
) -> Result<(), sp_runtime::TryRuntimeError> {
16001602
if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC {
16011603
log::warn!(target: "runtime::session_keys", "Skipping session keys migration post-upgrade check due to spec version (already applied?)");
1602-
return Ok(())
1604+
return Ok(());
16031605
}
16041606

16051607
let key_ids = SessionKeys::key_ids();
@@ -1780,33 +1782,33 @@ sp_api::impl_runtime_apis! {
17801782
}
17811783

17821784
impl xcm_payment_runtime_api::XcmPaymentApi<Block, RuntimeCall> for Runtime {
1783-
fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result<Vec<VersionedAssetId>, XcmPaymentError> {
1785+
fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result<Vec<VersionedAssetId>, XcmPaymentApiError> {
17841786
if !matches!(xcm_version, 3 | 4) {
1785-
return Err(XcmPaymentError::UnhandledXcmVersion);
1787+
return Err(XcmPaymentApiError::UnhandledXcmVersion);
17861788
}
17871789
Ok([VersionedAssetId::V4(xcm_config::TokenLocation::get().into())]
17881790
.into_iter()
17891791
.filter_map(|asset| asset.into_version(xcm_version).ok())
17901792
.collect())
17911793
}
17921794

1793-
fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, XcmPaymentError> {
1795+
fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, XcmPaymentApiError> {
17941796
let local_asset = VersionedAssetId::V4(xcm_config::TokenLocation::get().into());
17951797
let asset = asset
17961798
.into_version(4)
1797-
.map_err(|_| XcmPaymentError::VersionedConversionFailed)?;
1799+
.map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;
17981800

1799-
if asset != local_asset { return Err(XcmPaymentError::AssetNotFound); }
1801+
if asset != local_asset { return Err(XcmPaymentApiError::AssetNotFound); }
18001802

18011803
Ok(WeightToFee::weight_to_fee(&weight))
18021804
}
18031805

1804-
fn query_xcm_weight(message: VersionedXcm<RuntimeCall>) -> Result<Weight, XcmPaymentError> {
1806+
fn query_xcm_weight(message: VersionedXcm<RuntimeCall>) -> Result<Weight, XcmPaymentApiError> {
18051807
let mut message = message
18061808
.try_into()
1807-
.map_err(|_| XcmPaymentError::VersionedConversionFailed)?;
1809+
.map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;
18081810
<xcm_config::XcmConfig as xcm_executor::Config>::Weigher::weight(&mut message)
1809-
.map_err(|_| XcmPaymentError::WeightNotComputable)
1811+
.map_err(|_| XcmPaymentApiError::WeightNotComputable)
18101812
}
18111813
}
18121814

@@ -2493,7 +2495,7 @@ mod remote_tests {
24932495
#[tokio::test]
24942496
async fn run_migrations() {
24952497
if var("RUN_MIGRATION_TESTS").is_err() {
2496-
return
2498+
return;
24972499
}
24982500

24992501
sp_tracing::try_init_simple();

polkadot/runtime/westend/src/lib.rs

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ use xcm::{
108108
use xcm_builder::PayOverXcm;
109109

110110
use xcm_executor::traits::WeightBounds;
111-
use xcm_payment_runtime_api::Error as XcmPaymentError;
111+
use xcm_payment_runtime_api::Error as XcmPaymentApiError;
112112

113113
pub use frame_system::Call as SystemCall;
114114
pub use pallet_balances::Call as BalancesCall;
@@ -441,10 +441,12 @@ impl OpaqueKeys for OldSessionKeys {
441441
<<Babe as BoundToRuntimeAppPublic>::Public>::ID => self.babe.as_ref(),
442442
sp_core::crypto::key_types::IM_ONLINE => self.im_online.as_ref(),
443443
<<Initializer as BoundToRuntimeAppPublic>::Public>::ID => self.para_validator.as_ref(),
444-
<<ParaSessionInfo as BoundToRuntimeAppPublic>::Public>::ID =>
445-
self.para_assignment.as_ref(),
446-
<<AuthorityDiscovery as BoundToRuntimeAppPublic>::Public>::ID =>
447-
self.authority_discovery.as_ref(),
444+
<<ParaSessionInfo as BoundToRuntimeAppPublic>::Public>::ID => {
445+
self.para_assignment.as_ref()
446+
},
447+
<<AuthorityDiscovery as BoundToRuntimeAppPublic>::Public>::ID => {
448+
self.authority_discovery.as_ref()
449+
},
448450
<<Beefy as BoundToRuntimeAppPublic>::Public>::ID => self.beefy.as_ref(),
449451
_ => &[],
450452
}
@@ -1050,11 +1052,12 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
10501052
ProxyType::Staking => {
10511053
matches!(
10521054
c,
1053-
RuntimeCall::Staking(..) |
1054-
RuntimeCall::Session(..) | RuntimeCall::Utility(..) |
1055-
RuntimeCall::FastUnstake(..) |
1056-
RuntimeCall::VoterList(..) |
1057-
RuntimeCall::NominationPools(..)
1055+
RuntimeCall::Staking(..)
1056+
| RuntimeCall::Session(..)
1057+
| RuntimeCall::Utility(..)
1058+
| RuntimeCall::FastUnstake(..)
1059+
| RuntimeCall::VoterList(..)
1060+
| RuntimeCall::NominationPools(..)
10581061
)
10591062
},
10601063
ProxyType::NominationPools => {
@@ -1070,24 +1073,24 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
10701073
ProxyType::Governance => matches!(
10711074
c,
10721075
// OpenGov calls
1073-
RuntimeCall::ConvictionVoting(..) |
1074-
RuntimeCall::Referenda(..) |
1075-
RuntimeCall::Whitelist(..)
1076+
RuntimeCall::ConvictionVoting(..)
1077+
| RuntimeCall::Referenda(..)
1078+
| RuntimeCall::Whitelist(..)
10761079
),
10771080
ProxyType::IdentityJudgement => matches!(
10781081
c,
1079-
RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) |
1080-
RuntimeCall::Utility(..)
1082+
RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. })
1083+
| RuntimeCall::Utility(..)
10811084
),
10821085
ProxyType::CancelProxy => {
10831086
matches!(c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }))
10841087
},
10851088
ProxyType::Auction => matches!(
10861089
c,
1087-
RuntimeCall::Auctions(..) |
1088-
RuntimeCall::Crowdloan(..) |
1089-
RuntimeCall::Registrar(..) |
1090-
RuntimeCall::Slots(..)
1090+
RuntimeCall::Auctions(..)
1091+
| RuntimeCall::Crowdloan(..)
1092+
| RuntimeCall::Registrar(..)
1093+
| RuntimeCall::Slots(..)
10911094
),
10921095
}
10931096
}
@@ -1593,11 +1596,11 @@ pub mod migrations {
15931596
let now = frame_system::Pallet::<Runtime>::block_number();
15941597
let lease = slots::Pallet::<Runtime>::lease(para);
15951598
if lease.is_empty() {
1596-
return None
1599+
return None;
15971600
}
15981601
// Lease not yet started, ignore:
15991602
if lease.iter().any(Option::is_none) {
1600-
return None
1603+
return None;
16011604
}
16021605
let (index, _) =
16031606
<slots::Pallet<Runtime> as Leaser<BlockNumber>>::lease_period_index(now)?;
@@ -1619,7 +1622,7 @@ pub mod migrations {
16191622
fn pre_upgrade() -> Result<sp_std::vec::Vec<u8>, sp_runtime::TryRuntimeError> {
16201623
if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC {
16211624
log::warn!(target: "runtime::session_keys", "Skipping session keys migration pre-upgrade check due to spec version (already applied?)");
1622-
return Ok(Vec::new())
1625+
return Ok(Vec::new());
16231626
}
16241627

16251628
log::info!(target: "runtime::session_keys", "Collecting pre-upgrade session keys state");
@@ -1648,7 +1651,7 @@ pub mod migrations {
16481651
fn on_runtime_upgrade() -> Weight {
16491652
if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC {
16501653
log::warn!("Skipping session keys upgrade: already applied");
1651-
return <Runtime as frame_system::Config>::DbWeight::get().reads(1)
1654+
return <Runtime as frame_system::Config>::DbWeight::get().reads(1);
16521655
}
16531656
log::info!("Upgrading session keys");
16541657
Session::upgrade_keys::<OldSessionKeys, _>(transform_session_keys);
@@ -1661,7 +1664,7 @@ pub mod migrations {
16611664
) -> Result<(), sp_runtime::TryRuntimeError> {
16621665
if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC {
16631666
log::warn!(target: "runtime::session_keys", "Skipping session keys migration post-upgrade check due to spec version (already applied?)");
1664-
return Ok(())
1667+
return Ok(());
16651668
}
16661669

16671670
let key_ids = SessionKeys::key_ids();
@@ -2257,33 +2260,33 @@ sp_api::impl_runtime_apis! {
22572260
}
22582261

22592262
impl xcm_payment_runtime_api::XcmPaymentApi<Block, RuntimeCall> for Runtime {
2260-
fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result<Vec<VersionedAssetId>, XcmPaymentError> {
2263+
fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result<Vec<VersionedAssetId>, XcmPaymentApiError> {
22612264
if !matches!(xcm_version, 3 | 4) {
2262-
return Err(XcmPaymentError::UnhandledXcmVersion);
2265+
return Err(XcmPaymentApiError::UnhandledXcmVersion);
22632266
}
22642267
Ok([VersionedAssetId::V4(xcm_config::TokenLocation::get().into())]
22652268
.into_iter()
22662269
.filter_map(|asset| asset.into_version(xcm_version).ok())
22672270
.collect())
22682271
}
22692272

2270-
fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, XcmPaymentError> {
2273+
fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, XcmPaymentApiError> {
22712274
let local_asset = VersionedAssetId::V4(xcm_config::TokenLocation::get().into());
22722275
let asset = asset
22732276
.into_version(4)
2274-
.map_err(|_| XcmPaymentError::VersionedConversionFailed)?;
2277+
.map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;
22752278

2276-
if asset != local_asset { return Err(XcmPaymentError::AssetNotFound); }
2279+
if asset != local_asset { return Err(XcmPaymentApiError::AssetNotFound); }
22772280

22782281
Ok(WeightToFee::weight_to_fee(&weight))
22792282
}
22802283

2281-
fn query_xcm_weight(message: VersionedXcm<RuntimeCall>) -> Result<Weight, XcmPaymentError> {
2284+
fn query_xcm_weight(message: VersionedXcm<RuntimeCall>) -> Result<Weight, XcmPaymentApiError> {
22822285
let mut message = message
22832286
.try_into()
2284-
.map_err(|_| XcmPaymentError::VersionedConversionFailed)?;
2287+
.map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;
22852288
<xcm_config::XcmConfig as xcm_executor::Config>::Weigher::weight(&mut message)
2286-
.map_err(|_| XcmPaymentError::WeightNotComputable)
2289+
.map_err(|_| XcmPaymentApiError::WeightNotComputable)
22872290
}
22882291
}
22892292

@@ -2578,7 +2581,7 @@ mod remote_tests {
25782581
#[tokio::test]
25792582
async fn run_migrations() {
25802583
if var("RUN_MIGRATION_TESTS").is_err() {
2581-
return
2584+
return;
25822585
}
25832586

25842587
sp_tracing::try_init_simple();

0 commit comments

Comments
 (0)