diff --git a/src/build_upgrade.rs b/src/build_upgrade.rs index 08de2af..677888b 100644 --- a/src/build_upgrade.rs +++ b/src/build_upgrade.rs @@ -29,6 +29,11 @@ pub(crate) struct UpgradeArgs { #[clap(long = "collectives")] collectives: Option, + /// Optional. The runtime version of Encointer to which to upgrade. If not provided, it will use + /// the Relay Chain's version. + #[clap(long = "encointer")] + encointer: Option, + /// Name of the file to which to write the output. If not provided, a default will be /// constructed. #[clap(long = "filename")] @@ -75,6 +80,11 @@ fn parse_inputs(prefs: UpgradeArgs) -> UpgradeDetails { } else { relay_version.clone() }; + let encointer_version = if let Some(v) = prefs.encointer { + String::from(v.trim_start_matches('v')) + } else { + relay_version.clone() + }; let collectives_version = if let Some(v) = prefs.collectives { String::from(v.trim_start_matches('v')) } else { @@ -116,6 +126,10 @@ fn parse_inputs(prefs: UpgradeArgs) -> UpgradeDetails { network: Network::KusamaBridgeHub, version: bridge_hub_version.clone(), }); + networks.push(VersionedNetwork { + network: Network::KusamaEncointer, + version: encointer_version.clone(), + }); VersionedNetwork { network: Network::Kusama, version: relay_version.clone() } }, _ => panic!("`network` must be `polkadot` or `kusama`"), @@ -184,6 +198,7 @@ async fn download_runtimes(upgrade_details: &UpgradeDetails) { Network::Polkadot => "polkadot", Network::KusamaAssetHub => "asset-hub-kusama", Network::KusamaBridgeHub => "bridge-hub-kusama", + Network::KusamaEncointer => "encointer-kusama", Network::PolkadotAssetHub => "asset-hub-polkadot", Network::PolkadotCollectives => "collectives-polkadot", Network::PolkadotBridgeHub => "bridge-hub-polkadot", @@ -252,6 +267,24 @@ fn generate_authorize_upgrade_calls(upgrade_details: &UpgradeDetails) -> Vec { + use kusama_encointer::runtime_types::cumulus_pallet_parachain_system::pallet::Call; + let path = format!( + "{}encointer-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 Encointer Runtime Hash: 0x{}", hex::encode(runtime_hash)); + + let call = CallInfo::from_runtime_call(NetworkRuntimeCall::KusamaEncointer( + KusamaEncointerRuntimeCall::ParachainSystem(Call::authorize_upgrade { + code_hash: H256(runtime_hash), + check_version: true, + }), + )); + authorization_calls.push(call); + }, Network::PolkadotAssetHub => { use polkadot_asset_hub::runtime_types::cumulus_pallet_parachain_system::pallet::Call; let path = format!( @@ -394,6 +427,10 @@ async fn construct_kusama_batch( let send_auth = send_as_superuser_from_kusama(&auth).await; batch_calls.push(send_auth); }, + Network::KusamaEncointer => { + let send_auth = send_as_superuser_from_kusama(&auth).await; + batch_calls.push(send_auth); + }, } } if let Some(a) = additional { @@ -419,7 +456,8 @@ async fn construct_polkadot_batch( match auth.network { Network::Kusama | Network::Polkadot => panic!("para calls should not contain relay calls"), - Network::KusamaAssetHub | Network::KusamaBridgeHub => panic!("not polkadot parachains"), + Network::KusamaAssetHub | Network::KusamaBridgeHub | Network::KusamaEncointer => + panic!("not polkadot parachains"), Network::PolkadotAssetHub => { let send_auth = send_as_superuser_from_polkadot(&auth).await; batch_calls.push(send_auth); diff --git a/src/types.rs b/src/types.rs index 1b51314..0205cb5 100644 --- a/src/types.rs +++ b/src/types.rs @@ -18,6 +18,10 @@ pub(super) use kusama_asset_hub::runtime_types::asset_hub_kusama_runtime::Runtim pub mod kusama_bridge_hub {} pub(super) use kusama_bridge_hub::runtime_types::bridge_hub_kusama_runtime::RuntimeCall as KusamaBridgeHubRuntimeCall; +#[subxt::subxt(runtime_metadata_insecure_url = "wss://kusama.api.encointer.org:443")] +pub mod kusama_encointer {} +pub(super) use kusama_encointer::runtime_types::encointer_runtime::RuntimeCall as KusamaEncointerRuntimeCall; + #[subxt::subxt( runtime_metadata_insecure_url = "wss://polkadot-rpc.dwellir.com:443", derive_for_all_types = "PartialEq, Clone" @@ -51,6 +55,7 @@ pub(super) enum Network { Kusama, KusamaAssetHub, KusamaBridgeHub, + KusamaEncointer, Polkadot, PolkadotAssetHub, PolkadotCollectives, @@ -64,6 +69,7 @@ impl Network { Kusama => Err("relay chain"), KusamaAssetHub => Ok(1_000), KusamaBridgeHub => Ok(1_002), + KusamaEncointer => Ok(1_001), Polkadot => Err("relay chain"), PolkadotAssetHub => Ok(1_000), PolkadotCollectives => Ok(1_001), @@ -129,6 +135,7 @@ pub(super) enum NetworkRuntimeCall { Kusama(KusamaRuntimeCall), KusamaAssetHub(KusamaAssetHubRuntimeCall), KusamaBridgeHub(KusamaBridgeHubRuntimeCall), + KusamaEncointer(KusamaEncointerRuntimeCall), Polkadot(PolkadotRuntimeCall), PolkadotAssetHub(PolkadotAssetHubRuntimeCall), PolkadotCollectives(CollectivesRuntimeCall), @@ -171,6 +178,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::KusamaEncointer(cc) => (Network::KusamaEncointer, cc.encode()), NetworkRuntimeCall::Polkadot(cc) => (Network::Polkadot, cc.encode()), NetworkRuntimeCall::PolkadotAssetHub(cc) => (Network::PolkadotAssetHub, cc.encode()), NetworkRuntimeCall::PolkadotCollectives(cc) => @@ -235,6 +243,23 @@ impl CallInfo { } } + // Strip the outer enum and return a Kusama Encointer `RuntimeCall`. + #[allow(dead_code)] + pub(super) fn get_kusama_encointer_call( + &self, + ) -> Result { + match &self.network { + Network::KusamaEncointer => { + let bytes = &self.encoded; + Ok(::decode( + &mut &bytes[..], + ) + .unwrap()) + }, + _ => Err("not a kusama encointer call"), + } + } + // Strip the outer enum and return a Polkadot Relay `RuntimeCall`. pub(super) fn get_polkadot_call(&self) -> Result { match &self.network { @@ -308,6 +333,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::KusamaEncointer => "wss://kusama.api.encointer.org:443", Network::Polkadot => "wss://polkadot-rpc.dwellir.com:443", Network::PolkadotAssetHub => "wss://polkadot-asset-hub-rpc.polkadot.io:443", Network::PolkadotCollectives => "wss://polkadot-collectives-rpc.polkadot.io:443",