Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleaner parachain matching #25

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading