Skip to content

Commit

Permalink
cleaner parachain matching (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
joepetrowski authored Apr 16, 2024
1 parent 7ad99e1 commit 7bdfdb6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 39 deletions.
44 changes: 6 additions & 38 deletions src/build_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,25 +452,9 @@ async fn construct_kusama_batch(

let mut batch_calls = Vec::new();
for auth in para_calls {
match auth.network {
// Relays. This iterator should only have parachain calls.
Network::Kusama | Network::Polkadot =>
panic!("para calls should not contain relay calls"),

// Polkadot parachains
Network::PolkadotAssetHub
| Network::PolkadotCollectives
| Network::PolkadotBridgeHub => panic!("not kusama parachains"),

// The rest. We could `_` it but we match explicitly to avoid footguns when adding new
// chains to a network.
Network::KusamaAssetHub
| Network::KusamaBridgeHub
| Network::KusamaCoretime
| Network::KusamaEncointer => {
let send_auth = send_as_superuser_from_kusama(&auth).await;
batch_calls.push(send_auth);
},
if auth.network.is_kusama_para() {
let send_auth = send_as_superuser_from_kusama(&auth).await;
batch_calls.push(send_auth);
}
}
if let Some(a) = additional {
Expand All @@ -495,25 +479,9 @@ async fn construct_polkadot_batch(

let mut batch_calls = Vec::new();
for auth in para_calls {
match auth.network {
// Relays. This iterator should only have parachain calls.
Network::Kusama | Network::Polkadot =>
panic!("para calls should not contain relay calls"),

// Kusama parachains
Network::KusamaAssetHub
| Network::KusamaBridgeHub
| Network::KusamaCoretime
| Network::KusamaEncointer => panic!("not polkadot parachains"),

// The rest. We could `_` it but we match explicitly to avoid footguns when adding new
// chains to a network.
Network::PolkadotAssetHub
| Network::PolkadotCollectives
| Network::PolkadotBridgeHub => {
let send_auth = send_as_superuser_from_polkadot(&auth).await;
batch_calls.push(send_auth);
},
if auth.network.is_polkadot_para() {
let send_auth = send_as_superuser_from_polkadot(&auth).await;
batch_calls.push(send_auth);
}
}
if let Some(a) = additional {
Expand Down
17 changes: 16 additions & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,35 @@ pub(super) enum Network {
}

impl Network {
/// Return the `ParaId` of a given network. Returns an error if the network is not a parachain.
pub(super) fn get_para_id(&self) -> Result<u32, &'static str> {
use Network::*;
match &self {
// Kusama
Kusama => Err("relay chain"),
KusamaAssetHub => Ok(1_000),
KusamaBridgeHub => Ok(1_002),
KusamaCoretime => Ok(1_005),
KusamaEncointer => Ok(1_001),
// Polkadot
Polkadot => Err("relay chain"),
PolkadotAssetHub => Ok(1_000),
PolkadotCollectives => Ok(1_001),
PolkadotBridgeHub => Ok(1_002),
PolkadotCollectives => Ok(1_001),
}
}

/// Returns `true` if the network is a Kusama _parachain_.
pub(super) fn is_kusama_para(&self) -> bool {
use Network::*;
matches!(self, KusamaAssetHub | KusamaBridgeHub | KusamaCoretime | KusamaEncointer)
}

/// Returns `true` if the network is a Polkadot _parachain_.
pub(super) fn is_polkadot_para(&self) -> bool {
use Network::*;
matches!(self, PolkadotAssetHub | PolkadotCollectives | PolkadotBridgeHub)
}
}

// Info and preferences provided by the user for proposal submission.
Expand Down

0 comments on commit 7bdfdb6

Please sign in to comment.