-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
83 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use subxt::{OnlineClient, PolkadotConfig}; | ||
|
||
use crate::query::maybe_leases; | ||
|
||
pub enum Chain { | ||
DOT, | ||
KSM, | ||
ROC, | ||
} | ||
|
||
pub type Api = OnlineClient::<PolkadotConfig>; | ||
|
||
// Returns if the passed para_id is applicable for a permanent slot in Rococo | ||
pub async fn needs_perm_slot( | ||
para_id: u32 | ||
) -> Result<bool, Box<dyn std::error::Error>> { | ||
|
||
let polkadot_api = OnlineClient::<PolkadotConfig>::from_url("wss://rpc.polkadot.io:443").await?; | ||
let kusama_api = OnlineClient::<PolkadotConfig>::from_url("wss://kusama-rpc.polkadot.io:443").await?; | ||
let _rococo_api = OnlineClient::<PolkadotConfig>::from_url("wss://rococo-rpc.polkadot.io:443").await?; | ||
|
||
let lease_polkadot = maybe_leases( | ||
polkadot_api, | ||
Chain::DOT, | ||
para_id | ||
).await; | ||
|
||
let lease_kusama = maybe_leases( | ||
kusama_api, | ||
Chain::KSM, | ||
para_id | ||
).await; | ||
|
||
if lease_kusama.unwrap() || lease_polkadot.unwrap() { | ||
println!("ParaId: {} needs a permanent slot", para_id); | ||
Ok(true) | ||
} else { Ok(false) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod helper; | ||
pub mod query; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use crate::helper::{Chain, Api}; | ||
|
||
#[subxt::subxt(runtime_metadata_path = "metadata/polkadot_metadata.scale")] | ||
pub mod polkadot {} | ||
|
||
#[subxt::subxt(runtime_metadata_path = "metadata/kusama_metadata.scale")] | ||
pub mod kusama {} | ||
|
||
#[subxt::subxt(runtime_metadata_path = "metadata/rococo_metadata.scale")] | ||
pub mod rococo {} | ||
|
||
use polkadot::runtime_types::polkadot_parachain::primitives::Id; | ||
use kusama::runtime_types::polkadot_parachain::primitives::Id as KusamaId; | ||
use rococo::runtime_types::polkadot_parachain::primitives::Id as RococoId; | ||
|
||
|
||
// Checks if paraId holds any leases on the specified chain | ||
// | ||
pub async fn maybe_leases( | ||
api: Api, | ||
chain: Chain, | ||
para_id: u32 | ||
) -> Result<bool, Box<dyn std::error::Error>> { | ||
|
||
let query = match chain { | ||
Chain::DOT => polkadot::storage().slots().leases(Id(para_id)), | ||
Chain::KSM => kusama::storage().slots().leases(KusamaId(para_id)), | ||
Chain::ROC => rococo::storage().slots().leases(RococoId(para_id)), | ||
}; | ||
|
||
match api | ||
.storage() | ||
.at_latest() | ||
.await? | ||
.fetch(&query) | ||
.await? | ||
{ | ||
Some(_) => Ok(true), | ||
_ => Ok(false), | ||
} | ||
} |