mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 23:51:01 +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,7 +18,7 @@ use super::*;
|
||||
|
||||
#[test]
|
||||
fn pallet_query_should_work() {
|
||||
AllowUnpaidFrom::set(vec![X1(Parachain(1)).into()]);
|
||||
AllowUnpaidFrom::set(vec![[Parachain(1)].into()]);
|
||||
// They want to transfer 100 of our native asset from sovereign account of parachain #1 into #2
|
||||
// and let them know to hand it to account #3.
|
||||
let message = Xcm(vec![QueryPallet {
|
||||
@@ -29,14 +29,15 @@ fn pallet_query_should_work() {
|
||||
max_weight: Weight::from_parts(50, 50),
|
||||
},
|
||||
}]);
|
||||
let hash = fake_message_hash(&message);
|
||||
let r = XcmExecutor::<TestConfig>::execute_xcm(
|
||||
let mut hash = fake_message_hash(&message);
|
||||
let r = XcmExecutor::<TestConfig>::prepare_and_execute(
|
||||
Parachain(1),
|
||||
message,
|
||||
hash,
|
||||
&mut hash,
|
||||
Weight::from_parts(50, 50),
|
||||
Weight::zero(),
|
||||
);
|
||||
assert_eq!(r, Outcome::Complete(Weight::from_parts(10, 10)));
|
||||
assert_eq!(r, Outcome::Complete { used: Weight::from_parts(10, 10) });
|
||||
|
||||
let expected_msg = Xcm::<()>(vec![QueryResponse {
|
||||
query_id: 1,
|
||||
@@ -50,7 +51,7 @@ fn pallet_query_should_work() {
|
||||
|
||||
#[test]
|
||||
fn pallet_query_with_results_should_work() {
|
||||
AllowUnpaidFrom::set(vec![X1(Parachain(1)).into()]);
|
||||
AllowUnpaidFrom::set(vec![[Parachain(1)].into()]);
|
||||
// They want to transfer 100 of our native asset from sovereign account of parachain #1 into #2
|
||||
// and let them know to hand it to account #3.
|
||||
let message = Xcm(vec![QueryPallet {
|
||||
@@ -61,14 +62,15 @@ fn pallet_query_with_results_should_work() {
|
||||
max_weight: Weight::from_parts(50, 50),
|
||||
},
|
||||
}]);
|
||||
let hash = fake_message_hash(&message);
|
||||
let r = XcmExecutor::<TestConfig>::execute_xcm(
|
||||
let mut hash = fake_message_hash(&message);
|
||||
let r = XcmExecutor::<TestConfig>::prepare_and_execute(
|
||||
Parachain(1),
|
||||
message,
|
||||
hash,
|
||||
&mut hash,
|
||||
Weight::from_parts(50, 50),
|
||||
Weight::zero(),
|
||||
);
|
||||
assert_eq!(r, Outcome::Complete(Weight::from_parts(10, 10)));
|
||||
assert_eq!(r, Outcome::Complete { used: Weight::from_parts(10, 10) });
|
||||
|
||||
let expected_msg = Xcm::<()>(vec![QueryResponse {
|
||||
query_id: 1,
|
||||
@@ -106,15 +108,27 @@ fn prepaid_result_of_query_should_get_free_execution() {
|
||||
max_weight: Weight::from_parts(10, 10),
|
||||
querier: Some(Here.into()),
|
||||
}]);
|
||||
let hash = fake_message_hash(&message);
|
||||
let mut hash = fake_message_hash(&message);
|
||||
let weight_limit = Weight::from_parts(10, 10);
|
||||
|
||||
// First time the response gets through since we're expecting it...
|
||||
let r = XcmExecutor::<TestConfig>::execute_xcm(Parent, message.clone(), hash, weight_limit);
|
||||
assert_eq!(r, Outcome::Complete(Weight::from_parts(10, 10)));
|
||||
let r = XcmExecutor::<TestConfig>::prepare_and_execute(
|
||||
Parent,
|
||||
message.clone(),
|
||||
&mut hash,
|
||||
weight_limit,
|
||||
Weight::zero(),
|
||||
);
|
||||
assert_eq!(r, Outcome::Complete { used: Weight::from_parts(10, 10) });
|
||||
assert_eq!(response(query_id).unwrap(), the_response);
|
||||
|
||||
// Second time it doesn't, since we're not.
|
||||
let r = XcmExecutor::<TestConfig>::execute_xcm(Parent, message.clone(), hash, weight_limit);
|
||||
assert_eq!(r, Outcome::Error(XcmError::Barrier));
|
||||
let r = XcmExecutor::<TestConfig>::prepare_and_execute(
|
||||
Parent,
|
||||
message.clone(),
|
||||
&mut hash,
|
||||
weight_limit,
|
||||
Weight::zero(),
|
||||
);
|
||||
assert_eq!(r, Outcome::Error { error: XcmError::Barrier });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user