Skip to content

Commit

Permalink
refactor: various improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexD10S committed Dec 1, 2024
1 parent 6b963a4 commit 4ad7144
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 38 deletions.
44 changes: 20 additions & 24 deletions crates/pop-cli/src/commands/call/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ const DEFAULT_URI: &str = "//Alice";
#[derive(Args, Clone)]
pub struct CallParachainCommand {
/// The pallet containing the extrinsic to execute.
#[arg(long)]
#[arg(short, long)]
pallet: Option<String>,
/// The extrinsic to execute within the chosen pallet.
#[arg(long)]
#[arg(short, long)]
extrinsic: Option<String>,
/// The extrinsic arguments, encoded as strings.
#[arg(long, num_args = 0..,)]
#[arg(short, long, num_args = 0..,)]
args: Vec<String>,
/// Websocket endpoint of a node.
#[arg(short = 'u', long, value_parser)]
#[arg(short, long, value_parser)]
url: Option<Url>,
/// Secret key URI for the account signing the extrinsic.
///
/// e.g.
/// - for a dev account "//Alice"
/// - with a password "//Alice///SECRET_PASSWORD"
#[arg(long)]
#[arg(short, long)]
suri: Option<String>,
/// Automatically signs and submits the extrinsic without asking for confirmation.
/// Automatically signs and submits the extrinsic without prompting for confirmation.
#[arg(short('y'), long)]
skip_confirm: bool,
}
Expand Down Expand Up @@ -73,9 +73,8 @@ impl CallParachainCommand {
break;
}

if !prompt_to_repeat_call
|| !cli
.confirm("Do you want to perform another call?")
if !prompt_to_repeat_call ||
!cli.confirm("Do you want to perform another call?")
.initial_value(false)
.interact()?
{
Expand Down Expand Up @@ -137,9 +136,8 @@ impl CallParachainCommand {

// Resolve extrinsic.
let extrinsic = match self.extrinsic {
Some(ref extrinsic_name) => {
find_extrinsic_by_name(&chain.pallets, &pallet.name, extrinsic_name).await?
},
Some(ref extrinsic_name) =>
find_extrinsic_by_name(&chain.pallets, &pallet.name, extrinsic_name).await?,
None => {
let mut prompt_extrinsic = cli.select("Select the extrinsic to call:");
for extrinsic in &pallet.extrinsics {
Expand Down Expand Up @@ -175,9 +173,8 @@ impl CallParachainCommand {
// Resolve who is signing the extrinsic.
let suri = match self.clone().suri {
Some(suri) => suri,
None => {
cli.input("Signer of the extrinsic:").default_input(DEFAULT_URI).interact()?
},
None =>
cli.input("Signer of the extrinsic:").default_input(DEFAULT_URI).interact()?,
};

return Ok(CallParachain {
Expand All @@ -199,11 +196,11 @@ impl CallParachainCommand {

// Function to check if all required fields are specified
fn requires_user_input(&self) -> bool {
self.pallet.is_none()
|| self.extrinsic.is_none()
|| self.args.is_empty()
|| self.url.is_none()
|| self.suri.is_none()
self.pallet.is_none() ||
self.extrinsic.is_none() ||
self.args.is_empty() ||
self.url.is_none() ||
self.suri.is_none()
}
}

Expand All @@ -227,7 +224,7 @@ struct CallParachain {
/// - for a dev account "//Alice"
/// - with a password "//Alice///SECRET_PASSWORD"
suri: String,
/// Whether to automatically sign and submit the extrinsic without asking for confirmation.
/// Whether to automatically sign and submit the extrinsic without prompting for confirmation.
skip_confirm: bool,
}

Expand Down Expand Up @@ -261,9 +258,8 @@ impl CallParachain {
tx: DynamicPayload,
cli: &mut impl Cli,
) -> Result<()> {
if !self.skip_confirm
&& !cli
.confirm("Do you want to submit the extrinsic?")
if !self.skip_confirm &&
!cli.confirm("Do you want to submit the extrinsic?")
.initial_value(true)
.interact()?
{
Expand Down
4 changes: 2 additions & 2 deletions crates/pop-common/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ pub enum Error {
IO(#[from] std::io::Error),

Check warning on line 17 in crates/pop-common/src/errors.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> crates/pop-common/src/errors.rs:17:2 | 17 | IO(#[from] std::io::Error), | ^^
#[error("Failed to create keypair from URI: {0}")]
KeyPairCreation(String),

Check warning on line 19 in crates/pop-common/src/errors.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> crates/pop-common/src/errors.rs:19:2 | 19 | KeyPairCreation(String), | ^^^^^^^^^^^^^^^
#[error("Failed to get manifest path: {0}")]
ManifestPath(String),
#[error("Manifest error: {0}")]
ManifestError(#[from] cargo_toml::Error),

Check warning on line 21 in crates/pop-common/src/errors.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> crates/pop-common/src/errors.rs:21:2 | 21 | ManifestError(#[from] cargo_toml::Error), | ^^^^^^^^^^^^^
#[error("Failed to get manifest path: {0}")]
ManifestPath(String),

Check warning on line 23 in crates/pop-common/src/errors.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> crates/pop-common/src/errors.rs:23:2 | 23 | ManifestPath(String), | ^^^^^^^^^^^^
#[error("ParseError error: {0}")]
ParseError(#[from] url::ParseError),

Check warning on line 25 in crates/pop-common/src/errors.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> crates/pop-common/src/errors.rs:25:2 | 25 | ParseError(#[from] url::ParseError), | ^^^^^^^^^^
#[error("Failed to parse secret URI: {0}")]
Expand Down
6 changes: 4 additions & 2 deletions crates/pop-parachains/src/call/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ pub async fn sign_and_submit_extrinsic(
let result = api
.tx()
.sign_and_submit_then_watch_default(&tx, &signer)
.await?
.await
.map_err(|e| Error::ExtrinsicSubmissionError(format!("{:?}", e)))?
.wait_for_finalized_success()
.await?;
.await
.map_err(|e| Error::ExtrinsicSubmissionError(format!("{:?}", e)))?;
Ok(format!("{:?}", result.extrinsic_hash()))
}

Expand Down
11 changes: 2 additions & 9 deletions crates/pop-parachains/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: GPL-3.0

use subxt::ext::scale_decode;
use thiserror::Error;
use zombienet_sdk::OrchestratorError;

Expand All @@ -20,14 +19,12 @@ pub enum Error {
EndowmentError,

Check warning on line 19 in crates/pop-parachains/src/errors.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> crates/pop-parachains/src/errors.rs:19:2 | 19 | EndowmentError, | ^^^^^^^^^^^^^^
#[error("The extrinsic is not supported")]
ExtrinsicNotSupported,

Check warning on line 21 in crates/pop-parachains/src/errors.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> crates/pop-parachains/src/errors.rs:21:2 | 21 | ExtrinsicNotSupported, | ^^^^^^^^^^^^^^^^^^^^^
#[error("Failed decode a value")]
FromHexError(#[from] hex::FromHexError),
#[error("Extrinsic submission error: {0}")]
ExtrinsicSubmissionError(String),

Check warning on line 23 in crates/pop-parachains/src/errors.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> crates/pop-parachains/src/errors.rs:23:2 | 23 | ExtrinsicSubmissionError(String), | ^^^^^^^^^^^^^^^^^^^^^^^^
#[error("IO error: {0}")]
IO(#[from] std::io::Error),

Check warning on line 25 in crates/pop-parachains/src/errors.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> crates/pop-parachains/src/errors.rs:25:2 | 25 | IO(#[from] std::io::Error), | ^^
#[error("JSON error: {0}")]
JsonError(#[from] serde_json::Error),

Check warning on line 27 in crates/pop-parachains/src/errors.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> crates/pop-parachains/src/errors.rs:27:2 | 27 | JsonError(#[from] serde_json::Error), | ^^^^^^^^^
#[error("Metadata error: {0}")]
MetadataError(#[from] subxt::error::MetadataError),
#[error("Error parsing metadata for parameter {0} conversion")]
MetadataParsingError(String),

Check warning on line 29 in crates/pop-parachains/src/errors.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> crates/pop-parachains/src/errors.rs:29:2 | 29 | MetadataParsingError(String), | ^^^^^^^^^^^^^^^^^^^^
#[error("Missing binary: {0}")]
Expand All @@ -40,14 +37,10 @@ pub enum Error {
OrchestratorError(#[from] OrchestratorError),

Check warning on line 37 in crates/pop-parachains/src/errors.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> crates/pop-parachains/src/errors.rs:37:2 | 37 | OrchestratorError(#[from] OrchestratorError), | ^^^^^^^^^^^^^^^^^
#[error("Failed to create pallet directory")]
PalletDirCreation,

Check warning on line 39 in crates/pop-parachains/src/errors.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> crates/pop-parachains/src/errors.rs:39:2 | 39 | PalletDirCreation, | ^^^^^^^^^^^^^^^^^
#[error("The `Pallet` property is missing from the call variant")]
PalletMissing,
#[error("Failed to find the pallet {0}")]
PalletNotFound(String),

Check warning on line 41 in crates/pop-parachains/src/errors.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> crates/pop-parachains/src/errors.rs:41:2 | 41 | PalletNotFound(String), | ^^^^^^^^^^^^^^
#[error("Failed to process the arguments provided by the user.")]
ParamProcessingError,

Check warning on line 43 in crates/pop-parachains/src/errors.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> crates/pop-parachains/src/errors.rs:43:2 | 43 | ParamProcessingError, | ^^^^^^^^^^^^^^^^^^^^
#[error("Failed to parse the response")]
ParsingResponseError(#[from] scale_decode::Error),
#[error("Invalid path")]
PathError,

Check warning on line 45 in crates/pop-parachains/src/errors.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> crates/pop-parachains/src/errors.rs:45:2 | 45 | PathError, | ^^^^^^^^^
#[error("Failed to execute rustfmt")]
Expand Down
2 changes: 1 addition & 1 deletion crates/pop-parachains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub use indexmap::IndexSet;
pub use new_pallet::{create_pallet_template, new_pallet_options::*, TemplatePalletConfig};
pub use new_parachain::instantiate_template_dir;
// External export from subxt.
pub use subxt::{dynamic::Value, tx::DynamicPayload, OnlineClient, SubstrateConfig};
pub use subxt::{tx::DynamicPayload, OnlineClient, SubstrateConfig};
pub use templates::{Config, Parachain, Provider};
pub use up::Zombienet;
pub use utils::helpers::is_initial_endowment_valid;
Expand Down

0 comments on commit 4ad7144

Please sign in to comment.