[XCM] Make NetworkId and Junction versioned (#7376)

* [XCM] Make NetworkId and Junction versioned

* Fixes

---------

Co-authored-by: parity-processbot <>
This commit is contained in:
Keith Yeung
2023-06-15 19:22:35 +01:00
committed by GitHub
parent 0a1bc654d9
commit 9e31bcdc00
3 changed files with 49 additions and 8 deletions
+20
View File
@@ -242,6 +242,26 @@ versioned_type! {
}
}
versioned_type! {
/// A single `NetworkId` value, together with its version code.
pub enum VersionedNetworkId {
#[codec(index = 2)]
V2(v2::NetworkId),
#[codec(index = 3)]
V3(v3::NetworkId),
}
}
versioned_type! {
/// A single `Junction` value, together with its version code.
pub enum VersionedJunction {
#[codec(index = 2)]
V2(v2::Junction),
#[codec(index = 3)]
V3(v3::Junction),
}
}
versioned_type! {
/// A single `MultiLocation` value, together with its version code.
#[derive(Ord, PartialOrd)]
+17 -8
View File
@@ -117,16 +117,25 @@ pub enum NetworkId {
Kusama,
}
impl TryInto<NetworkId> for Option<NewNetworkId> {
impl TryFrom<Option<NewNetworkId>> for NetworkId {
type Error = ();
fn try_into(self) -> result::Result<NetworkId, ()> {
fn try_from(new: Option<NewNetworkId>) -> result::Result<NetworkId, ()> {
match new {
None => Ok(NetworkId::Any),
Some(id) => Self::try_from(id),
}
}
}
impl TryFrom<NewNetworkId> for NetworkId {
type Error = ();
fn try_from(new: NewNetworkId) -> result::Result<NetworkId, ()> {
use NewNetworkId::*;
Ok(match self {
None => NetworkId::Any,
Some(Polkadot) => NetworkId::Polkadot,
Some(Kusama) => NetworkId::Kusama,
_ => return Err(()),
})
match new {
Polkadot => Ok(NetworkId::Polkadot),
Kusama => Ok(NetworkId::Kusama),
_ => Err(()),
}
}
}
+12
View File
@@ -88,6 +88,18 @@ impl From<OldNetworkId> for Option<NetworkId> {
}
}
impl TryFrom<OldNetworkId> for NetworkId {
type Error = ();
fn try_from(old: OldNetworkId) -> Result<Self, Self::Error> {
use OldNetworkId::*;
match old {
Any | Named(_) => Err(()),
Polkadot => Ok(NetworkId::Polkadot),
Kusama => Ok(NetworkId::Kusama),
}
}
}
/// An identifier of a pluralistic body.
#[derive(
Copy,