mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 19:11: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
@@ -25,7 +25,10 @@ use frame_support::traits::{
|
||||
};
|
||||
use sp_std::{marker::PhantomData, prelude::*, result};
|
||||
use xcm::latest::prelude::*;
|
||||
use xcm_executor::traits::{ConvertLocation, Error as MatchError, MatchesFungible, TransactAsset};
|
||||
use xcm_executor::{
|
||||
traits::{ConvertLocation, Error as MatchError, MatchesFungible, TransactAsset},
|
||||
AssetsInHolding,
|
||||
};
|
||||
|
||||
/// [`TransactAsset`] implementation that allows the use of a [`fungible`] implementation for
|
||||
/// handling an asset in the XCM executor.
|
||||
@@ -41,11 +44,11 @@ impl<
|
||||
> TransactAsset for FungibleTransferAdapter<Fungible, Matcher, AccountIdConverter, AccountId>
|
||||
{
|
||||
fn internal_transfer_asset(
|
||||
what: &MultiAsset,
|
||||
from: &MultiLocation,
|
||||
to: &MultiLocation,
|
||||
what: &Asset,
|
||||
from: &Location,
|
||||
to: &Location,
|
||||
_context: &XcmContext,
|
||||
) -> result::Result<xcm_executor::Assets, XcmError> {
|
||||
) -> result::Result<AssetsInHolding, XcmError> {
|
||||
log::trace!(
|
||||
target: "xcm::fungible_adapter",
|
||||
"internal_transfer_asset what: {:?}, from: {:?}, to: {:?}",
|
||||
@@ -111,11 +114,7 @@ impl<
|
||||
> TransactAsset
|
||||
for FungibleMutateAdapter<Fungible, Matcher, AccountIdConverter, AccountId, CheckingAccount>
|
||||
{
|
||||
fn can_check_in(
|
||||
_origin: &MultiLocation,
|
||||
what: &MultiAsset,
|
||||
_context: &XcmContext,
|
||||
) -> XcmResult {
|
||||
fn can_check_in(_origin: &Location, what: &Asset, _context: &XcmContext) -> XcmResult {
|
||||
log::trace!(
|
||||
target: "xcm::fungible_adapter",
|
||||
"can_check_in origin: {:?}, what: {:?}",
|
||||
@@ -132,7 +131,7 @@ impl<
|
||||
}
|
||||
}
|
||||
|
||||
fn check_in(_origin: &MultiLocation, what: &MultiAsset, _context: &XcmContext) {
|
||||
fn check_in(_origin: &Location, what: &Asset, _context: &XcmContext) {
|
||||
log::trace!(
|
||||
target: "xcm::fungible_adapter",
|
||||
"check_in origin: {:?}, what: {:?}",
|
||||
@@ -149,7 +148,7 @@ impl<
|
||||
}
|
||||
}
|
||||
|
||||
fn can_check_out(_dest: &MultiLocation, what: &MultiAsset, _context: &XcmContext) -> XcmResult {
|
||||
fn can_check_out(_dest: &Location, what: &Asset, _context: &XcmContext) -> XcmResult {
|
||||
log::trace!(
|
||||
target: "xcm::fungible_adapter",
|
||||
"check_out dest: {:?}, what: {:?}",
|
||||
@@ -166,7 +165,7 @@ impl<
|
||||
}
|
||||
}
|
||||
|
||||
fn check_out(_dest: &MultiLocation, what: &MultiAsset, _context: &XcmContext) {
|
||||
fn check_out(_dest: &Location, what: &Asset, _context: &XcmContext) {
|
||||
log::trace!(
|
||||
target: "xcm::fungible_adapter",
|
||||
"check_out dest: {:?}, what: {:?}",
|
||||
@@ -184,11 +183,7 @@ impl<
|
||||
}
|
||||
}
|
||||
|
||||
fn deposit_asset(
|
||||
what: &MultiAsset,
|
||||
who: &MultiLocation,
|
||||
_context: Option<&XcmContext>,
|
||||
) -> XcmResult {
|
||||
fn deposit_asset(what: &Asset, who: &Location, _context: Option<&XcmContext>) -> XcmResult {
|
||||
log::trace!(
|
||||
target: "xcm::fungible_adapter",
|
||||
"deposit_asset what: {:?}, who: {:?}",
|
||||
@@ -203,10 +198,10 @@ impl<
|
||||
}
|
||||
|
||||
fn withdraw_asset(
|
||||
what: &MultiAsset,
|
||||
who: &MultiLocation,
|
||||
what: &Asset,
|
||||
who: &Location,
|
||||
_context: Option<&XcmContext>,
|
||||
) -> result::Result<xcm_executor::Assets, XcmError> {
|
||||
) -> result::Result<AssetsInHolding, XcmError> {
|
||||
log::trace!(
|
||||
target: "xcm::fungible_adapter",
|
||||
"deposit_asset what: {:?}, who: {:?}",
|
||||
@@ -236,7 +231,7 @@ impl<
|
||||
> TransactAsset
|
||||
for FungibleAdapter<Fungible, Matcher, AccountIdConverter, AccountId, CheckingAccount>
|
||||
{
|
||||
fn can_check_in(origin: &MultiLocation, what: &MultiAsset, context: &XcmContext) -> XcmResult {
|
||||
fn can_check_in(origin: &Location, what: &Asset, context: &XcmContext) -> XcmResult {
|
||||
FungibleMutateAdapter::<
|
||||
Fungible,
|
||||
Matcher,
|
||||
@@ -246,7 +241,7 @@ impl<
|
||||
>::can_check_in(origin, what, context)
|
||||
}
|
||||
|
||||
fn check_in(origin: &MultiLocation, what: &MultiAsset, context: &XcmContext) {
|
||||
fn check_in(origin: &Location, what: &Asset, context: &XcmContext) {
|
||||
FungibleMutateAdapter::<
|
||||
Fungible,
|
||||
Matcher,
|
||||
@@ -256,7 +251,7 @@ impl<
|
||||
>::check_in(origin, what, context)
|
||||
}
|
||||
|
||||
fn can_check_out(dest: &MultiLocation, what: &MultiAsset, context: &XcmContext) -> XcmResult {
|
||||
fn can_check_out(dest: &Location, what: &Asset, context: &XcmContext) -> XcmResult {
|
||||
FungibleMutateAdapter::<
|
||||
Fungible,
|
||||
Matcher,
|
||||
@@ -266,7 +261,7 @@ impl<
|
||||
>::can_check_out(dest, what, context)
|
||||
}
|
||||
|
||||
fn check_out(dest: &MultiLocation, what: &MultiAsset, context: &XcmContext) {
|
||||
fn check_out(dest: &Location, what: &Asset, context: &XcmContext) {
|
||||
FungibleMutateAdapter::<
|
||||
Fungible,
|
||||
Matcher,
|
||||
@@ -276,11 +271,7 @@ impl<
|
||||
>::check_out(dest, what, context)
|
||||
}
|
||||
|
||||
fn deposit_asset(
|
||||
what: &MultiAsset,
|
||||
who: &MultiLocation,
|
||||
context: Option<&XcmContext>,
|
||||
) -> XcmResult {
|
||||
fn deposit_asset(what: &Asset, who: &Location, context: Option<&XcmContext>) -> XcmResult {
|
||||
FungibleMutateAdapter::<
|
||||
Fungible,
|
||||
Matcher,
|
||||
@@ -291,10 +282,10 @@ impl<
|
||||
}
|
||||
|
||||
fn withdraw_asset(
|
||||
what: &MultiAsset,
|
||||
who: &MultiLocation,
|
||||
what: &Asset,
|
||||
who: &Location,
|
||||
maybe_context: Option<&XcmContext>,
|
||||
) -> result::Result<xcm_executor::Assets, XcmError> {
|
||||
) -> result::Result<AssetsInHolding, XcmError> {
|
||||
FungibleMutateAdapter::<
|
||||
Fungible,
|
||||
Matcher,
|
||||
@@ -305,11 +296,11 @@ impl<
|
||||
}
|
||||
|
||||
fn internal_transfer_asset(
|
||||
what: &MultiAsset,
|
||||
from: &MultiLocation,
|
||||
to: &MultiLocation,
|
||||
what: &Asset,
|
||||
from: &Location,
|
||||
to: &Location,
|
||||
context: &XcmContext,
|
||||
) -> result::Result<xcm_executor::Assets, XcmError> {
|
||||
) -> result::Result<AssetsInHolding, XcmError> {
|
||||
FungibleTransferAdapter::<Fungible, Matcher, AccountIdConverter, AccountId>::internal_transfer_asset(
|
||||
what, from, to, context
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user