Skip to content

Commit

Permalink
add kusama people (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
joepetrowski authored May 21, 2024
1 parent c6ebdc4 commit e10e9a1
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 5 deletions.
34 changes: 31 additions & 3 deletions src/build_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ pub(crate) struct UpgradeArgs {
#[clap(long = "encointer")]
pub(crate) encointer: Option<String>,

/// Optional. The runtime version of People to which to upgrade. If not provided, it will use
/// the Relay Chain's version.
#[clap(long = "people")]
pub(crate) people: Option<String>,

/// Optional. The runtime version of Coretime to which to upgrade. If not provided, it will use
/// the Relay Chain's version.
#[clap(long = "coretime")]
Expand Down Expand Up @@ -113,6 +118,7 @@ pub(crate) fn parse_inputs(prefs: UpgradeArgs) -> UpgradeDetails {
let relay_version = chain_version(prefs.relay_version, None, only);
let asset_hub_version = chain_version(prefs.asset_hub, relay_version.clone(), only);
let bridge_hub_version = chain_version(prefs.bridge_hub, relay_version.clone(), only);
let people_version = chain_version(prefs.people, relay_version.clone(), only);
let coretime_version = chain_version(prefs.coretime, relay_version.clone(), only);
let encointer_version = chain_version(prefs.encointer, relay_version.clone(), only);
let collectives_version = chain_version(prefs.collectives, relay_version.clone(), only);
Expand Down Expand Up @@ -147,6 +153,9 @@ pub(crate) fn parse_inputs(prefs: UpgradeArgs) -> UpgradeDetails {
if let Some(v) = bridge_hub_version.clone() {
networks.push(VersionedNetwork { network: Network::KusamaBridgeHub, version: v });
}
if let Some(v) = people_version.clone() {
networks.push(VersionedNetwork { network: Network::KusamaPeople, version: v });
}
if let Some(v) = coretime_version.clone() {
networks.push(VersionedNetwork { network: Network::KusamaCoretime, version: v });
}
Expand All @@ -173,9 +182,9 @@ pub(crate) fn parse_inputs(prefs: UpgradeArgs) -> UpgradeDetails {

// Get a version from one of the args. (This still feels dirty.)
let version = relay_version.clone().unwrap_or(asset_hub_version.unwrap_or(
bridge_hub_version.unwrap_or(encointer_version.unwrap_or(
collectives_version.unwrap_or(coretime_version.unwrap_or(String::from("no-version"))),
)),
bridge_hub_version.unwrap_or(encointer_version.unwrap_or(collectives_version.unwrap_or(
coretime_version.unwrap_or(people_version.unwrap_or(String::from("no-version"))),
))),
));

// Set up a directory to store information fetched/written during this program.
Expand Down Expand Up @@ -236,6 +245,7 @@ async fn download_runtimes(upgrade_details: &UpgradeDetails) {
Network::Polkadot => "polkadot",
Network::KusamaAssetHub => "asset-hub-kusama",
Network::KusamaBridgeHub => "bridge-hub-kusama",
Network::KusamaPeople => "people-kusama",
Network::KusamaCoretime => "coretime-kusama",
Network::KusamaEncointer => "encointer-kusama",
Network::PolkadotAssetHub => "asset-hub-polkadot",
Expand Down Expand Up @@ -306,6 +316,24 @@ fn generate_authorize_upgrade_calls(upgrade_details: &UpgradeDetails) -> Vec<Cal
));
authorization_calls.push(call);
},
Network::KusamaPeople => {
use kusama_people::runtime_types::cumulus_pallet_parachain_system::pallet::Call;
let path = format!(
"{}people-kusama_runtime-v{}.compact.compressed.wasm",
upgrade_details.directory, runtime_version
);
let runtime = fs::read(path).expect("Should give a valid file path");
let runtime_hash = blake2_256(&runtime);
println!("Kusama People Runtime Hash: 0x{}", hex::encode(runtime_hash));

let call = CallInfo::from_runtime_call(NetworkRuntimeCall::KusamaPeople(
KusamaPeopleRuntimeCall::ParachainSystem(Call::authorize_upgrade {
code_hash: H256(runtime_hash),
check_version: true,
}),
));
authorization_calls.push(call);
},
Network::KusamaCoretime => {
use kusama_coretime::runtime_types::cumulus_pallet_parachain_system::pallet::Call;
let path = format!(
Expand Down
3 changes: 3 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ fn upgrade_args_for_only_relay() -> UpgradeArgs {
bridge_hub: None,
collectives: None,
encointer: None,
people: None,
coretime: None,
filename: None,
additional: None,
Expand All @@ -144,6 +145,7 @@ fn upgrade_args_for_only_asset_hub() -> UpgradeArgs {
bridge_hub: None,
collectives: None,
encointer: None,
people: None,
coretime: None,
filename: None,
additional: None,
Expand All @@ -160,6 +162,7 @@ fn upgrade_args_for_all() -> UpgradeArgs {
bridge_hub: None,
collectives: None,
encointer: None,
people: None,
coretime: None,
filename: None,
additional: None,
Expand Down
29 changes: 27 additions & 2 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ pub(super) use kusama_bridge_hub::runtime_types::bridge_hub_kusama_runtime::Runt
pub mod kusama_encointer {}
pub(super) use kusama_encointer::runtime_types::encointer_kusama_runtime::RuntimeCall as KusamaEncointerRuntimeCall;

#[subxt::subxt(runtime_metadata_insecure_url = "wss://kusama-people-rpc.polkadot.io:443")]
pub mod kusama_people {}
pub(super) use kusama_people::runtime_types::people_kusama_runtime::RuntimeCall as KusamaPeopleRuntimeCall;

#[subxt::subxt(runtime_metadata_insecure_url = "wss://kusama-coretime-rpc.polkadot.io:443")]
pub mod kusama_coretime {}
pub(super) use kusama_coretime::runtime_types::coretime_kusama_runtime::RuntimeCall as KusamaCoretimeRuntimeCall;
Expand Down Expand Up @@ -63,9 +67,10 @@ pub(super) use polkadot_bridge_hub::runtime_types::bridge_hub_polkadot_runtime::
pub(super) enum Network {
Kusama,
KusamaAssetHub,
KusamaEncointer,
KusamaBridgeHub,
KusamaPeople,
KusamaCoretime,
KusamaEncointer,
Polkadot,
PolkadotAssetHub,
PolkadotCollectives,
Expand All @@ -81,6 +86,7 @@ impl Network {
Kusama => Err("relay chain"),
KusamaAssetHub => Ok(1_000),
KusamaBridgeHub => Ok(1_002),
KusamaPeople => Ok(1_004),
KusamaCoretime => Ok(1_005),
KusamaEncointer => Ok(1_001),
// Polkadot
Expand All @@ -94,7 +100,10 @@ impl Network {
/// 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)
matches!(
self,
KusamaAssetHub | KusamaBridgeHub | KusamaPeople | KusamaCoretime | KusamaEncointer
)
}

/// Returns `true` if the network is a Polkadot _parachain_.
Expand Down Expand Up @@ -166,6 +175,7 @@ pub(super) enum NetworkRuntimeCall {
Kusama(KusamaRuntimeCall),
KusamaAssetHub(KusamaAssetHubRuntimeCall),
KusamaBridgeHub(KusamaBridgeHubRuntimeCall),
KusamaPeople(KusamaPeopleRuntimeCall),
KusamaCoretime(KusamaCoretimeRuntimeCall),
KusamaEncointer(KusamaEncointerRuntimeCall),
Polkadot(PolkadotRuntimeCall),
Expand Down Expand Up @@ -210,6 +220,7 @@ impl CallInfo {
NetworkRuntimeCall::Kusama(cc) => (Network::Kusama, cc.encode()),
NetworkRuntimeCall::KusamaAssetHub(cc) => (Network::KusamaAssetHub, cc.encode()),
NetworkRuntimeCall::KusamaBridgeHub(cc) => (Network::KusamaBridgeHub, cc.encode()),
NetworkRuntimeCall::KusamaPeople(cc) => (Network::KusamaPeople, cc.encode()),
NetworkRuntimeCall::KusamaCoretime(cc) => (Network::KusamaCoretime, cc.encode()),
NetworkRuntimeCall::KusamaEncointer(cc) => (Network::KusamaEncointer, cc.encode()),
NetworkRuntimeCall::Polkadot(cc) => (Network::Polkadot, cc.encode()),
Expand Down Expand Up @@ -293,6 +304,19 @@ impl CallInfo {
}
}

// Strip the outer enum and return a Kusama People `RuntimeCall`.
#[allow(dead_code)]
pub(super) fn get_kusama_people_call(&self) -> Result<KusamaPeopleRuntimeCall, &'static str> {
match &self.network {
Network::KusamaPeople => {
let bytes = &self.encoded;
Ok(<KusamaPeopleRuntimeCall as parity_scale_codec::Decode>::decode(&mut &bytes[..])
.unwrap())
},
_ => Err("not a kusama people call"),
}
}

// Strip the outer enum and return a Kusama Coretime `RuntimeCall`.
#[allow(dead_code)]
pub(super) fn get_kusama_coretime_call(
Expand Down Expand Up @@ -383,6 +407,7 @@ impl CallInfo {
Network::Kusama => "wss://kusama-rpc.dwellir.com:443",
Network::KusamaAssetHub => "wss://kusama-asset-hub-rpc.polkadot.io:443",
Network::KusamaBridgeHub => "wss://kusama-bridge-hub-rpc.polkadot.io:443",
Network::KusamaPeople => "wss://kusama-people-rpc.polkadot.io:443",
Network::KusamaCoretime => "wss://kusama-coretime-rpc.polkadot.io:443",
Network::KusamaEncointer => "wss://encointer-kusama-rpc.dwellir.com:443",
Network::Polkadot => "wss://polkadot-rpc.dwellir.com:443",
Expand Down

0 comments on commit e10e9a1

Please sign in to comment.