mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-22 02:05:41 +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
@@ -18,18 +18,18 @@ use crate::*;
|
||||
use frame_support::{parameter_types, traits::fungibles::Inspect};
|
||||
use mock::{setup_pool, AccountId, AssetId, Balance, Fungibles};
|
||||
use xcm::latest::AssetId as XcmAssetId;
|
||||
use xcm_executor::Assets as HoldingAsset;
|
||||
use xcm_executor::AssetsInHolding;
|
||||
|
||||
fn create_holding_asset(asset_id: AssetId, amount: Balance) -> HoldingAsset {
|
||||
fn create_holding_asset(asset_id: AssetId, amount: Balance) -> AssetsInHolding {
|
||||
create_asset(asset_id, amount).into()
|
||||
}
|
||||
|
||||
fn create_asset(asset_id: AssetId, amount: Balance) -> MultiAsset {
|
||||
MultiAsset { id: create_asset_id(asset_id), fun: Fungible(amount) }
|
||||
fn create_asset(asset_id: AssetId, amount: Balance) -> Asset {
|
||||
Asset { id: create_asset_id(asset_id), fun: Fungible(amount) }
|
||||
}
|
||||
|
||||
fn create_asset_id(asset_id: AssetId) -> XcmAssetId {
|
||||
Concrete(MultiLocation::new(0, X1(GeneralIndex(asset_id.into()))))
|
||||
AssetId(Location::new(0, [GeneralIndex(asset_id.into())]))
|
||||
}
|
||||
|
||||
fn xcm_context() -> XcmContext {
|
||||
@@ -319,7 +319,7 @@ fn empty_holding_asset() {
|
||||
let mut trader = Trader::new();
|
||||
assert_eq!(
|
||||
trader
|
||||
.buy_weight(Weight::from_all(10), HoldingAsset::new(), &xcm_context())
|
||||
.buy_weight(Weight::from_all(10), AssetsInHolding::new(), &xcm_context())
|
||||
.unwrap_err(),
|
||||
XcmError::AssetNotFound
|
||||
);
|
||||
@@ -328,8 +328,7 @@ fn empty_holding_asset() {
|
||||
#[test]
|
||||
fn fails_to_match_holding_asset() {
|
||||
let mut trader = Trader::new();
|
||||
let holding_asset =
|
||||
MultiAsset { id: Concrete(MultiLocation::new(1, X1(Parachain(1)))), fun: Fungible(10) };
|
||||
let holding_asset = Asset { id: AssetId(Location::new(1, [Parachain(1)])), fun: Fungible(10) };
|
||||
assert_eq!(
|
||||
trader
|
||||
.buy_weight(Weight::from_all(10), holding_asset.into(), &xcm_context())
|
||||
@@ -536,14 +535,15 @@ pub mod mock {
|
||||
pub struct FungiblesMatcher;
|
||||
impl MatchesFungibles<AssetId, Balance> for FungiblesMatcher {
|
||||
fn matches_fungibles(
|
||||
a: &MultiAsset,
|
||||
a: &Asset,
|
||||
) -> core::result::Result<(AssetId, Balance), xcm_executor::traits::Error> {
|
||||
match a {
|
||||
MultiAsset {
|
||||
fun: Fungible(amount),
|
||||
id:
|
||||
Concrete(MultiLocation { parents: 0, interior: X1(Junction::GeneralIndex(id)) }),
|
||||
} => Ok(((*id).try_into().unwrap(), *amount)),
|
||||
Asset { fun: Fungible(amount), id: AssetId(inner_location) } =>
|
||||
match inner_location.unpack() {
|
||||
(0, [Junction::GeneralIndex(id)]) =>
|
||||
Ok(((*id).try_into().unwrap(), *amount)),
|
||||
_ => Err(xcm_executor::traits::Error::AssetNotHandled),
|
||||
},
|
||||
_ => Err(xcm_executor::traits::Error::AssetNotHandled),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user