mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 22:41:02 +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
@@ -30,7 +30,7 @@ use xcm_executor::traits::{QueryHandler, QueryResponseStatus};
|
||||
/// ownership of some `Interior` location of the local chain to a particular `Beneficiary`. The
|
||||
/// `AssetKind` value is not itself bounded (to avoid the issue of needing to wrap some preexisting
|
||||
/// datatype), however a converter type `AssetKindToLocatableAsset` must be provided in order to
|
||||
/// translate it into a `LocatableAsset`, which comprises both an XCM `MultiLocation` describing
|
||||
/// translate it into a `LocatableAsset`, which comprises both an XCM `Location` describing
|
||||
/// the XCM endpoint on which the asset to be paid resides and an XCM `AssetId` to identify the
|
||||
/// specific asset at that endpoint.
|
||||
///
|
||||
@@ -65,14 +65,14 @@ pub struct PayOverXcm<
|
||||
)>,
|
||||
);
|
||||
impl<
|
||||
Interior: Get<InteriorMultiLocation>,
|
||||
Interior: Get<InteriorLocation>,
|
||||
Router: SendXcm,
|
||||
Querier: QueryHandler,
|
||||
Timeout: Get<Querier::BlockNumber>,
|
||||
Beneficiary: Clone,
|
||||
AssetKind,
|
||||
AssetKindToLocatableAsset: TryConvert<AssetKind, LocatableAssetId>,
|
||||
BeneficiaryRefToLocation: for<'a> TryConvert<&'a Beneficiary, MultiLocation>,
|
||||
BeneficiaryRefToLocation: for<'a> TryConvert<&'a Beneficiary, Location>,
|
||||
> Pay
|
||||
for PayOverXcm<
|
||||
Interior,
|
||||
@@ -105,7 +105,7 @@ impl<
|
||||
let beneficiary = BeneficiaryRefToLocation::try_convert(&who)
|
||||
.map_err(|_| xcm::latest::Error::InvalidLocation)?;
|
||||
|
||||
let query_id = Querier::new_query(asset_location, Timeout::get(), Interior::get());
|
||||
let query_id = Querier::new_query(asset_location.clone(), Timeout::get(), Interior::get());
|
||||
|
||||
let message = Xcm(vec![
|
||||
DescendOrigin(Interior::get()),
|
||||
@@ -120,8 +120,7 @@ impl<
|
||||
])),
|
||||
TransferAsset {
|
||||
beneficiary,
|
||||
assets: vec![MultiAsset { id: asset_id, fun: Fungibility::Fungible(amount) }]
|
||||
.into(),
|
||||
assets: vec![Asset { id: asset_id, fun: Fungibility::Fungible(amount) }].into(),
|
||||
},
|
||||
]);
|
||||
|
||||
@@ -195,16 +194,16 @@ pub struct LocatableAssetId {
|
||||
/// The asset's ID.
|
||||
pub asset_id: AssetId,
|
||||
/// The (relative) location in which the asset ID is meaningful.
|
||||
pub location: MultiLocation,
|
||||
pub location: Location,
|
||||
}
|
||||
|
||||
/// Adapter `struct` which implements a conversion from any `AssetKind` into a [`LocatableAssetId`]
|
||||
/// value using a fixed `Location` for the `location` field.
|
||||
pub struct FixedLocation<Location>(sp_std::marker::PhantomData<Location>);
|
||||
impl<Location: Get<MultiLocation>, AssetKind: Into<AssetId>> TryConvert<AssetKind, LocatableAssetId>
|
||||
for FixedLocation<Location>
|
||||
pub struct FixedLocation<FixedLocationValue>(sp_std::marker::PhantomData<FixedLocationValue>);
|
||||
impl<FixedLocationValue: Get<Location>, AssetKind: Into<AssetId>>
|
||||
TryConvert<AssetKind, LocatableAssetId> for FixedLocation<FixedLocationValue>
|
||||
{
|
||||
fn try_convert(value: AssetKind) -> Result<LocatableAssetId, AssetKind> {
|
||||
Ok(LocatableAssetId { asset_id: value.into(), location: Location::get() })
|
||||
Ok(LocatableAssetId { asset_id: value.into(), location: FixedLocationValue::get() })
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user