Skip to content

Commit

Permalink
add encointer
Browse files Browse the repository at this point in the history
  • Loading branch information
joepetrowski committed Apr 2, 2024
1 parent 5e27fda commit c584ba8
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/build_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ pub(crate) struct UpgradeArgs {
#[clap(long = "collectives")]
collectives: Option<String>,

/// 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<String>,

/// Name of the file to which to write the output. If not provided, a default will be
/// constructed.
#[clap(long = "filename")]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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`"),
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -252,6 +267,24 @@ fn generate_authorize_upgrade_calls(upgrade_details: &UpgradeDetails) -> Vec<Cal
));
authorization_calls.push(call);
},
Network::KusamaEncointer => {
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!(
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
Expand Down
26 changes: 26 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -51,6 +55,7 @@ pub(super) enum Network {
Kusama,
KusamaAssetHub,
KusamaBridgeHub,
KusamaEncointer,
Polkadot,
PolkadotAssetHub,
PolkadotCollectives,
Expand All @@ -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),
Expand Down Expand Up @@ -129,6 +135,7 @@ pub(super) enum NetworkRuntimeCall {
Kusama(KusamaRuntimeCall),
KusamaAssetHub(KusamaAssetHubRuntimeCall),
KusamaBridgeHub(KusamaBridgeHubRuntimeCall),
KusamaEncointer(KusamaEncointerRuntimeCall),
Polkadot(PolkadotRuntimeCall),
PolkadotAssetHub(PolkadotAssetHubRuntimeCall),
PolkadotCollectives(CollectivesRuntimeCall),
Expand Down Expand Up @@ -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) =>
Expand Down Expand Up @@ -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<KusamaEncointerRuntimeCall, &'static str> {
match &self.network {
Network::KusamaEncointer => {
let bytes = &self.encoded;
Ok(<KusamaEncointerRuntimeCall as parity_scale_codec::Decode>::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<PolkadotRuntimeCall, &'static str> {
match &self.network {
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit c584ba8

Please sign in to comment.