Skip to content

Commit

Permalink
Add the Polkadot Coretime chain (#34)
Browse files Browse the repository at this point in the history
* Add Polkadot Coretime

* Update OriginKind to v3

* Fix tests
  • Loading branch information
seadanda authored Sep 20, 2024
1 parent 8f59abd commit 57f855a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/build_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ pub(crate) fn parse_inputs(prefs: UpgradeArgs) -> UpgradeDetails {
if let Some(v) = people_version.clone() {
networks.push(VersionedNetwork { network: Network::PolkadotPeople, version: v });
}
if let Some(v) = coretime_version.clone() {
networks.push(VersionedNetwork { network: Network::PolkadotCoretime, version: v });
}
Network::Polkadot
},
"kusama" => {
Expand Down Expand Up @@ -255,6 +258,7 @@ async fn download_runtimes(upgrade_details: &UpgradeDetails) {
Network::PolkadotCollectives => "collectives-polkadot",
Network::PolkadotBridgeHub => "bridge-hub-polkadot",
Network::PolkadotPeople => "people-polkadot",
Network::PolkadotCoretime => "coretime-polkadot",
};
let runtime_version = semver_to_intver(&chain.version);
let fname = format!("{}_runtime-v{}.compact.compressed.wasm", chain_name, runtime_version);
Expand Down Expand Up @@ -437,6 +441,23 @@ fn generate_authorize_upgrade_calls(upgrade_details: &UpgradeDetails) -> Vec<Cal
));
authorization_calls.push(call);
},
Network::PolkadotCoretime => {
use polkadot_coretime::runtime_types::frame_system::pallet::Call;
let path = format!(
"{}coretime-polkadot_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!("Polkadot Coretime Runtime Hash: 0x{}", hex::encode(runtime_hash));

let call = CallInfo::from_runtime_call(NetworkRuntimeCall::PolkadotCoretime(
PolkadotCoretimeRuntimeCall::System(Call::authorize_upgrade {
code_hash: H256(runtime_hash),
}),
));
authorization_calls.push(call);
},
};
}
authorization_calls
Expand Down
1 change: 1 addition & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ fn upgrade_everything_works_with_just_relay_version() {
VersionedNetwork { network: Network::PolkadotCollectives, version: String::from("1.2.0") },
VersionedNetwork { network: Network::PolkadotBridgeHub, version: String::from("1.2.0") },
VersionedNetwork { network: Network::PolkadotPeople, version: String::from("1.2.0") },
VersionedNetwork { network: Network::PolkadotCoretime, version: String::from("1.2.0") },
];
assert_eq!(details.networks, expected_networks);
assert!(details.additional.is_none());
Expand Down
34 changes: 33 additions & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ pub(super) use polkadot_bridge_hub::runtime_types::bridge_hub_polkadot_runtime::
pub mod polkadot_people {}
pub(super) use polkadot_people::runtime_types::people_polkadot_runtime::RuntimeCall as PolkadotPeopleRuntimeCall;

#[subxt::subxt(runtime_metadata_insecure_url = "wss://polkadot-coretime-rpc.polkadot.io:443")]
pub mod polkadot_coretime {}
pub(super) use polkadot_coretime::runtime_types::coretime_polkadot_runtime::RuntimeCall as PolkadotCoretimeRuntimeCall;

#[derive(Clone, Debug, PartialEq)]
pub(super) enum Network {
Kusama,
Expand All @@ -80,6 +84,7 @@ pub(super) enum Network {
PolkadotCollectives,
PolkadotBridgeHub,
PolkadotPeople,
PolkadotCoretime,
}

impl Network {
Expand All @@ -100,6 +105,7 @@ impl Network {
PolkadotBridgeHub => Ok(1_002),
PolkadotCollectives => Ok(1_001),
PolkadotPeople => Ok(1_004),
PolkadotCoretime => Ok(1_005),
}
}

Expand All @@ -115,7 +121,13 @@ impl Network {
/// Returns `true` if the network is a Polkadot _parachain_.
pub(super) fn is_polkadot_para(&self) -> bool {
use Network::*;
matches!(self, PolkadotAssetHub | PolkadotCollectives | PolkadotBridgeHub | PolkadotPeople)
matches!(
self,
PolkadotAssetHub
| PolkadotCollectives
| PolkadotBridgeHub
| PolkadotPeople | PolkadotCoretime
)
}
}

Expand Down Expand Up @@ -189,6 +201,7 @@ pub(super) enum NetworkRuntimeCall {
PolkadotCollectives(CollectivesRuntimeCall),
PolkadotBridgeHub(PolkadotBridgeHubRuntimeCall),
PolkadotPeople(PolkadotPeopleRuntimeCall),
PolkadotCoretime(PolkadotCoretimeRuntimeCall),
}

// How the user would like to see the output of the program.
Expand Down Expand Up @@ -236,6 +249,7 @@ impl CallInfo {
(Network::PolkadotCollectives, cc.encode()),
NetworkRuntimeCall::PolkadotBridgeHub(cc) => (Network::PolkadotBridgeHub, cc.encode()),
NetworkRuntimeCall::PolkadotPeople(cc) => (Network::PolkadotPeople, cc.encode()),
NetworkRuntimeCall::PolkadotCoretime(cc) => (Network::PolkadotCoretime, cc.encode()),
};
let hash = blake2_256(&encoded);
let length: u32 = (encoded.len()).try_into().unwrap();
Expand Down Expand Up @@ -419,6 +433,23 @@ impl CallInfo {
}
}

// Strip the outer enum and return a Polkadot Coretime `RuntimeCall`.
#[allow(dead_code)]
pub(super) fn get_polkadot_coretime_call(
&self,
) -> Result<PolkadotCoretimeRuntimeCall, &'static str> {
match &self.network {
Network::PolkadotCoretime => {
let bytes = &self.encoded;
Ok(<PolkadotCoretimeRuntimeCall as parity_scale_codec::Decode>::decode(
&mut &bytes[..],
)
.unwrap())
},
_ => Err("not a polkadot coretime call"),
}
}

pub(super) async fn get_transact_weight_needed(
&self,
network: &Network,
Expand All @@ -440,6 +471,7 @@ impl CallInfo {
Network::PolkadotCollectives => "wss://polkadot-collectives-rpc.polkadot.io:443",
Network::PolkadotBridgeHub => "wss://polkadot-bridge-hub-rpc.polkadot.io:443",
Network::PolkadotPeople => "wss://polkadot-people-rpc.polkadot.io:443",
Network::PolkadotCoretime => "wss://polkadot-coretime-rpc.polkadot.io:443",
};

let mut args = self.encoded.clone();
Expand Down

0 comments on commit 57f855a

Please sign in to comment.