Skip to content

Commit

Permalink
Add polkadot people chain (#32)
Browse files Browse the repository at this point in the history
* Add polkadot people chain

* Fix test
  • Loading branch information
seadanda authored Sep 10, 2024
1 parent 5cfc43f commit 95cb8a5
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
23 changes: 22 additions & 1 deletion src/build_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ pub(crate) fn parse_inputs(prefs: UpgradeArgs) -> UpgradeDetails {
if let Some(v) = bridge_hub_version.clone() {
networks.push(VersionedNetwork { network: Network::PolkadotBridgeHub, version: v });
}
if let Some(v) = people_version.clone() {
networks.push(VersionedNetwork { network: Network::PolkadotPeople, version: v });
}
Network::Polkadot
},
"kusama" => {
Expand Down Expand Up @@ -251,6 +254,7 @@ async fn download_runtimes(upgrade_details: &UpgradeDetails) {
Network::PolkadotAssetHub => "asset-hub-polkadot",
Network::PolkadotCollectives => "collectives-polkadot",
Network::PolkadotBridgeHub => "bridge-hub-polkadot",
Network::PolkadotPeople => "people-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 @@ -416,6 +420,23 @@ fn generate_authorize_upgrade_calls(upgrade_details: &UpgradeDetails) -> Vec<Cal
));
authorization_calls.push(call);
},
Network::PolkadotPeople => {
use polkadot_people::runtime_types::frame_system::pallet::Call;
let path = format!(
"{}people-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 People Runtime Hash: 0x{}", hex::encode(runtime_hash));

let call = CallInfo::from_runtime_call(NetworkRuntimeCall::PolkadotPeople(
PolkadotPeopleRuntimeCall::System(Call::authorize_upgrade {
code_hash: H256(runtime_hash),
}),
));
authorization_calls.push(call);
},
};
}
authorization_calls
Expand Down Expand Up @@ -574,7 +595,7 @@ async fn send_as_superuser_from_kusama(auth: &CallInfo) -> KusamaRuntimeCall {
Instruction, Xcm,
},
xcm::{
double_encoded::DoubleEncoded, v2::OriginKind, v3::WeightLimit, VersionedLocation,
double_encoded::DoubleEncoded, v3::OriginKind, v3::WeightLimit, VersionedLocation,
VersionedXcm::V4,
},
};
Expand Down
1 change: 1 addition & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ fn upgrade_everything_works_with_just_relay_version() {
VersionedNetwork { network: Network::PolkadotAssetHub, version: String::from("1.2.0") },
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") },
];
assert_eq!(details.networks, expected_networks);
assert!(details.additional.is_none());
Expand Down
28 changes: 27 additions & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ pub(super) use polkadot_collectives::runtime_types::{
pub mod polkadot_bridge_hub {}
pub(super) use polkadot_bridge_hub::runtime_types::bridge_hub_polkadot_runtime::RuntimeCall as PolkadotBridgeHubRuntimeCall;

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

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

impl Network {
Expand All @@ -94,6 +99,7 @@ impl Network {
PolkadotAssetHub => Ok(1_000),
PolkadotBridgeHub => Ok(1_002),
PolkadotCollectives => Ok(1_001),
PolkadotPeople => Ok(1_004),
}
}

Expand All @@ -109,7 +115,7 @@ 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)
matches!(self, PolkadotAssetHub | PolkadotCollectives | PolkadotBridgeHub | PolkadotPeople)
}
}

Expand Down Expand Up @@ -182,6 +188,7 @@ pub(super) enum NetworkRuntimeCall {
PolkadotAssetHub(PolkadotAssetHubRuntimeCall),
PolkadotCollectives(CollectivesRuntimeCall),
PolkadotBridgeHub(PolkadotBridgeHubRuntimeCall),
PolkadotPeople(PolkadotPeopleRuntimeCall),
}

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

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

pub(super) async fn get_transact_weight_needed(
&self,
network: &Network,
Expand All @@ -414,6 +439,7 @@ impl CallInfo {
Network::PolkadotAssetHub => "wss://polkadot-asset-hub-rpc.polkadot.io:443",
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",
};

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

0 comments on commit 95cb8a5

Please sign in to comment.