Skip to content

Commit 930a085

Browse files
```
fix: update signer_from_path to use mutable None parameter ```
1 parent 5fd8253 commit 930a085

File tree

14 files changed

+193
-128
lines changed

14 files changed

+193
-128
lines changed

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
7676
}),
7777
#[cfg(not(feature = "remote-wallet"))]
7878
default_signer: default_signer
79-
.signer_from_path(matches, &None)
79+
.signer_from_path(matches, &mut None)
8080
.unwrap_or_else(|err| {
8181
eprintln!("error: {}", err);
8282
exit(1);
@@ -754,4 +754,4 @@ mod test {
754754
// Assert that the deserialized data matches the original
755755
assert_eq!(faux, in_faux);
756756
}
757-
}
757+
}

src/prelude.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@ pub use crate::utils::dashboard;
1515
pub use crate::utils::examples;
1616
// Color formatting utilities
1717
pub use crate::utils::color;
18+
19+
/// Type alias for progress callback functions
20+
///
21+
/// This type is used throughout the codebase for functions that report progress
22+
/// with a percentage (0-100) and a status message.
23+
pub type ProgressCallback = Box<dyn Fn(u8, &str) + Send>;

src/utils/dashboard.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ impl DashboardManager {
206206
}
207207
2 => {
208208
println!(
209-
"Monitoring {} nodes with refresh rate of {} seconds",
210-
"[node_count]", 5
209+
"Monitoring [node_count] nodes with refresh rate of {} seconds",
210+
5
211211
);
212212
Ok(())
213213
}
@@ -246,4 +246,4 @@ pub fn run_dashboard(
246246
commitment_config: CommitmentConfig,
247247
) -> Result<(), Box<dyn Error>> {
248248
crate::utils::nodes::run_dashboard(client, commitment_config, 1)
249-
}
249+
}

src/utils/nodes.rs

Lines changed: 140 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -403,26 +403,17 @@ pub fn list_all_nodes(
403403

404404
// Apply SVM filter if provided
405405
if let Some(svm) = svm_filter {
406-
nodes = nodes
407-
.into_iter()
408-
.filter(|node| node.svm_type == svm)
409-
.collect();
406+
nodes.retain(|node| node.svm_type == svm);
410407
}
411408

412409
// Apply network filter if not "all"
413410
if network_filter != "all" {
414-
nodes = nodes
415-
.into_iter()
416-
.filter(|node| node.network.to_string() == network_filter)
417-
.collect();
411+
nodes.retain(|node| node.network.to_string() == network_filter);
418412
}
419413

420414
// Apply node type filter if not "all"
421415
if node_type_filter != "all" {
422-
nodes = nodes
423-
.into_iter()
424-
.filter(|node| node.node_type == node_type_filter)
425-
.collect();
416+
nodes.retain(|node| node.node_type == node_type_filter);
426417
}
427418

428419
// Apply status filter if not "all"
@@ -435,10 +426,7 @@ pub fn list_all_nodes(
435426
_ => NodeStatus::Running, // Default to running if invalid
436427
};
437428

438-
nodes = nodes
439-
.into_iter()
440-
.filter(|node| node.status == status)
441-
.collect();
429+
nodes.retain(|node| node.status == status);
442430
}
443431

444432
// Sort nodes by SVM type by default
@@ -453,39 +441,133 @@ pub fn list_all_nodes(
453441
Ok(nodes)
454442
}
455443

444+
/// Configuration for deploying a node
445+
pub struct DeployNodeConfig {
446+
/// SVM type
447+
pub svm_type: String,
448+
/// Node type (validator or RPC)
449+
pub node_type: String,
450+
/// Network type
451+
pub network: NetworkType,
452+
/// Node name
453+
pub name: String,
454+
/// Host
455+
pub host: String,
456+
/// Port
457+
pub port: u16,
458+
/// Authentication method
459+
pub auth_method: AuthMethod,
460+
/// Installation directory
461+
pub install_dir: String,
462+
/// Progress callback function
463+
pub progress_callback: Option<crate::prelude::ProgressCallback>,
464+
}
465+
466+
impl std::fmt::Debug for DeployNodeConfig {
467+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
468+
f.debug_struct("DeployNodeConfig")
469+
.field("svm_type", &self.svm_type)
470+
.field("node_type", &self.node_type)
471+
.field("network", &self.network)
472+
.field("name", &self.name)
473+
.field("host", &self.host)
474+
.field("port", &self.port)
475+
.field("auth_method", &self.auth_method)
476+
.field("install_dir", &self.install_dir)
477+
.field("progress_callback", &if self.progress_callback.is_some() { "Some(ProgressCallback)" } else { "None" })
478+
.finish()
479+
}
480+
}
481+
482+
impl Clone for DeployNodeConfig {
483+
fn clone(&self) -> Self {
484+
Self {
485+
svm_type: self.svm_type.clone(),
486+
node_type: self.node_type.clone(),
487+
network: self.network,
488+
name: self.name.clone(),
489+
host: self.host.clone(),
490+
port: self.port,
491+
auth_method: self.auth_method.clone(),
492+
install_dir: self.install_dir.clone(),
493+
progress_callback: None, // Progress callback can't be cloned, so we set it to None
494+
}
495+
}
496+
}
497+
498+
impl DeployNodeConfig {
499+
/// Create a new deploy node configuration with minimal required parameters
500+
pub fn new(svm_type: &str, node_type: &str, network: NetworkType) -> Self {
501+
Self {
502+
svm_type: svm_type.to_string(),
503+
node_type: node_type.to_string(),
504+
network,
505+
name: format!("{}-{}-{}", svm_type, node_type, network),
506+
host: "localhost".to_string(),
507+
port: 22,
508+
auth_method: AuthMethod::Password {
509+
username: "root".to_string(),
510+
password: "".to_string(),
511+
},
512+
install_dir: "/opt/osvm".to_string(),
513+
progress_callback: None,
514+
}
515+
}
516+
517+
/// Set node name
518+
pub fn with_name(mut self, name: &str) -> Self {
519+
self.name = name.to_string();
520+
self
521+
}
522+
523+
/// Set host
524+
pub fn with_host(mut self, host: &str) -> Self {
525+
self.host = host.to_string();
526+
self
527+
}
528+
529+
/// Set port
530+
pub fn with_port(mut self, port: u16) -> Self {
531+
self.port = port;
532+
self
533+
}
534+
535+
/// Set authentication method
536+
pub fn with_auth_method(mut self, auth_method: AuthMethod) -> Self {
537+
self.auth_method = auth_method;
538+
self
539+
}
540+
541+
/// Set installation directory
542+
pub fn with_install_dir(mut self, install_dir: &str) -> Self {
543+
self.install_dir = install_dir.to_string();
544+
self
545+
}
546+
547+
/// Set progress callback
548+
pub fn with_progress_callback(mut self, callback: crate::prelude::ProgressCallback) -> Self {
549+
self.progress_callback = Some(callback);
550+
self
551+
}
552+
}
553+
456554
/// Deploy a new node
457555
///
458556
/// # Arguments
459557
/// * `client` - RPC client
460-
/// * `svm_type` - SVM type
461-
/// * `node_type` - Node type (validator or RPC)
462-
/// * `network` - Network type
463-
/// * `name` - Node name
464-
/// * `host` - Host
465-
/// * `port` - Port
466-
/// * `auth_method` - Authentication method
467-
/// * `install_dir` - Installation directory
468-
/// * `progress_callback` - Progress callback function
558+
/// * `config` - Deployment configuration
469559
///
470560
/// # Returns
471561
/// * `Result<NodeInfo, Box<dyn Error>>` - Node information or error
472562
pub async fn deploy_node(
473563
client: &RpcClient,
474-
svm_type: &str,
475-
node_type: &str,
476-
network: NetworkType,
477-
name: &str,
478-
host: &str,
479-
port: u16,
480-
auth_method: AuthMethod,
481-
install_dir: &str,
482-
progress_callback: Option<Box<dyn Fn(u8, &str) + Send>>,
564+
config: DeployNodeConfig,
483565
) -> Result<NodeInfo, Box<dyn Error>> {
484566
// Get SVM information
485-
let svm_info = get_svm_info(client, svm_type, CommitmentConfig::confirmed())?;
567+
let svm_info = get_svm_info(client, &config.svm_type, CommitmentConfig::confirmed())?;
486568

487569
// Check if the SVM supports the requested node type
488-
let can_install = match node_type {
570+
let can_install = match config.node_type.as_str() {
489571
"validator" => svm_info.can_install_validator,
490572
"rpc" => svm_info.can_install_rpc,
491573
_ => false,
@@ -494,33 +576,33 @@ pub async fn deploy_node(
494576
if !can_install {
495577
return Err(Box::new(NodeError::InvalidConfig(format!(
496578
"SVM '{}' does not support installing a {} node",
497-
svm_type, node_type
579+
config.svm_type, config.node_type
498580
))));
499581
}
500582

501583
// Check if the network exists for this SVM
502-
let network_name = network.to_string();
584+
let network_name = config.network.to_string();
503585
if !svm_info.networks.contains_key(&network_name) {
504586
return Err(Box::new(NodeError::InvalidConfig(format!(
505587
"Network '{}' does not exist for SVM '{}'",
506-
network_name, svm_type
588+
network_name, config.svm_type
507589
))));
508590
}
509591

510592
// Create server configuration
511593
let server_config = ServerConfig {
512-
host: host.to_string(),
513-
port,
514-
auth: auth_method,
515-
install_dir: install_dir.to_string(),
594+
host: config.host.clone(),
595+
port: config.port,
596+
auth: config.auth_method,
597+
install_dir: config.install_dir.clone(),
516598
};
517599

518600
// Create deployment configuration
519601
let deployment_config = DeploymentConfig {
520-
svm_type: svm_type.to_string(),
521-
node_type: node_type.to_string(),
522-
network,
523-
node_name: name.to_string(),
602+
svm_type: config.svm_type.clone(),
603+
node_type: config.node_type.clone(),
604+
network: config.network,
605+
node_name: config.name.clone(),
524606
rpc_url: None, // Will be set by the deployment process
525607
additional_params: HashMap::new(),
526608
version: None,
@@ -531,20 +613,20 @@ pub async fn deploy_node(
531613
};
532614

533615
// Deploy the node
534-
deploy_svm_node(server_config.clone(), deployment_config, progress_callback).await?;
616+
deploy_svm_node(server_config.clone(), deployment_config, config.progress_callback).await?;
535617

536618
// Create node information
537619
let node_info = NodeInfo {
538-
id: format!("{}-{}-{}-{}", svm_type, node_type, network, host),
620+
id: format!("{}-{}-{}-{}", config.svm_type, config.node_type, config.network, config.host),
539621
system_metrics: None,
540-
svm_type: svm_type.to_string(),
541-
node_type: node_type.to_string(),
542-
network,
543-
name: name.to_string(),
544-
host: host.to_string(),
622+
svm_type: config.svm_type.clone(),
623+
node_type: config.node_type.clone(),
624+
network: config.network,
625+
name: config.name.clone(),
626+
host: config.host.clone(),
545627
status: NodeStatus::Running,
546-
rpc_url: if node_type == "rpc" {
547-
Some(format!("http://{}:8899", host))
628+
rpc_url: if config.node_type == "rpc" {
629+
Some(format!("http://{}:8899", config.host))
548630
} else {
549631
None
550632
},
@@ -1191,7 +1273,7 @@ pub fn display_node_status(node_id: &str, status: &NodeStatus, verbosity: u8) {
11911273
println!("{}", "--------------------".blue());
11921274
println!(
11931275
" Status check performed at: {}",
1194-
chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string()
1276+
chrono::Local::now().format("%Y-%m-%d %H:%M:%S")
11951277
);
11961278
}
11971279
}
@@ -1262,4 +1344,4 @@ impl SshClientExt for crate::utils::ssh_deploy::SshClient {
12621344

12631345
Ok(())
12641346
}
1265-
}
1347+
}

0 commit comments

Comments
 (0)