mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-23 17:45:46 +00:00
feat(xcm): support json schema (for CosmWasm VM support) (#1454)
# Description - What does this PR do? Allows to generate JSON schema for subset of XCM in std builds - Why are these changes needed? To support XCM messages in CosmWasm contracts which require Schemars to generate contract clients - How were these changes implemented and what do they affect? We will use schema feature flag to build XCM pallet with JSON schema enabled # Checklist - [x] My PR includes a detailed description as outlined in the "Description" section above - [x] My PR follows the [labeling requirements](CONTRIBUTING.md#Process) of this project (at minimum one label for `T` required) - [x] I have made corresponding changes to the documentation (if applicable) - [x] I have added tests that prove my fix is effective or that my feature works (if applicable) - [x] If this PR alters any external APIs or interfaces used by Polkadot, the corresponding Polkadot PR is ready as well as the corresponding Cumulus PR (optional)
This commit is contained in:
@@ -25,6 +25,7 @@ use parity_scale_codec::{Decode, DecodeLimit, Encode};
|
||||
#[codec(decode_bound())]
|
||||
#[scale_info(bounds(), skip_type_params(T))]
|
||||
#[scale_info(replace_segment("staging_xcm", "xcm"))]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub struct DoubleEncoded<T> {
|
||||
encoded: Vec<u8>,
|
||||
#[codec(skip)]
|
||||
|
||||
@@ -82,6 +82,7 @@ pub use traits::{Error, ExecuteXcm, GetWeight, Outcome, Result, SendError, SendR
|
||||
/// Basically just the XCM (more general) version of `ParachainDispatchOrigin`.
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Encode, Decode, Debug, TypeInfo)]
|
||||
#[scale_info(replace_segment("staging_xcm", "xcm"))]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub enum OriginKind {
|
||||
/// Origin should just be the native dispatch origin representation for the sender in the
|
||||
/// local runtime framework. For Cumulus/Frame chains this is the `Parachain` or `Relay` origin
|
||||
|
||||
@@ -49,6 +49,7 @@ use serde::{Deserialize, Serialize};
|
||||
Serialize,
|
||||
Deserialize,
|
||||
)]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
#[scale_info(replace_segment("staging_xcm", "xcm"))]
|
||||
pub enum NetworkId {
|
||||
/// Network specified by the first 32 bytes of its genesis block.
|
||||
@@ -119,6 +120,7 @@ impl TryFrom<OldNetworkId> for NetworkId {
|
||||
Serialize,
|
||||
Deserialize,
|
||||
)]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
#[scale_info(replace_segment("staging_xcm", "xcm"))]
|
||||
pub enum BodyId {
|
||||
/// The only body in its context.
|
||||
@@ -190,6 +192,7 @@ impl TryFrom<OldBodyId> for BodyId {
|
||||
Serialize,
|
||||
Deserialize,
|
||||
)]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
#[scale_info(replace_segment("staging_xcm", "xcm"))]
|
||||
pub enum BodyPart {
|
||||
/// The body's declaration, under whatever means it decides.
|
||||
@@ -266,6 +269,7 @@ impl TryFrom<OldBodyPart> for BodyPart {
|
||||
Serialize,
|
||||
Deserialize,
|
||||
)]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
#[scale_info(replace_segment("staging_xcm", "xcm"))]
|
||||
pub enum Junction {
|
||||
/// An indexed parachain belonging to and operated by the context.
|
||||
|
||||
@@ -44,6 +44,7 @@ pub(crate) const MAX_JUNCTIONS: usize = 8;
|
||||
serde::Serialize,
|
||||
serde::Deserialize,
|
||||
)]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
#[scale_info(replace_segment("staging_xcm", "xcm"))]
|
||||
pub enum Junctions {
|
||||
/// The interpreting consensus system.
|
||||
|
||||
@@ -69,6 +69,7 @@ pub type QueryId = u64;
|
||||
#[codec(encode_bound())]
|
||||
#[scale_info(bounds(), skip_type_params(Call))]
|
||||
#[scale_info(replace_segment("staging_xcm", "xcm"))]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub struct Xcm<Call>(pub Vec<Instruction<Call>>);
|
||||
|
||||
/// The maximal number of instructions in an XCM before decoding fails.
|
||||
@@ -232,15 +233,19 @@ pub mod prelude {
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub MaxPalletNameLen: u32 = 48;
|
||||
/// Maximum size of the encoded error code coming from a `Dispatch` result, used for
|
||||
/// `MaybeErrorCode`. This is not (yet) enforced, so it's just an indication of expectation.
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub MaxDispatchErrorLen: u32 = 128;
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub MaxPalletsInfo: u32 = 64;
|
||||
}
|
||||
|
||||
#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
|
||||
#[scale_info(replace_segment("staging_xcm", "xcm"))]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub struct PalletInfo {
|
||||
#[codec(compact)]
|
||||
pub index: u32,
|
||||
@@ -272,6 +277,7 @@ impl PalletInfo {
|
||||
|
||||
#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
|
||||
#[scale_info(replace_segment("staging_xcm", "xcm"))]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub enum MaybeErrorCode {
|
||||
Success,
|
||||
Error(BoundedVec<u8, MaxDispatchErrorLen>),
|
||||
@@ -296,6 +302,7 @@ impl Default for MaybeErrorCode {
|
||||
/// Response data to a query.
|
||||
#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
|
||||
#[scale_info(replace_segment("staging_xcm", "xcm"))]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub enum Response {
|
||||
/// No response. Serves as a neutral default.
|
||||
Null,
|
||||
@@ -320,6 +327,7 @@ impl Default for Response {
|
||||
/// Information regarding the composition of a query response.
|
||||
#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug, TypeInfo)]
|
||||
#[scale_info(replace_segment("staging_xcm", "xcm"))]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub struct QueryResponseInfo {
|
||||
/// The destination to which the query response message should be send.
|
||||
pub destination: MultiLocation,
|
||||
@@ -333,6 +341,7 @@ pub struct QueryResponseInfo {
|
||||
/// An optional weight limit.
|
||||
#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug, TypeInfo)]
|
||||
#[scale_info(replace_segment("staging_xcm", "xcm"))]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub enum WeightLimit {
|
||||
/// No weight limit imposed.
|
||||
Unlimited,
|
||||
@@ -417,6 +426,7 @@ impl XcmContext {
|
||||
#[codec(decode_bound())]
|
||||
#[scale_info(bounds(), skip_type_params(Call))]
|
||||
#[scale_info(replace_segment("staging_xcm", "xcm"))]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub enum Instruction<Call> {
|
||||
/// Withdraw asset(s) (`assets`) from the ownership of `origin` and place them into the Holding
|
||||
/// Register.
|
||||
|
||||
@@ -47,6 +47,7 @@ use scale_info::TypeInfo;
|
||||
Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, TypeInfo, MaxEncodedLen,
|
||||
)]
|
||||
#[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 {
|
||||
/// Undefined - used if the non-fungible asset class has only one instance.
|
||||
@@ -243,6 +244,7 @@ impl TryFrom<AssetInstance> for u128 {
|
||||
/// instance.
|
||||
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Encode, TypeInfo, MaxEncodedLen)]
|
||||
#[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 Fungibility {
|
||||
/// A fungible asset; we record a number of units, as a `u128` in the inner item.
|
||||
@@ -313,6 +315,7 @@ impl TryFrom<OldFungibility> for Fungibility {
|
||||
Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Encode, Decode, TypeInfo, MaxEncodedLen,
|
||||
)]
|
||||
#[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 {
|
||||
/// The asset is fungible.
|
||||
@@ -337,6 +340,7 @@ impl TryFrom<OldWildFungibility> for WildFungibility {
|
||||
Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Encode, Decode, TypeInfo, MaxEncodedLen,
|
||||
)]
|
||||
#[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 {
|
||||
/// A specific location identifying an asset.
|
||||
@@ -412,6 +416,7 @@ 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))]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
#[scale_info(replace_segment("staging_xcm", "xcm"))]
|
||||
pub struct MultiAsset {
|
||||
/// The overall asset identity (aka *class*, in the case of a non-fungible).
|
||||
@@ -510,6 +515,7 @@ impl TryFrom<OldMultiAsset> for MultiAsset {
|
||||
/// - 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))]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
#[scale_info(replace_segment("staging_xcm", "xcm"))]
|
||||
pub struct MultiAssets(Vec<MultiAsset>);
|
||||
|
||||
@@ -710,6 +716,7 @@ 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))]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
#[scale_info(replace_segment("staging_xcm", "xcm"))]
|
||||
pub enum WildMultiAsset {
|
||||
/// All assets in Holding.
|
||||
@@ -823,6 +830,7 @@ 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))]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
#[scale_info(replace_segment("staging_xcm", "xcm"))]
|
||||
pub enum MultiAssetFilter {
|
||||
/// Specify the filter as being everything contained by the given `MultiAssets` inner.
|
||||
|
||||
@@ -66,6 +66,7 @@ use scale_info::TypeInfo;
|
||||
serde::Serialize,
|
||||
serde::Deserialize,
|
||||
)]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub struct MultiLocation {
|
||||
/// The number of parent junctions at the beginning of this `MultiLocation`.
|
||||
pub parents: u8,
|
||||
|
||||
@@ -30,6 +30,7 @@ use super::*;
|
||||
/// they will retain the same index over time.
|
||||
#[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, Debug, TypeInfo)]
|
||||
#[scale_info(replace_segment("staging_xcm", "xcm"))]
|
||||
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
|
||||
pub enum Error {
|
||||
// Errors that happen due to instructions being executed. These alone are defined in the
|
||||
// XCM specification.
|
||||
|
||||
Reference in New Issue
Block a user