mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 19:31:02 +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>
82 lines
2.8 KiB
Rust
82 lines
2.8 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/>.
|
|
|
|
//! Test the methods generated by the Builder derive macro.
|
|
//! Tests directly on the actual Xcm struct and Instruction enum.
|
|
|
|
use xcm::latest::prelude::*;
|
|
|
|
#[test]
|
|
fn builder_pattern_works() {
|
|
let asset: Asset = (Here, 100u128).into();
|
|
let beneficiary: Location = AccountId32 { id: [0u8; 32], network: None }.into();
|
|
let message: Xcm<()> = Xcm::builder()
|
|
.receive_teleported_asset(asset.clone().into())
|
|
.buy_execution(asset.clone(), Unlimited)
|
|
.deposit_asset(asset.clone().into(), beneficiary.clone())
|
|
.build();
|
|
assert_eq!(
|
|
message,
|
|
Xcm(vec![
|
|
ReceiveTeleportedAsset(asset.clone().into()),
|
|
BuyExecution { fees: asset.clone(), weight_limit: Unlimited },
|
|
DepositAsset { assets: asset.into(), beneficiary },
|
|
])
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn default_builder_requires_buy_execution() {
|
|
let asset: Asset = (Here, 100u128).into();
|
|
let beneficiary: Location = AccountId32 { id: [0u8; 32], network: None }.into();
|
|
// This is invalid, since it doesn't pay for fees.
|
|
// This is enforced by the runtime, because the build() method doesn't exist
|
|
// on the resulting type.
|
|
// let message: Xcm<()> = Xcm::builder()
|
|
// .withdraw_asset(asset.clone().into())
|
|
// .deposit_asset(asset.into(), beneficiary)
|
|
// .build();
|
|
|
|
// To be able to do that, we need to use the explicitly unpaid variant
|
|
let message: Xcm<()> = Xcm::builder_unpaid()
|
|
.unpaid_execution(Unlimited, None)
|
|
.withdraw_asset(asset.clone().into())
|
|
.deposit_asset(asset.clone().into(), beneficiary.clone())
|
|
.build(); // This works
|
|
assert_eq!(
|
|
message,
|
|
Xcm(vec![
|
|
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
|
|
WithdrawAsset(asset.clone().into()),
|
|
DepositAsset { assets: asset.clone().into(), beneficiary: beneficiary.clone() },
|
|
])
|
|
);
|
|
|
|
// The other option doesn't have any limits whatsoever, so it should
|
|
// only be used when you really know what you're doing.
|
|
let message: Xcm<()> = Xcm::builder_unsafe()
|
|
.withdraw_asset(asset.clone().into())
|
|
.deposit_asset(asset.clone().into(), beneficiary.clone())
|
|
.build();
|
|
assert_eq!(
|
|
message,
|
|
Xcm(vec![
|
|
WithdrawAsset(asset.clone().into()),
|
|
DepositAsset { assets: asset.clone().into(), beneficiary },
|
|
])
|
|
);
|
|
}
|