Skip to content

Commit

Permalink
refactor: use dynamic tx
Browse files Browse the repository at this point in the history
  • Loading branch information
evilrobot-01 committed Nov 27, 2024
1 parent f7b937f commit cf3cfcc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 30 deletions.
6 changes: 2 additions & 4 deletions crates/pop-cli/src/commands/up/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl ZombienetCommand {
None => {
log::error(format!("🚫 Using `{relay_chain}` with HRMP channels is currently unsupported. Please use `paseo-local` or `rococo-local`."))?;
},
Some(relay_chain) => {
Some(_) => {
use tokio::time::sleep;
let spinner = cliclack::spinner();
spinner.start("Connecting to relay chain to prepare channels...");
Expand All @@ -166,9 +166,7 @@ impl ZombienetCommand {
let para_ids: Vec<_> =
network.parachains().iter().map(|p| p.para_id()).collect();
tokio::spawn(async move {
if let Err(e) =
clear_dmpq(relay_chain, relay_endpoint, &para_ids).await
{
if let Err(e) = clear_dmpq(relay_endpoint, &para_ids).await {
spinner.stop("");
log::error(format!("🚫 Could not prepare channels: {e}"))?;
return Ok::<(), Error>(());
Expand Down
39 changes: 13 additions & 26 deletions crates/pop-parachains/src/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

use crate::Error;
use sp_core::twox_128;
use subxt::{config::BlockHash, ext::sp_core, OnlineClient, PolkadotConfig};
use subxt::{
config::BlockHash,
dynamic::{self, Value},
ext::sp_core,
OnlineClient, PolkadotConfig,
};

/// Clears the DMPQ state for the given parachain IDs.
///
Expand All @@ -11,7 +16,6 @@ use subxt::{config::BlockHash, ext::sp_core, OnlineClient, PolkadotConfig};
/// * `client` - Client for the network which state is to be modified.
/// * `para_ids` - List of ids to build the keys that will be mutated.
pub async fn clear_dmpq(
relay_chain: RelayChain,
client: OnlineClient<PolkadotConfig>,
para_ids: &[u32],
) -> Result<impl BlockHash, Error> {
Expand Down Expand Up @@ -44,22 +48,13 @@ pub async fn clear_dmpq(

// Submit calls to remove specified keys
let sudo = subxt_signer::sr25519::dev::alice();
match relay_chain {
RelayChain::PaseoLocal => {
use paseo_local::{
runtime_types::paseo_runtime::RuntimeCall::System, system::Call, tx,
};
let sudo_call = tx().sudo().sudo(System(Call::kill_storage { keys: clear_dmq_keys }));
Ok(client.tx().sign_and_submit_default(&sudo_call, &sudo).await?)
},
RelayChain::RococoLocal => {
use rococo_local::{
runtime_types::rococo_runtime::RuntimeCall::System, system::Call, tx,
};
let sudo_call = tx().sudo().sudo(System(Call::kill_storage { keys: clear_dmq_keys }));
Ok(client.tx().sign_and_submit_default(&sudo_call, &sudo).await?)
},
}
let kill_storage = dynamic::tx(
"System",
"kill_storage",
vec![Value::unnamed_composite(clear_dmq_keys.into_iter().map(|k| Value::from_bytes(k)))],

Check warning on line 54 in crates/pop-parachains/src/relay.rs

View workflow job for this annotation

GitHub Actions / clippy

redundant closure

warning: redundant closure --> crates/pop-parachains/src/relay.rs:54:64 | 54 | vec![Value::unnamed_composite(clear_dmq_keys.into_iter().map(|k| Value::from_bytes(k)))], | ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `Value::from_bytes` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure = note: `#[warn(clippy::redundant_closure)]` on by default
);
let sudo_call = dynamic::tx("Sudo", "sudo", vec![kill_storage.into_value()]);
Ok(client.tx().sign_and_submit_default(&sudo_call, &sudo).await?)
}

/// A supported relay chain.
Expand All @@ -83,11 +78,3 @@ impl RelayChain {
}
}
}

// subxt metadata --url ws://127.0.0.1:58774 --pallets System,Sudo > paseo-local.scale
#[subxt::subxt(runtime_metadata_path = "./src/utils/artifacts/paseo-local.scale")]
mod paseo_local {}

// subxt metadata --url ws://127.0.0.1:58774 --pallets System,Sudo > rococo-local.scale
#[subxt::subxt(runtime_metadata_path = "./src/utils/artifacts/rococo-local.scale")]
mod rococo_local {}
Binary file not shown.
Binary file not shown.

0 comments on commit cf3cfcc

Please sign in to comment.