mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 22:41: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
@@ -19,16 +19,16 @@
|
||||
use crate::{generic, mock::*, *};
|
||||
use codec::Decode;
|
||||
use frame_support::{
|
||||
derive_impl, match_types, parameter_types,
|
||||
traits::{Everything, OriginTrait},
|
||||
derive_impl, parameter_types,
|
||||
traits::{Contains, Everything, OriginTrait},
|
||||
weights::Weight,
|
||||
};
|
||||
use sp_core::H256;
|
||||
use sp_runtime::traits::{BlakeTwo256, IdentityLookup, TrailingZeroInput};
|
||||
use xcm_builder::{
|
||||
test_utils::{
|
||||
Assets, TestAssetExchanger, TestAssetLocker, TestAssetTrap, TestSubscriptionService,
|
||||
TestUniversalAliases,
|
||||
AssetsInHolding, TestAssetExchanger, TestAssetLocker, TestAssetTrap,
|
||||
TestSubscriptionService, TestUniversalAliases,
|
||||
},
|
||||
AliasForeignAccountId32, AllowUnpaidExecutionFrom,
|
||||
};
|
||||
@@ -81,19 +81,15 @@ impl frame_system::Config for Test {
|
||||
/// The benchmarks in this pallet should never need an asset transactor to begin with.
|
||||
pub struct NoAssetTransactor;
|
||||
impl xcm_executor::traits::TransactAsset for NoAssetTransactor {
|
||||
fn deposit_asset(
|
||||
_: &MultiAsset,
|
||||
_: &MultiLocation,
|
||||
_: Option<&XcmContext>,
|
||||
) -> Result<(), XcmError> {
|
||||
fn deposit_asset(_: &Asset, _: &Location, _: Option<&XcmContext>) -> Result<(), XcmError> {
|
||||
unreachable!();
|
||||
}
|
||||
|
||||
fn withdraw_asset(
|
||||
_: &MultiAsset,
|
||||
_: &MultiLocation,
|
||||
_: &Asset,
|
||||
_: &Location,
|
||||
_: Option<&XcmContext>,
|
||||
) -> Result<Assets, XcmError> {
|
||||
) -> Result<AssetsInHolding, XcmError> {
|
||||
unreachable!();
|
||||
}
|
||||
}
|
||||
@@ -103,10 +99,11 @@ parameter_types! {
|
||||
pub const MaxAssetsIntoHolding: u32 = 64;
|
||||
}
|
||||
|
||||
match_types! {
|
||||
pub type OnlyParachains: impl Contains<MultiLocation> = {
|
||||
MultiLocation { parents: 0, interior: X1(Parachain(_)) }
|
||||
};
|
||||
pub struct OnlyParachains;
|
||||
impl Contains<Location> for OnlyParachains {
|
||||
fn contains(location: &Location) -> bool {
|
||||
matches!(location.unpack(), (0, [Parachain(_)]))
|
||||
}
|
||||
}
|
||||
|
||||
type Aliasers = AliasForeignAccountId32<OnlyParachains>;
|
||||
@@ -153,13 +150,13 @@ impl crate::Config for Test {
|
||||
type XcmConfig = XcmConfig;
|
||||
type AccountIdConverter = AccountIdConverter;
|
||||
type DeliveryHelper = ();
|
||||
fn valid_destination() -> Result<MultiLocation, BenchmarkError> {
|
||||
let valid_destination: MultiLocation =
|
||||
fn valid_destination() -> Result<Location, BenchmarkError> {
|
||||
let valid_destination: Location =
|
||||
Junction::AccountId32 { network: None, id: [0u8; 32] }.into();
|
||||
|
||||
Ok(valid_destination)
|
||||
}
|
||||
fn worst_case_holding(depositable_count: u32) -> MultiAssets {
|
||||
fn worst_case_holding(depositable_count: u32) -> Assets {
|
||||
crate::mock_worst_case_holding(
|
||||
depositable_count,
|
||||
<XcmConfig as xcm_executor::Config>::MaxAssetsIntoHolding::get(),
|
||||
@@ -172,48 +169,47 @@ impl generic::Config for Test {
|
||||
type RuntimeCall = RuntimeCall;
|
||||
|
||||
fn worst_case_response() -> (u64, Response) {
|
||||
let assets: MultiAssets = (Concrete(Here.into()), 100).into();
|
||||
let assets: Assets = (AssetId(Here.into()), 100).into();
|
||||
(0, Response::Assets(assets))
|
||||
}
|
||||
|
||||
fn worst_case_asset_exchange() -> Result<(MultiAssets, MultiAssets), BenchmarkError> {
|
||||
fn worst_case_asset_exchange() -> Result<(Assets, Assets), BenchmarkError> {
|
||||
Ok(Default::default())
|
||||
}
|
||||
|
||||
fn universal_alias() -> Result<(MultiLocation, Junction), BenchmarkError> {
|
||||
fn universal_alias() -> Result<(Location, Junction), BenchmarkError> {
|
||||
Ok((Here.into(), GlobalConsensus(ByGenesis([0; 32]))))
|
||||
}
|
||||
|
||||
fn transact_origin_and_runtime_call(
|
||||
) -> Result<(MultiLocation, <Self as generic::Config>::RuntimeCall), BenchmarkError> {
|
||||
) -> Result<(Location, <Self as generic::Config>::RuntimeCall), BenchmarkError> {
|
||||
Ok((Default::default(), frame_system::Call::remark_with_event { remark: vec![] }.into()))
|
||||
}
|
||||
|
||||
fn subscribe_origin() -> Result<MultiLocation, BenchmarkError> {
|
||||
fn subscribe_origin() -> Result<Location, BenchmarkError> {
|
||||
Ok(Default::default())
|
||||
}
|
||||
|
||||
fn claimable_asset() -> Result<(MultiLocation, MultiLocation, MultiAssets), BenchmarkError> {
|
||||
let assets: MultiAssets = (Concrete(Here.into()), 100).into();
|
||||
let ticket = MultiLocation { parents: 0, interior: X1(GeneralIndex(0)) };
|
||||
fn claimable_asset() -> Result<(Location, Location, Assets), BenchmarkError> {
|
||||
let assets: Assets = (AssetId(Here.into()), 100).into();
|
||||
let ticket = Location { parents: 0, interior: [GeneralIndex(0)].into() };
|
||||
Ok((Default::default(), ticket, assets))
|
||||
}
|
||||
|
||||
fn unlockable_asset() -> Result<(MultiLocation, MultiLocation, MultiAsset), BenchmarkError> {
|
||||
let assets: MultiAsset = (Concrete(Here.into()), 100).into();
|
||||
fn unlockable_asset() -> Result<(Location, Location, Asset), BenchmarkError> {
|
||||
let assets: Asset = (AssetId(Here.into()), 100).into();
|
||||
Ok((Default::default(), account_id_junction::<Test>(1).into(), assets))
|
||||
}
|
||||
|
||||
fn export_message_origin_and_destination(
|
||||
) -> Result<(MultiLocation, NetworkId, InteriorMultiLocation), BenchmarkError> {
|
||||
) -> Result<(Location, NetworkId, InteriorLocation), BenchmarkError> {
|
||||
// No MessageExporter in tests
|
||||
Err(BenchmarkError::Skip)
|
||||
}
|
||||
|
||||
fn alias_origin() -> Result<(MultiLocation, MultiLocation), BenchmarkError> {
|
||||
let origin: MultiLocation =
|
||||
(Parachain(1), AccountId32 { network: None, id: [0; 32] }).into();
|
||||
let target: MultiLocation = AccountId32 { network: None, id: [0; 32] }.into();
|
||||
fn alias_origin() -> Result<(Location, Location), BenchmarkError> {
|
||||
let origin: Location = (Parachain(1), AccountId32 { network: None, id: [0; 32] }).into();
|
||||
let target: Location = AccountId32 { network: None, id: [0; 32] }.into();
|
||||
Ok((origin, target))
|
||||
}
|
||||
}
|
||||
@@ -233,9 +229,9 @@ where
|
||||
<RuntimeOrigin as OriginTrait>::AccountId: Decode,
|
||||
{
|
||||
fn convert_origin(
|
||||
_origin: impl Into<MultiLocation>,
|
||||
_origin: impl Into<Location>,
|
||||
_kind: OriginKind,
|
||||
) -> Result<RuntimeOrigin, MultiLocation> {
|
||||
) -> Result<RuntimeOrigin, Location> {
|
||||
Ok(RuntimeOrigin::signed(
|
||||
<RuntimeOrigin as OriginTrait>::AccountId::decode(&mut TrailingZeroInput::zeroes())
|
||||
.expect("infinite length input; no invalid inputs for type; qed"),
|
||||
|
||||
Reference in New Issue
Block a user