Companion for paritytech/substrate#11631 (#5671)

* Companion for paritytech/substrate#11631

* Fixes

* Update sp-runtime

* Fixes

* update lockfile for {"substrate"}

* remove unused

Co-authored-by: parity-processbot <>
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Keith Yeung
2022-06-16 19:36:01 +02:00
committed by GitHub
parent 2dfc7cec47
commit 2c85668512
9 changed files with 216 additions and 199 deletions
+9 -9
View File
@@ -16,17 +16,17 @@
//! Support data structures for `MultiLocation`, primarily the `Junction` datatype.
use alloc::vec::Vec;
use parity_scale_codec::{Decode, Encode};
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_runtime::{traits::ConstU32, WeakBoundedVec};
/// A global identifier of an account-bearing consensus system.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, TypeInfo)]
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
pub enum NetworkId {
/// Unidentified/any.
Any,
/// Some named network.
Named(Vec<u8>),
Named(WeakBoundedVec<u8, ConstU32<32>>),
/// The Polkadot Relay chain
Polkadot,
/// Kusama.
@@ -34,12 +34,12 @@ pub enum NetworkId {
}
/// An identifier of a pluralistic body.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, TypeInfo)]
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
pub enum BodyId {
/// The only body in its context.
Unit,
/// A named body.
Named(Vec<u8>),
Named(WeakBoundedVec<u8, ConstU32<32>>),
/// An indexed body.
Index(#[codec(compact)] u32),
/// The unambiguous executive body (for Polkadot, this would be the Polkadot council).
@@ -55,7 +55,7 @@ pub enum BodyId {
}
/// A part of a pluralistic body.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, TypeInfo)]
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
pub enum BodyPart {
/// The body's declaration, under whatever means it decides.
Voice,
@@ -102,7 +102,7 @@ impl BodyPart {
/// A single item in a path to describe the relative location of a consensus system.
///
/// Each item assumes a pre-existing location as its context and is defined in terms of it.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, TypeInfo)]
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
pub enum Junction {
/// The consensus system of which the context is a member and state-wise super-set.
///
@@ -147,7 +147,7 @@ pub enum Junction {
/// Usage will vary widely owing to its generality.
///
/// NOTE: Try to avoid using this and instead use a more specific item.
GeneralKey(Vec<u8>),
GeneralKey(WeakBoundedVec<u8, ConstU32<32>>),
/// The unambiguous child.
///
/// Not currently used except as a fallback when deriving ancestry.
+4 -4
View File
@@ -18,14 +18,14 @@
use super::{BodyId, BodyPart, Junctions, MultiLocation, NetworkId};
use crate::v0::Junction as Junction0;
use alloc::vec::Vec;
use parity_scale_codec::{self, Decode, Encode};
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_runtime::{traits::ConstU32, WeakBoundedVec};
/// A single item in a path to describe the relative location of a consensus system.
///
/// Each item assumes a pre-existing location as its context and is defined in terms of it.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, TypeInfo)]
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
pub enum Junction {
/// An indexed parachain belonging to and operated by the context.
///
@@ -65,7 +65,7 @@ pub enum Junction {
/// Usage will vary widely owing to its generality.
///
/// NOTE: Try to avoid using this and instead use a more specific item.
GeneralKey(Vec<u8>),
GeneralKey(WeakBoundedVec<u8, ConstU32<32>>),
/// The unambiguous child.
///
/// Not currently used except as a fallback when deriving ancestry.
+8 -6
View File
@@ -18,7 +18,7 @@
use super::Junction;
use core::{mem, result};
use parity_scale_codec::{Decode, Encode};
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
/// A relative path between state-bearing consensus systems.
@@ -47,7 +47,7 @@ use scale_info::TypeInfo;
/// that a value is strictly an interior location, in those cases, `Junctions` may be used.
///
/// The `MultiLocation` value of `Null` simply refers to the interpreting consensus system.
#[derive(Clone, Decode, Encode, Eq, PartialEq, Ord, PartialOrd, Debug, TypeInfo)]
#[derive(Clone, Decode, Encode, Eq, PartialEq, Ord, PartialOrd, Debug, TypeInfo, MaxEncodedLen)]
pub struct MultiLocation {
/// The number of parent junctions at the beginning of this `MultiLocation`.
pub parents: u8,
@@ -425,7 +425,7 @@ const MAX_JUNCTIONS: usize = 8;
///
/// Parent junctions cannot be constructed with this type. Refer to `MultiLocation` for
/// instructions on constructing parent junctions.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, TypeInfo)]
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, TypeInfo, MaxEncodedLen)]
pub enum Junctions {
/// The interpreting consensus system.
Here,
@@ -1011,7 +1011,6 @@ mod tests {
#[test]
fn conversion_from_other_types_works() {
use crate::v0;
fn takes_multilocation<Arg: Into<MultiLocation>>(_arg: Arg) {}
takes_multilocation(Parent);
@@ -1042,10 +1041,13 @@ mod tests {
v0::MultiLocation::X3(
v0::Junction::Parent,
v0::Junction::Parent,
v0::Junction::GeneralKey(b"foo".to_vec()),
v0::Junction::GeneralKey(b"foo".to_vec().try_into().unwrap()),
)
.try_into(),
Ok(MultiLocation { parents: 2, interior: X1(GeneralKey(b"foo".to_vec())) }),
Ok(MultiLocation {
parents: 2,
interior: X1(GeneralKey(b"foo".to_vec().try_into().unwrap()))
}),
);
}
}