mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 02:51:01 +00:00
XCMv4 (#1230)
# Note for reviewer
Most changes are just syntax changes necessary for the new version.
Most important files should be the ones under the `xcm` folder.
# Description
Added XCMv4.
## Removed `Multi` prefix
The following types have been renamed:
- MultiLocation -> Location
- MultiAsset -> Asset
- MultiAssets -> Assets
- InteriorMultiLocation -> InteriorLocation
- MultiAssetFilter -> AssetFilter
- VersionedMultiAsset -> VersionedAsset
- WildMultiAsset -> WildAsset
- VersionedMultiLocation -> VersionedLocation
In order to fix a name conflict, the `Assets` in `xcm-executor` were
renamed to `HoldingAssets`, as they represent assets in holding.
## Removed `Abstract` asset id
It was not being used anywhere and this simplifies the code.
Now assets are just constructed as follows:
```rust
let asset: Asset = (AssetId(Location::new(1, Here)), 100u128).into();
```
No need for specifying `Concrete` anymore.
## Outcome is now a named fields struct
Instead of
```rust
pub enum Outcome {
Complete(Weight),
Incomplete(Weight, Error),
Error(Error),
}
```
we now have
```rust
pub enum Outcome {
Complete { used: Weight },
Incomplete { used: Weight, error: Error },
Error { error: Error },
}
```
## Added Reanchorable trait
Now both locations and assets implement this trait, making it easier to
reanchor both.
## New syntax for building locations and junctions
Now junctions are built using the following methods:
```rust
let location = Location {
parents: 1,
interior: [Parachain(1000), PalletInstance(50), GeneralIndex(1984)].into()
};
```
or
```rust
let location = Location::new(1, [Parachain(1000), PalletInstance(50), GeneralIndex(1984)]);
```
And they are matched like so:
```rust
match location.unpack() {
(1, [Parachain(id)]) => ...
(0, Here) => ...,
(1, [_]) => ...,
}
```
This syntax is mandatory in v4, and has been also implemented for v2 and
v3 for easier migration.
This was needed to make all sizes smaller.
# TODO
- [x] Scaffold v4
- [x] Port github.com/paritytech/polkadot/pull/7236
- [x] Remove `Multi` prefix
- [x] Remove `Abstract` asset id
---------
Co-authored-by: command-bot <>
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
This commit is contained in:
committed by
GitHub
parent
ec7bfae00a
commit
8428f678fe
@@ -54,8 +54,8 @@ use scale_info::TypeInfo;
|
||||
use sp_core::{H160, H256};
|
||||
use sp_std::{convert::TryFrom, vec};
|
||||
use xcm::prelude::{
|
||||
send_xcm, Instruction::SetTopic, Junction::*, Junctions::*, MultiLocation,
|
||||
SendError as XcmpSendError, SendXcm, Xcm, XcmContext, XcmHash,
|
||||
send_xcm, Instruction::SetTopic, Junction::*, Location, SendError as XcmpSendError, SendXcm,
|
||||
Xcm, XcmContext, XcmHash,
|
||||
};
|
||||
use xcm_executor::traits::TransactAsset;
|
||||
|
||||
@@ -324,7 +324,7 @@ pub mod pallet {
|
||||
}
|
||||
|
||||
pub fn send_xcm(xcm: Xcm<()>, dest: ParaId) -> Result<XcmHash, Error<T>> {
|
||||
let dest = MultiLocation { parents: 1, interior: X1(Parachain(dest.into())) };
|
||||
let dest = Location::new(1, [Parachain(dest.into())]);
|
||||
let (xcm_hash, _) = send_xcm::<T::XcmSender>(dest, xcm).map_err(Error::<T>::from)?;
|
||||
Ok(xcm_hash)
|
||||
}
|
||||
@@ -341,8 +341,8 @@ pub mod pallet {
|
||||
pub fn burn_fees(para_id: ParaId, fee: BalanceOf<T>) -> DispatchResult {
|
||||
let dummy_context =
|
||||
XcmContext { origin: None, message_id: Default::default(), topic: None };
|
||||
let dest = MultiLocation { parents: 1, interior: X1(Parachain(para_id.into())) };
|
||||
let fees = (MultiLocation::parent(), fee.saturated_into::<u128>()).into();
|
||||
let dest = Location::new(1, [Parachain(para_id.into())]);
|
||||
let fees = (Location::parent(), fee.saturated_into::<u128>()).into();
|
||||
T::AssetTransactor::can_check_out(&dest, &fees, &dummy_context).map_err(|error| {
|
||||
log::error!(
|
||||
target: LOG_TARGET,
|
||||
|
||||
@@ -21,8 +21,8 @@ use sp_runtime::{
|
||||
BuildStorage, FixedU128, MultiSignature,
|
||||
};
|
||||
use sp_std::convert::From;
|
||||
use xcm::v3::{prelude::*, MultiAssets, SendXcm};
|
||||
use xcm_executor::Assets;
|
||||
use xcm::v4::{prelude::*, SendXcm};
|
||||
use xcm_executor::AssetsInHolding;
|
||||
|
||||
use crate::{self as inbound_queue};
|
||||
|
||||
@@ -155,17 +155,16 @@ impl SendXcm for MockXcmSender {
|
||||
type Ticket = Xcm<()>;
|
||||
|
||||
fn validate(
|
||||
dest: &mut Option<MultiLocation>,
|
||||
xcm: &mut Option<xcm::v3::Xcm<()>>,
|
||||
dest: &mut Option<Location>,
|
||||
xcm: &mut Option<Xcm<()>>,
|
||||
) -> SendResult<Self::Ticket> {
|
||||
match dest {
|
||||
Some(MultiLocation { interior, .. }) => {
|
||||
if let X1(Parachain(1001)) = interior {
|
||||
return Err(XcmpSendError::NotApplicable)
|
||||
}
|
||||
Ok((xcm.clone().unwrap(), MultiAssets::default()))
|
||||
},
|
||||
_ => Ok((xcm.clone().unwrap(), MultiAssets::default())),
|
||||
if let Some(location) = dest {
|
||||
match location.unpack() {
|
||||
(_, [Parachain(1001)]) => return Err(XcmpSendError::NotApplicable),
|
||||
_ => Ok((xcm.clone().unwrap(), Assets::default())),
|
||||
}
|
||||
} else {
|
||||
Ok((xcm.clone().unwrap(), Assets::default()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,45 +202,33 @@ impl StaticLookup for MockChannelLookup {
|
||||
|
||||
pub struct SuccessfulTransactor;
|
||||
impl TransactAsset for SuccessfulTransactor {
|
||||
fn can_check_in(
|
||||
_origin: &MultiLocation,
|
||||
_what: &MultiAsset,
|
||||
_context: &XcmContext,
|
||||
) -> XcmResult {
|
||||
fn can_check_in(_origin: &Location, _what: &Asset, _context: &XcmContext) -> XcmResult {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn can_check_out(
|
||||
_dest: &MultiLocation,
|
||||
_what: &MultiAsset,
|
||||
_context: &XcmContext,
|
||||
) -> XcmResult {
|
||||
fn can_check_out(_dest: &Location, _what: &Asset, _context: &XcmContext) -> XcmResult {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn deposit_asset(
|
||||
_what: &MultiAsset,
|
||||
_who: &MultiLocation,
|
||||
_context: Option<&XcmContext>,
|
||||
) -> XcmResult {
|
||||
fn deposit_asset(_what: &Asset, _who: &Location, _context: Option<&XcmContext>) -> XcmResult {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn withdraw_asset(
|
||||
_what: &MultiAsset,
|
||||
_who: &MultiLocation,
|
||||
_what: &Asset,
|
||||
_who: &Location,
|
||||
_context: Option<&XcmContext>,
|
||||
) -> Result<Assets, XcmError> {
|
||||
Ok(Assets::default())
|
||||
) -> Result<AssetsInHolding, XcmError> {
|
||||
Ok(AssetsInHolding::default())
|
||||
}
|
||||
|
||||
fn internal_transfer_asset(
|
||||
_what: &MultiAsset,
|
||||
_from: &MultiLocation,
|
||||
_to: &MultiLocation,
|
||||
_what: &Asset,
|
||||
_from: &Location,
|
||||
_to: &Location,
|
||||
_context: &XcmContext,
|
||||
) -> Result<Assets, XcmError> {
|
||||
Ok(Assets::default())
|
||||
) -> Result<AssetsInHolding, XcmError> {
|
||||
Ok(AssetsInHolding::default())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,8 +41,8 @@ fn test_submit_happy_path() {
|
||||
.into(),
|
||||
nonce: 1,
|
||||
message_id: [
|
||||
27, 217, 88, 127, 46, 143, 199, 70, 236, 66, 212, 244, 85, 221, 153, 104, 175, 37,
|
||||
224, 20, 140, 95, 140, 7, 27, 74, 182, 199, 77, 12, 194, 236,
|
||||
57, 61, 232, 3, 66, 61, 25, 190, 234, 188, 193, 174, 13, 186, 1, 64, 237, 94, 73,
|
||||
83, 14, 18, 209, 213, 78, 121, 43, 108, 251, 245, 107, 67,
|
||||
],
|
||||
fee_burned: 110000000000,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user