mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 09:21:04 +00:00
XCM: Use matcher API in DenyReserveAssetTransferToRelay (#2290)
* Use matcher API in DenyReserveAssetTransferToRelay * Fixes * Fixes * Fixes * cargo fmt
This commit is contained in:
@@ -2,7 +2,7 @@ use super::{
|
|||||||
AccountId, AllPalletsWithSystem, Balances, ParachainInfo, ParachainSystem, PolkadotXcm,
|
AccountId, AllPalletsWithSystem, Balances, ParachainInfo, ParachainSystem, PolkadotXcm,
|
||||||
Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue,
|
Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue,
|
||||||
};
|
};
|
||||||
use core::marker::PhantomData;
|
use core::{marker::PhantomData, ops::ControlFlow};
|
||||||
use frame_support::{
|
use frame_support::{
|
||||||
log, match_types, parameter_types,
|
log, match_types, parameter_types,
|
||||||
traits::{ConstU32, Everything, Nothing},
|
traits::{ConstU32, Everything, Nothing},
|
||||||
@@ -11,7 +11,7 @@ use frame_support::{
|
|||||||
use pallet_xcm::XcmPassthrough;
|
use pallet_xcm::XcmPassthrough;
|
||||||
use polkadot_parachain::primitives::Sibling;
|
use polkadot_parachain::primitives::Sibling;
|
||||||
use polkadot_runtime_common::impls::ToAuthor;
|
use polkadot_runtime_common::impls::ToAuthor;
|
||||||
use xcm::latest::prelude::*;
|
use xcm::{latest::prelude::*, CreateMatcher, MatchXcm};
|
||||||
use xcm_builder::{
|
use xcm_builder::{
|
||||||
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom,
|
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom,
|
||||||
CurrencyAdapter, EnsureXcmOrigin, FixedWeightBounds, IsConcrete, NativeAsset, ParentIsPreset,
|
CurrencyAdapter, EnsureXcmOrigin, FixedWeightBounds, IsConcrete, NativeAsset, ParentIsPreset,
|
||||||
@@ -122,32 +122,36 @@ impl ShouldExecute for DenyReserveTransferToRelayChain {
|
|||||||
_max_weight: Weight,
|
_max_weight: Weight,
|
||||||
_weight_credit: &mut Weight,
|
_weight_credit: &mut Weight,
|
||||||
) -> Result<(), ()> {
|
) -> Result<(), ()> {
|
||||||
if message.iter().any(|inst| {
|
message.matcher().match_next_inst_while(
|
||||||
matches!(
|
|_| true,
|
||||||
inst,
|
|inst| match inst {
|
||||||
InitiateReserveWithdraw {
|
InitiateReserveWithdraw {
|
||||||
reserve: MultiLocation { parents: 1, interior: Here },
|
reserve: MultiLocation { parents: 1, interior: Here },
|
||||||
..
|
..
|
||||||
} | DepositReserveAsset { dest: MultiLocation { parents: 1, interior: Here }, .. } |
|
} |
|
||||||
TransferReserveAsset {
|
DepositReserveAsset {
|
||||||
dest: MultiLocation { parents: 1, interior: Here },
|
dest: MultiLocation { parents: 1, interior: Here }, ..
|
||||||
..
|
} |
|
||||||
}
|
TransferReserveAsset {
|
||||||
)
|
dest: MultiLocation { parents: 1, interior: Here }, ..
|
||||||
}) {
|
} => {
|
||||||
return Err(()) // Deny
|
Err(()) // Deny
|
||||||
}
|
},
|
||||||
|
// An unexpected reserve transfer has arrived from the Relay Chain. Generally,
|
||||||
|
// `IsReserve` should not allow this, but we just log it here.
|
||||||
|
ReserveAssetDeposited { .. }
|
||||||
|
if matches!(origin, MultiLocation { parents: 1, interior: Here }) =>
|
||||||
|
{
|
||||||
|
log::warn!(
|
||||||
|
target: "xcm::barrier",
|
||||||
|
"Unexpected ReserveAssetDeposited from the Relay Chain",
|
||||||
|
);
|
||||||
|
Ok(ControlFlow::Continue(()))
|
||||||
|
},
|
||||||
|
_ => Ok(ControlFlow::Continue(())),
|
||||||
|
},
|
||||||
|
)?;
|
||||||
|
|
||||||
// An unexpected reserve transfer has arrived from the Relay Chain. Generally, `IsReserve`
|
|
||||||
// should not allow this, but we just log it here.
|
|
||||||
if matches!(origin, MultiLocation { parents: 1, interior: Here }) &&
|
|
||||||
message.iter().any(|inst| matches!(inst, ReserveAssetDeposited { .. }))
|
|
||||||
{
|
|
||||||
log::warn!(
|
|
||||||
target: "xcm::barriers",
|
|
||||||
"Unexpected ReserveAssetDeposited from the Relay Chain",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// Permit everything else
|
// Permit everything else
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
use crate::impls::AccountIdOf;
|
use crate::impls::AccountIdOf;
|
||||||
use core::marker::PhantomData;
|
use core::{marker::PhantomData, ops::ControlFlow};
|
||||||
use frame_support::{
|
use frame_support::{
|
||||||
log,
|
log,
|
||||||
traits::{fungibles::Inspect, tokens::BalanceConversion, ContainsPair},
|
traits::{fungibles::Inspect, tokens::BalanceConversion, ContainsPair},
|
||||||
weights::{Weight, WeightToFee, WeightToFeePolynomial},
|
weights::{Weight, WeightToFee, WeightToFeePolynomial},
|
||||||
};
|
};
|
||||||
use sp_runtime::traits::Get;
|
use sp_runtime::traits::Get;
|
||||||
use xcm::latest::prelude::*;
|
use xcm::{latest::prelude::*, CreateMatcher, MatchXcm};
|
||||||
use xcm_executor::traits::ShouldExecute;
|
use xcm_executor::traits::ShouldExecute;
|
||||||
|
|
||||||
//TODO: move DenyThenTry to polkadot's xcm module.
|
//TODO: move DenyThenTry to polkadot's xcm module.
|
||||||
@@ -42,32 +42,38 @@ impl ShouldExecute for DenyReserveTransferToRelayChain {
|
|||||||
_max_weight: Weight,
|
_max_weight: Weight,
|
||||||
_weight_credit: &mut Weight,
|
_weight_credit: &mut Weight,
|
||||||
) -> Result<(), ()> {
|
) -> Result<(), ()> {
|
||||||
if message.iter().any(|inst| {
|
message.matcher().match_next_inst_while(
|
||||||
matches!(
|
|_| true,
|
||||||
inst,
|
|inst| match inst {
|
||||||
InitiateReserveWithdraw {
|
InitiateReserveWithdraw {
|
||||||
reserve: MultiLocation { parents: 1, interior: Here },
|
reserve: MultiLocation { parents: 1, interior: Here },
|
||||||
..
|
..
|
||||||
} | DepositReserveAsset { dest: MultiLocation { parents: 1, interior: Here }, .. } |
|
} |
|
||||||
TransferReserveAsset {
|
DepositReserveAsset {
|
||||||
dest: MultiLocation { parents: 1, interior: Here },
|
dest: MultiLocation { parents: 1, interior: Here }, ..
|
||||||
..
|
} |
|
||||||
}
|
TransferReserveAsset {
|
||||||
)
|
dest: MultiLocation { parents: 1, interior: Here }, ..
|
||||||
}) {
|
} => {
|
||||||
return Err(()) // Deny
|
Err(()) // Deny
|
||||||
}
|
},
|
||||||
|
|
||||||
|
// An unexpected reserve transfer has arrived from the Relay Chain. Generally,
|
||||||
|
// `IsReserve` should not allow this, but we just log it here.
|
||||||
|
ReserveAssetDeposited { .. }
|
||||||
|
if matches!(origin, MultiLocation { parents: 1, interior: Here }) =>
|
||||||
|
{
|
||||||
|
log::warn!(
|
||||||
|
target: "xcm::barrier",
|
||||||
|
"Unexpected ReserveAssetDeposited from the Relay Chain",
|
||||||
|
);
|
||||||
|
Ok(ControlFlow::Continue(()))
|
||||||
|
},
|
||||||
|
|
||||||
|
_ => Ok(ControlFlow::Continue(())),
|
||||||
|
},
|
||||||
|
)?;
|
||||||
|
|
||||||
// An unexpected reserve transfer has arrived from the Relay Chain. Generally, `IsReserve`
|
|
||||||
// should not allow this, but we just log it here.
|
|
||||||
if matches!(origin, MultiLocation { parents: 1, interior: Here }) &&
|
|
||||||
message.iter().any(|inst| matches!(inst, ReserveAssetDeposited { .. }))
|
|
||||||
{
|
|
||||||
log::warn!(
|
|
||||||
target: "xcm::barriers",
|
|
||||||
"Unexpected ReserveAssetDeposited from the Relay Chain",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// Permit everything else
|
// Permit everything else
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user