mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-15 14:55:42 +00:00
8428f678fe
# 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>
90 lines
3.0 KiB
Rust
90 lines
3.0 KiB
Rust
// Copyright (C) Parity Technologies (UK) Ltd.
|
|
// This file is part of Polkadot.
|
|
|
|
// Polkadot is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// Polkadot is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
use crate::AssetsInHolding;
|
|
use core::marker::PhantomData;
|
|
use frame_support::traits::Contains;
|
|
use xcm::latest::{Assets, Location, Weight, XcmContext};
|
|
|
|
/// Define a handler for when some non-empty `AssetsInHolding` value should be dropped.
|
|
pub trait DropAssets {
|
|
/// Handler for receiving dropped assets. Returns the weight consumed by this operation.
|
|
fn drop_assets(origin: &Location, assets: AssetsInHolding, context: &XcmContext) -> Weight;
|
|
}
|
|
impl DropAssets for () {
|
|
fn drop_assets(_origin: &Location, _assets: AssetsInHolding, _context: &XcmContext) -> Weight {
|
|
Weight::zero()
|
|
}
|
|
}
|
|
|
|
/// Morph a given `DropAssets` implementation into one which can filter based on assets. This can
|
|
/// be used to ensure that `AssetsInHolding` values which hold no value are ignored.
|
|
pub struct FilterAssets<D, A>(PhantomData<(D, A)>);
|
|
|
|
impl<D: DropAssets, A: Contains<AssetsInHolding>> DropAssets for FilterAssets<D, A> {
|
|
fn drop_assets(origin: &Location, assets: AssetsInHolding, context: &XcmContext) -> Weight {
|
|
if A::contains(&assets) {
|
|
D::drop_assets(origin, assets, context)
|
|
} else {
|
|
Weight::zero()
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Morph a given `DropAssets` implementation into one which can filter based on origin. This can
|
|
/// be used to ban origins which don't have proper protections/policies against misuse of the
|
|
/// asset trap facility don't get to use it.
|
|
pub struct FilterOrigin<D, O>(PhantomData<(D, O)>);
|
|
|
|
impl<D: DropAssets, O: Contains<Location>> DropAssets for FilterOrigin<D, O> {
|
|
fn drop_assets(origin: &Location, assets: AssetsInHolding, context: &XcmContext) -> Weight {
|
|
if O::contains(origin) {
|
|
D::drop_assets(origin, assets, context)
|
|
} else {
|
|
Weight::zero()
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Define any handlers for the `AssetClaim` instruction.
|
|
pub trait ClaimAssets {
|
|
/// Claim any assets available to `origin` and return them in a single `Assets` value, together
|
|
/// with the weight used by this operation.
|
|
fn claim_assets(
|
|
origin: &Location,
|
|
ticket: &Location,
|
|
what: &Assets,
|
|
context: &XcmContext,
|
|
) -> bool;
|
|
}
|
|
|
|
#[impl_trait_for_tuples::impl_for_tuples(30)]
|
|
impl ClaimAssets for Tuple {
|
|
fn claim_assets(
|
|
origin: &Location,
|
|
ticket: &Location,
|
|
what: &Assets,
|
|
context: &XcmContext,
|
|
) -> bool {
|
|
for_tuples!( #(
|
|
if Tuple::claim_assets(origin, ticket, what, context) {
|
|
return true;
|
|
}
|
|
)* );
|
|
false
|
|
}
|
|
}
|