Skip to content

Commit

Permalink
Serialize/Deserialize trait implemented in no-std for XCM assets (par…
Browse files Browse the repository at this point in the history
…itytech#3057)

Continues the work of paritytech/polkadot#7312.
`MultiLocation` was modified to implement serialize in no-std in that
PR, but not the assets types.
This PR does the same for assets, and this also allows to inject them in
pallets that require them in genesis.
# Conflicts:
#	polkadot/xcm/src/v4/asset.rs
  • Loading branch information
fgamundi committed Feb 23, 2024
1 parent 2d54310 commit 9bff304
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 16 deletions.
121 changes: 105 additions & 16 deletions polkadot/xcm/src/v3/multiasset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,20 @@ use scale_info::TypeInfo;

/// A general identifier for an instance of a non-fungible asset class.
#[derive(
Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, TypeInfo, MaxEncodedLen,
Copy,
Clone,
Eq,
PartialEq,
Ord,
PartialOrd,
Encode,
Decode,
Debug,
TypeInfo,
MaxEncodedLen,
serde::Serialize,
serde::Deserialize,
)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum AssetInstance {
Expand Down Expand Up @@ -242,8 +253,19 @@ impl TryFrom<AssetInstance> for u128 {

/// Classification of whether an asset is fungible or not, along with a mandatory amount or
/// instance.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Encode, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[derive(
Clone,
Eq,
PartialEq,
Ord,
PartialOrd,
Debug,
Encode,
TypeInfo,
MaxEncodedLen,
serde::Serialize,
serde::Deserialize,
)]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum Fungibility {
Expand Down Expand Up @@ -312,9 +334,20 @@ impl TryFrom<OldFungibility> for Fungibility {

/// Classification of whether an asset is fungible or not.
#[derive(
Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Encode, Decode, TypeInfo, MaxEncodedLen,
Copy,
Clone,
Eq,
PartialEq,
Ord,
PartialOrd,
Debug,
Encode,
Decode,
TypeInfo,
MaxEncodedLen,
serde::Serialize,
serde::Deserialize,
)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum WildFungibility {
Expand All @@ -337,9 +370,20 @@ impl TryFrom<OldWildFungibility> for WildFungibility {

/// Classification of an asset being concrete or abstract.
#[derive(
Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Encode, Decode, TypeInfo, MaxEncodedLen,
Copy,
Clone,
Eq,
PartialEq,
Ord,
PartialOrd,
Debug,
Encode,
Decode,
TypeInfo,
MaxEncodedLen,
serde::Serialize,
serde::Deserialize,
)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum AssetId {
Expand Down Expand Up @@ -414,8 +458,18 @@ impl AssetId {
}

/// Either an amount of a single fungible asset, or a single well-identified non-fungible asset.
#[derive(Clone, Eq, PartialEq, Debug, Encode, Decode, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[derive(
Clone,
Eq,
PartialEq,
Debug,
Encode,
Decode,
TypeInfo,
MaxEncodedLen,
serde::Serialize,
serde::Deserialize,
)]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub struct MultiAsset {
Expand Down Expand Up @@ -513,8 +567,19 @@ impl TryFrom<OldMultiAsset> for MultiAsset {
/// - It may contain no items of duplicate asset class;
/// - All items must be ordered;
/// - The number of items should grow no larger than `MAX_ITEMS_IN_MULTIASSETS`.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Encode, TypeInfo, Default)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[derive(
Clone,
Eq,
PartialEq,
Ord,
PartialOrd,
Debug,
Encode,
TypeInfo,
Default,
serde::Serialize,
serde::Deserialize,
)]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub struct MultiAssets(Vec<MultiAsset>);
Expand Down Expand Up @@ -714,8 +779,20 @@ impl MultiAssets {
}

/// A wildcard representing a set of assets.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Encode, Decode, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[derive(
Clone,
Eq,
PartialEq,
Ord,
PartialOrd,
Debug,
Encode,
Decode,
TypeInfo,
MaxEncodedLen,
serde::Serialize,
serde::Deserialize,
)]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum WildMultiAsset {
Expand Down Expand Up @@ -828,8 +905,20 @@ impl<A: Into<AssetId>, B: Into<WildFungibility>> From<(A, B)> for WildMultiAsset
}

/// `MultiAsset` collection, defined either by a number of `MultiAssets` or a single wildcard.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Encode, Decode, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
#[derive(
Clone,
Eq,
PartialEq,
Ord,
PartialOrd,
Debug,
Encode,
Decode,
TypeInfo,
MaxEncodedLen,
serde::Serialize,
serde::Deserialize,
)]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
#[scale_info(replace_segment("staging_xcm", "xcm"))]
pub enum MultiAssetFilter {
Expand Down
13 changes: 13 additions & 0 deletions prdoc/pr_3057.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: Serialize/Deserialize trait implemented in no-std for XCM assets types

doc:
- audience: Runtime Dev
description: |
Serialize/Deserialize trait implemented in no-std for XCM v3 and v4
assets types

crates:
- name: staging-xcm

0 comments on commit 9bff304

Please sign in to comment.