Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
pallet-xcm: minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
acatangiu committed Jul 10, 2023
1 parent dd125cc commit afc70e2
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions xcm/pallet-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1208,19 +1208,13 @@ impl<T: Config> Pallet<T> {
let context = T::UniversalLocation::get();
let weight_limit = Limited(Weight::zero());

// estimate weight_limit by weighing message to be executed on destination
let mut remote_message = match destination_fees_setup {
let buy_execution_on_dest = match destination_fees_setup {
DestinationFeesSetup::ByOrigin => {
let fees = origin_fees
.clone()
.reanchored(&dest, context)
.map_err(|_| Error::<T>::CannotReanchor)?;
Xcm(vec![
ReserveAssetDeposited(assets),
ClearOrigin,
BuyExecution { fees, weight_limit },
DepositAsset { assets: Wild(AllCounted(max_assets)), beneficiary },
])
vec![BuyExecution { fees, weight_limit }]
},
DestinationFeesSetup::ByUniversalLocation { .. } => {
let sovereign_account_on_destination = T::UniversalLocation::get()
Expand All @@ -1235,9 +1229,7 @@ impl<T: Config> Pallet<T> {
.clone()
.reanchored(&dest, context)
.map_err(|_| Error::<T>::CannotReanchor)?;
Xcm(vec![
ReserveAssetDeposited(assets.clone()),
ClearOrigin,
vec![
// Change origin to sovereign account of `T::UniversalLocation` on destination.
AliasOrigin(sovereign_account_on_destination),
// Withdraw fees (do not use those in `ReserveAssetDeposited`)
Expand All @@ -1250,12 +1242,16 @@ impl<T: Config> Pallet<T> {
assets: MultiAssetFilter::from(MultiAssets::from(remote_fees)),
beneficiary: sovereign_account_on_destination,
},
// deposit `assets` to beneficiary
DepositAsset { assets: MultiAssetFilter::from(assets), beneficiary },
])
]
},
};

let mut remote_message = Xcm(vec![ReserveAssetDeposited(assets), ClearOrigin]);
remote_message.0.extend_from_slice(&buy_execution_on_dest);
remote_message
.0
.push(DepositAsset { assets: Wild(AllCounted(max_assets)), beneficiary });

// if message is going to different consensus, also include `UniversalOrigin/DescendOrigin`
if ensure_is_remote(T::UniversalLocation::get(), dest).is_ok() {
let (local_net, local_sub) = T::UniversalLocation::get()
Expand Down

0 comments on commit afc70e2

Please sign in to comment.