Skip to content

Commit a27c70f

Browse files
committed
refactor
1 parent 707f0b0 commit a27c70f

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
@@ -124,7 +124,7 @@ use governance::{
124124
TreasurySpender,
125125
};
126126
use xcm_executor::traits::WeightBounds;
127-
use xcm_payment_runtime_api::Error as XcmPaymentError;
127+
use xcm_payment_runtime_api::Error as XcmPaymentApiError;
128128

129129
#[cfg(test)]
130130
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) {
@@ -380,10 +380,12 @@ impl OpaqueKeys for OldSessionKeys {
380380
<<Babe as BoundToRuntimeAppPublic>::Public>::ID => self.babe.as_ref(),
381381
sp_core::crypto::key_types::IM_ONLINE => self.im_online.as_ref(),
382382
<<Initializer as BoundToRuntimeAppPublic>::Public>::ID => self.para_validator.as_ref(),
383-
<<ParaSessionInfo as BoundToRuntimeAppPublic>::Public>::ID =>
384-
self.para_assignment.as_ref(),
385-
<<AuthorityDiscovery as BoundToRuntimeAppPublic>::Public>::ID =>
386-
self.authority_discovery.as_ref(),
383+
<<ParaSessionInfo as BoundToRuntimeAppPublic>::Public>::ID => {
384+
self.para_assignment.as_ref()
385+
},
386+
<<AuthorityDiscovery as BoundToRuntimeAppPublic>::Public>::ID => {
387+
self.authority_discovery.as_ref()
388+
},
387389
<<Beefy as BoundToRuntimeAppPublic>::Public>::ID => self.beefy.as_ref(),
388390
_ => &[],
389391
}
@@ -882,19 +884,19 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
882884
),
883885
ProxyType::IdentityJudgement => matches!(
884886
c,
885-
RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) |
886-
RuntimeCall::Utility(..)
887+
RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. })
888+
| RuntimeCall::Utility(..)
887889
),
888890
ProxyType::CancelProxy => {
889891
matches!(c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }))
890892
},
891893
ProxyType::Auction => matches!(
892894
c,
893-
RuntimeCall::Auctions { .. } |
894-
RuntimeCall::Crowdloan { .. } |
895-
RuntimeCall::Registrar { .. } |
896-
RuntimeCall::Multisig(..) |
897-
RuntimeCall::Slots { .. }
895+
RuntimeCall::Auctions { .. }
896+
| RuntimeCall::Crowdloan { .. }
897+
| RuntimeCall::Registrar { .. }
898+
| RuntimeCall::Multisig(..)
899+
| RuntimeCall::Slots { .. }
898900
),
899901
ProxyType::Society => matches!(c, RuntimeCall::Society(..)),
900902
ProxyType::OnDemandOrdering => matches!(c, RuntimeCall::OnDemandAssignmentProvider(..)),
@@ -1510,11 +1512,11 @@ pub mod migrations {
15101512
let now = frame_system::Pallet::<Runtime>::block_number();
15111513
let lease = slots::Pallet::<Runtime>::lease(para);
15121514
if lease.is_empty() {
1513-
return None
1515+
return None;
15141516
}
15151517
// Lease not yet started, ignore:
15161518
if lease.iter().any(Option::is_none) {
1517-
return None
1519+
return None;
15181520
}
15191521
let (index, _) =
15201522
<slots::Pallet<Runtime> as Leaser<BlockNumber>>::lease_period_index(now)?;
@@ -1576,7 +1578,7 @@ pub mod migrations {
15761578
fn pre_upgrade() -> Result<sp_std::vec::Vec<u8>, sp_runtime::TryRuntimeError> {
15771579
if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC {
15781580
log::warn!(target: "runtime::session_keys", "Skipping session keys migration pre-upgrade check due to spec version (already applied?)");
1579-
return Ok(Vec::new())
1581+
return Ok(Vec::new());
15801582
}
15811583

15821584
log::info!(target: "runtime::session_keys", "Collecting pre-upgrade session keys state");
@@ -1605,7 +1607,7 @@ pub mod migrations {
16051607
fn on_runtime_upgrade() -> Weight {
16061608
if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC {
16071609
log::info!("Skipping session keys upgrade: already applied");
1608-
return <Runtime as frame_system::Config>::DbWeight::get().reads(1)
1610+
return <Runtime as frame_system::Config>::DbWeight::get().reads(1);
16091611
}
16101612
log::trace!("Upgrading session keys");
16111613
Session::upgrade_keys::<OldSessionKeys, _>(transform_session_keys);
@@ -1618,7 +1620,7 @@ pub mod migrations {
16181620
) -> Result<(), sp_runtime::TryRuntimeError> {
16191621
if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC {
16201622
log::warn!(target: "runtime::session_keys", "Skipping session keys migration post-upgrade check due to spec version (already applied?)");
1621-
return Ok(())
1623+
return Ok(());
16221624
}
16231625

16241626
let key_ids = SessionKeys::key_ids();
@@ -1802,33 +1804,33 @@ sp_api::impl_runtime_apis! {
18021804
}
18031805

18041806
impl xcm_payment_runtime_api::XcmPaymentApi<Block, RuntimeCall> for Runtime {
1805-
fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result<Vec<VersionedAssetId>, XcmPaymentError> {
1807+
fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result<Vec<VersionedAssetId>, XcmPaymentApiError> {
18061808
if !matches!(xcm_version, 3 | 4) {
1807-
return Err(XcmPaymentError::UnhandledXcmVersion);
1809+
return Err(XcmPaymentApiError::UnhandledXcmVersion);
18081810
}
18091811
Ok([VersionedAssetId::V4(xcm_config::TokenLocation::get().into())]
18101812
.into_iter()
18111813
.filter_map(|asset| asset.into_version(xcm_version).ok())
18121814
.collect())
18131815
}
18141816

1815-
fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, XcmPaymentError> {
1817+
fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, XcmPaymentApiError> {
18161818
let local_asset = VersionedAssetId::V4(xcm_config::TokenLocation::get().into());
18171819
let asset = asset
18181820
.into_version(4)
1819-
.map_err(|_| XcmPaymentError::VersionedConversionFailed)?;
1821+
.map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;
18201822

1821-
if asset != local_asset { return Err(XcmPaymentError::AssetNotFound); }
1823+
if asset != local_asset { return Err(XcmPaymentApiError::AssetNotFound); }
18221824

18231825
Ok(WeightToFee::weight_to_fee(&weight))
18241826
}
18251827

1826-
fn query_xcm_weight(message: VersionedXcm<RuntimeCall>) -> Result<Weight, XcmPaymentError> {
1828+
fn query_xcm_weight(message: VersionedXcm<RuntimeCall>) -> Result<Weight, XcmPaymentApiError> {
18271829
let mut message = message
18281830
.try_into()
1829-
.map_err(|_| XcmPaymentError::VersionedConversionFailed)?;
1831+
.map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;
18301832
<xcm_config::XcmConfig as xcm_executor::Config>::Weigher::weight(&mut message)
1831-
.map_err(|_| XcmPaymentError::WeightNotComputable)
1833+
.map_err(|_| XcmPaymentApiError::WeightNotComputable)
18321834
}
18331835
}
18341836

@@ -2542,7 +2544,7 @@ mod remote_tests {
25422544
#[tokio::test]
25432545
async fn run_migrations() {
25442546
if var("RUN_MIGRATION_TESTS").is_err() {
2545-
return
2547+
return;
25462548
}
25472549

25482550
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
@@ -107,7 +107,7 @@ use xcm::{
107107
use xcm_builder::PayOverXcm;
108108

109109
use xcm_executor::traits::WeightBounds;
110-
use xcm_payment_runtime_api::Error as XcmPaymentError;
110+
use xcm_payment_runtime_api::Error as XcmPaymentApiError;
111111

112112
pub use frame_system::Call as SystemCall;
113113
pub use pallet_balances::Call as BalancesCall;
@@ -442,10 +442,12 @@ impl OpaqueKeys for OldSessionKeys {
442442
<<Babe as BoundToRuntimeAppPublic>::Public>::ID => self.babe.as_ref(),
443443
sp_core::crypto::key_types::IM_ONLINE => self.im_online.as_ref(),
444444
<<Initializer as BoundToRuntimeAppPublic>::Public>::ID => self.para_validator.as_ref(),
445-
<<ParaSessionInfo as BoundToRuntimeAppPublic>::Public>::ID =>
446-
self.para_assignment.as_ref(),
447-
<<AuthorityDiscovery as BoundToRuntimeAppPublic>::Public>::ID =>
448-
self.authority_discovery.as_ref(),
445+
<<ParaSessionInfo as BoundToRuntimeAppPublic>::Public>::ID => {
446+
self.para_assignment.as_ref()
447+
},
448+
<<AuthorityDiscovery as BoundToRuntimeAppPublic>::Public>::ID => {
449+
self.authority_discovery.as_ref()
450+
},
449451
<<Beefy as BoundToRuntimeAppPublic>::Public>::ID => self.beefy.as_ref(),
450452
_ => &[],
451453
}
@@ -1052,11 +1054,12 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
10521054
ProxyType::Staking => {
10531055
matches!(
10541056
c,
1055-
RuntimeCall::Staking(..) |
1056-
RuntimeCall::Session(..) | RuntimeCall::Utility(..) |
1057-
RuntimeCall::FastUnstake(..) |
1058-
RuntimeCall::VoterList(..) |
1059-
RuntimeCall::NominationPools(..)
1057+
RuntimeCall::Staking(..)
1058+
| RuntimeCall::Session(..)
1059+
| RuntimeCall::Utility(..)
1060+
| RuntimeCall::FastUnstake(..)
1061+
| RuntimeCall::VoterList(..)
1062+
| RuntimeCall::NominationPools(..)
10601063
)
10611064
},
10621065
ProxyType::NominationPools => {
@@ -1072,24 +1075,24 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
10721075
ProxyType::Governance => matches!(
10731076
c,
10741077
// OpenGov calls
1075-
RuntimeCall::ConvictionVoting(..) |
1076-
RuntimeCall::Referenda(..) |
1077-
RuntimeCall::Whitelist(..)
1078+
RuntimeCall::ConvictionVoting(..)
1079+
| RuntimeCall::Referenda(..)
1080+
| RuntimeCall::Whitelist(..)
10781081
),
10791082
ProxyType::IdentityJudgement => matches!(
10801083
c,
1081-
RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) |
1082-
RuntimeCall::Utility(..)
1084+
RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. })
1085+
| RuntimeCall::Utility(..)
10831086
),
10841087
ProxyType::CancelProxy => {
10851088
matches!(c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }))
10861089
},
10871090
ProxyType::Auction => matches!(
10881091
c,
1089-
RuntimeCall::Auctions(..) |
1090-
RuntimeCall::Crowdloan(..) |
1091-
RuntimeCall::Registrar(..) |
1092-
RuntimeCall::Slots(..)
1092+
RuntimeCall::Auctions(..)
1093+
| RuntimeCall::Crowdloan(..)
1094+
| RuntimeCall::Registrar(..)
1095+
| RuntimeCall::Slots(..)
10931096
),
10941097
}
10951098
}
@@ -1592,11 +1595,11 @@ pub mod migrations {
15921595
let now = frame_system::Pallet::<Runtime>::block_number();
15931596
let lease = slots::Pallet::<Runtime>::lease(para);
15941597
if lease.is_empty() {
1595-
return None
1598+
return None;
15961599
}
15971600
// Lease not yet started, ignore:
15981601
if lease.iter().any(Option::is_none) {
1599-
return None
1602+
return None;
16001603
}
16011604
let (index, _) =
16021605
<slots::Pallet<Runtime> as Leaser<BlockNumber>>::lease_period_index(now)?;
@@ -1618,7 +1621,7 @@ pub mod migrations {
16181621
fn pre_upgrade() -> Result<sp_std::vec::Vec<u8>, sp_runtime::TryRuntimeError> {
16191622
if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC {
16201623
log::warn!(target: "runtime::session_keys", "Skipping session keys migration pre-upgrade check due to spec version (already applied?)");
1621-
return Ok(Vec::new())
1624+
return Ok(Vec::new());
16221625
}
16231626

16241627
log::info!(target: "runtime::session_keys", "Collecting pre-upgrade session keys state");
@@ -1647,7 +1650,7 @@ pub mod migrations {
16471650
fn on_runtime_upgrade() -> Weight {
16481651
if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC {
16491652
log::warn!("Skipping session keys upgrade: already applied");
1650-
return <Runtime as frame_system::Config>::DbWeight::get().reads(1)
1653+
return <Runtime as frame_system::Config>::DbWeight::get().reads(1);
16511654
}
16521655
log::info!("Upgrading session keys");
16531656
Session::upgrade_keys::<OldSessionKeys, _>(transform_session_keys);
@@ -1660,7 +1663,7 @@ pub mod migrations {
16601663
) -> Result<(), sp_runtime::TryRuntimeError> {
16611664
if System::last_runtime_upgrade_spec_version() > UPGRADE_SESSION_KEYS_FROM_SPEC {
16621665
log::warn!(target: "runtime::session_keys", "Skipping session keys migration post-upgrade check due to spec version (already applied?)");
1663-
return Ok(())
1666+
return Ok(());
16641667
}
16651668

16661669
let key_ids = SessionKeys::key_ids();
@@ -2259,33 +2262,33 @@ sp_api::impl_runtime_apis! {
22592262
}
22602263

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

2272-
fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, XcmPaymentError> {
2275+
fn query_weight_to_asset_fee(weight: Weight, asset: VersionedAssetId) -> Result<u128, XcmPaymentApiError> {
22732276
let local_asset = VersionedAssetId::V4(xcm_config::TokenLocation::get().into());
22742277
let asset = asset
22752278
.into_version(4)
2276-
.map_err(|_| XcmPaymentError::VersionedConversionFailed)?;
2279+
.map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;
22772280

2278-
if asset != local_asset { return Err(XcmPaymentError::AssetNotFound); }
2281+
if asset != local_asset { return Err(XcmPaymentApiError::AssetNotFound); }
22792282

22802283
Ok(WeightToFee::weight_to_fee(&weight))
22812284
}
22822285

2283-
fn query_xcm_weight(message: VersionedXcm<RuntimeCall>) -> Result<Weight, XcmPaymentError> {
2286+
fn query_xcm_weight(message: VersionedXcm<RuntimeCall>) -> Result<Weight, XcmPaymentApiError> {
22842287
let mut message = message
22852288
.try_into()
2286-
.map_err(|_| XcmPaymentError::VersionedConversionFailed)?;
2289+
.map_err(|_| XcmPaymentApiError::VersionedConversionFailed)?;
22872290
<xcm_config::XcmConfig as xcm_executor::Config>::Weigher::weight(&mut message)
2288-
.map_err(|_| XcmPaymentError::WeightNotComputable)
2291+
.map_err(|_| XcmPaymentApiError::WeightNotComputable)
22892292
}
22902293
}
22912294

@@ -2609,7 +2612,7 @@ mod remote_tests {
26092612
#[tokio::test]
26102613
async fn run_migrations() {
26112614
if var("RUN_MIGRATION_TESTS").is_err() {
2612-
return
2615+
return;
26132616
}
26142617

26152618
sp_tracing::try_init_simple();

0 commit comments

Comments
 (0)