From 62910238c9cca225b6e300ac537869551fbc18e2 Mon Sep 17 00:00:00 2001 From: Deep Mehta Date: Mon, 5 Jun 2023 14:27:02 +0530 Subject: [PATCH 01/10] chore: rename --- .gitmodules | 2 +- Cargo.toml | 2 +- cli/Cargo.toml | 2 +- cli/src/lib.rs | 2 +- client/Cargo.toml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.gitmodules b/.gitmodules index 6e313c95b8..8b6f056eab 100644 --- a/.gitmodules +++ b/.gitmodules @@ -15,4 +15,4 @@ [submodule "tests/auction-house"] path = tests/auction-house url = https://github.com/armaniferrante/auction-house - branch = armani/pda + branch = armani/pda \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index b5cd7e7f8a..fba3468024 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,4 +17,4 @@ members = [ exclude = [ "tests/swap/deps/openbook-dex", "tests/cfo/deps/openbook-dex", -] +] \ No newline at end of file diff --git a/cli/Cargo.toml b/cli/Cargo.toml index cb0cb80e5b..fb9f76ff1e 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -9,7 +9,7 @@ description = "Anchor CLI" license = "Apache-2.0" [[bin]] -name = "anchor" +name = "xanchor" path = "src/bin/main.rs" [features] diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 37b53121ad..9320123ee7 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -3063,7 +3063,7 @@ fn deploy( let keypair = cfg.provider.wallet.to_string(); // Deploy the programs. - println!("Deploying workspace: {url}"); + println!("Deploying cluster: {url}"); println!("Upgrade authority: {keypair}"); for mut program in cfg.read_all_programs()? { diff --git a/client/Cargo.toml b/client/Cargo.toml index 2f950e0afb..6d7160f32b 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -19,4 +19,4 @@ solana-client = "1.14.7" solana-sdk = "1.14.16" solana-account-decoder = "1.14.16" thiserror = "1.0.20" -url = "2.2.2" +url = "2.2.2" \ No newline at end of file From f12c84cf2a53dae6d3f9a42706202a01dee82d5f Mon Sep 17 00:00:00 2001 From: Deep Mehta Date: Mon, 5 Jun 2023 14:34:54 +0530 Subject: [PATCH 02/10] chore: If the specified programme cannot be found, display a message. --- cli/src/lib.rs | 114 +++++++++++++++++++++++++++---------------------- 1 file changed, 62 insertions(+), 52 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 9320123ee7..827d0cf3ef 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -3066,70 +3066,80 @@ fn deploy( println!("Deploying cluster: {url}"); println!("Upgrade authority: {keypair}"); + let mut program_found = true; // Flag to track if the specified program is found + for mut program in cfg.read_all_programs()? { if let Some(single_prog_str) = &program_str { let program_name = program.path.file_name().unwrap().to_str().unwrap(); + if single_prog_str.as_str() != program_name { - continue; + program_found = false; + } else { + program_found = true; } } - let binary_path = program.binary_path().display().to_string(); + if program_found { + let binary_path = program.binary_path().display().to_string(); - println!( - "Deploying program {:?}...", - program.path.file_name().unwrap().to_str().unwrap() - ); - - println!("Program path: {binary_path}..."); - - let (program_keypair_filepath, program_id) = match &program_keypair { - Some(path) => ( - path.clone(), - solana_sdk::signature::read_keypair_file(path) - .map_err(|_| anyhow!("Unable to read keypair file"))? - .pubkey(), - ), - None => ( - program.keypair_file()?.path().display().to_string(), - program.pubkey()?, - ), - }; - - // Send deploy transactions. - let exit = std::process::Command::new("solana") - .arg("program") - .arg("deploy") - .arg("--url") - .arg(&url) - .arg("--keypair") - .arg(&keypair) - .arg("--program-id") - .arg(strip_workspace_prefix(program_keypair_filepath)) - .arg(strip_workspace_prefix(binary_path)) - .stdout(Stdio::inherit()) - .stderr(Stdio::inherit()) - .output() - .expect("Must deploy"); - if !exit.status.success() { - println!("There was a problem deploying: {exit:?}."); - std::process::exit(exit.status.code().unwrap_or(1)); - } + println!( + "Deploying program {:?}...", + program.path.file_name().unwrap().to_str().unwrap() + ); + println!("Program path: {binary_path}..."); + + let (program_keypair_filepath, program_id) = match &program_keypair { + Some(path) => ( + path.clone(), + solana_sdk::signature::read_keypair_file(path) + .map_err(|_| anyhow!("Unable to read keypair file"))? + .pubkey(), + ), + None => ( + program.keypair_file()?.path().display().to_string(), + program.pubkey()?, + ), + }; - if let Some(mut idl) = program.idl.as_mut() { - // Add program address to the IDL. - idl.metadata = Some(serde_json::to_value(IdlTestMetadata { - address: program_id.to_string(), - })?); + // Send deploy transactions. + let exit = std::process::Command::new("solana") + .arg("program") + .arg("deploy") + .arg("--url") + .arg(&url) + .arg("--keypair") + .arg(&keypair) + .arg("--program-id") + .arg(strip_workspace_prefix(program_keypair_filepath)) + .arg(strip_workspace_prefix(binary_path)) + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .output() + .expect("Must deploy"); + if !exit.status.success() { + println!("There was a problem deploying: {exit:?}."); + std::process::exit(exit.status.code().unwrap_or(1)); + } - // Persist it. - let idl_out = PathBuf::from("target/idl") - .join(&idl.name) - .with_extension("json"); - write_idl(idl, OutFile::File(idl_out))?; + if let Some(mut idl) = program.idl.as_mut() { + // Add program address to the IDL. + idl.metadata = Some(serde_json::to_value(IdlTestMetadata { + address: program_id.to_string(), + })?); + + // Persist it. + let idl_out = PathBuf::from("target/idl") + .join(&idl.name) + .with_extension("json"); + write_idl(idl, OutFile::File(idl_out))?; + } } } - println!("Deploy success"); + if program_str.is_some() && !program_found { + println!("Specified program not found"); + } else { + println!("Deploy success"); + } Ok(()) }) From 60ee3aef40900057ba075df7f2b4e8e9c38ec23b Mon Sep 17 00:00:00 2001 From: Deep Mehta Date: Mon, 5 Jun 2023 14:41:50 +0530 Subject: [PATCH 03/10] chore: add documentation --- cli/src/lib.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 827d0cf3ef..7a97f74cb7 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -3058,6 +3058,8 @@ fn deploy( program_str: Option, program_keypair: Option, ) -> Result<()> { + + // Execute the code within the workspace with_workspace(cfg_override, |cfg| { let url = cluster_url(cfg, &cfg.test_validator); let keypair = cfg.provider.wallet.to_string(); @@ -3069,15 +3071,18 @@ fn deploy( let mut program_found = true; // Flag to track if the specified program is found for mut program in cfg.read_all_programs()? { + // If a program string is provided if let Some(single_prog_str) = &program_str { let program_name = program.path.file_name().unwrap().to_str().unwrap(); + // Check if the provided program string matches the program name if single_prog_str.as_str() != program_name { program_found = false; } else { program_found = true; } } + if program_found { let binary_path = program.binary_path().display().to_string(); @@ -3085,7 +3090,7 @@ fn deploy( "Deploying program {:?}...", program.path.file_name().unwrap().to_str().unwrap() ); - println!("Program path: {binary_path}..."); + println!("Program path: {}...", binary_path); let (program_keypair_filepath, program_id) = match &program_keypair { Some(path) => ( @@ -3100,7 +3105,7 @@ fn deploy( ), }; - // Send deploy transactions. + // Send deploy transactions using the Solana CLI let exit = std::process::Command::new("solana") .arg("program") .arg("deploy") @@ -3115,6 +3120,8 @@ fn deploy( .stderr(Stdio::inherit()) .output() .expect("Must deploy"); + + // Check if deployment was successful if !exit.status.success() { println!("There was a problem deploying: {exit:?}."); std::process::exit(exit.status.code().unwrap_or(1)); @@ -3135,6 +3142,7 @@ fn deploy( } } + // If a program string is provided but not found if program_str.is_some() && !program_found { println!("Specified program not found"); } else { From df6e655ebf7e78741ac64b18825065ac1349c87c Mon Sep 17 00:00:00 2001 From: Deep Mehta Date: Mon, 5 Jun 2023 14:42:25 +0530 Subject: [PATCH 04/10] chore: cargo fmt --- cli/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 7a97f74cb7..0ab23ba74b 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -3058,7 +3058,6 @@ fn deploy( program_str: Option, program_keypair: Option, ) -> Result<()> { - // Execute the code within the workspace with_workspace(cfg_override, |cfg| { let url = cluster_url(cfg, &cfg.test_validator); @@ -3082,7 +3081,7 @@ fn deploy( program_found = true; } } - + if program_found { let binary_path = program.binary_path().display().to_string(); From 539cc7a95b28983286d8697dbb62f0a48965cfe0 Mon Sep 17 00:00:00 2001 From: Deep Mehta Date: Mon, 5 Jun 2023 15:09:14 +0530 Subject: [PATCH 05/10] chore: formate println --- cli/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 0ab23ba74b..4299a2387d 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -3064,8 +3064,8 @@ fn deploy( let keypair = cfg.provider.wallet.to_string(); // Deploy the programs. - println!("Deploying cluster: {url}"); - println!("Upgrade authority: {keypair}"); + println!("Deploying cluster: {}", url); + println!("Upgrade authority: {}", keypair); let mut program_found = true; // Flag to track if the specified program is found From c1d780609904246d17489dc79f99faec4dc59bfa Mon Sep 17 00:00:00 2001 From: Deep Mehta Date: Mon, 5 Jun 2023 15:23:10 +0530 Subject: [PATCH 06/10] update cargo.toml --- cli/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 4ac23f39c9..d21749c75b 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -9,7 +9,7 @@ description = "Anchor CLI" license = "Apache-2.0" [[bin]] -name = "xanchor" +name = "anchor" path = "src/bin/main.rs" [features] From 33328dcf5886833562ff8a3e1767a473256594cb Mon Sep 17 00:00:00 2001 From: Deep Mehta Date: Mon, 5 Jun 2023 17:02:11 +0530 Subject: [PATCH 07/10] update EOF --- .gitmodules | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 8b6f056eab..6e313c95b8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -15,4 +15,4 @@ [submodule "tests/auction-house"] path = tests/auction-house url = https://github.com/armaniferrante/auction-house - branch = armani/pda \ No newline at end of file + branch = armani/pda diff --git a/Cargo.toml b/Cargo.toml index fba3468024..b5cd7e7f8a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,4 +17,4 @@ members = [ exclude = [ "tests/swap/deps/openbook-dex", "tests/cfo/deps/openbook-dex", -] \ No newline at end of file +] From 4662cbba21af2e2dfc9a76f265ab0b6aa0b161b3 Mon Sep 17 00:00:00 2001 From: Deep Mehta Date: Mon, 5 Jun 2023 17:04:15 +0530 Subject: [PATCH 08/10] update EOF --- client/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/Cargo.toml b/client/Cargo.toml index 48a5d3ebd1..b4aed6db20 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -19,4 +19,4 @@ solana-client = "1.14.7" solana-sdk = "<1.17.0" solana-account-decoder = "<1.17.0" thiserror = "1.0.20" -url = "2.2.2" \ No newline at end of file +url = "2.2.2" From 930ccfda96cfd55afbc88620763848f337f36a15 Mon Sep 17 00:00:00 2001 From: Deep Mehta Date: Mon, 5 Jun 2023 20:51:54 +0530 Subject: [PATCH 09/10] chore: break the loop if given program found --- cli/src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 163ea7f48c..2e3a505fcb 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -3140,6 +3140,12 @@ fn deploy( write_idl(idl, OutFile::File(idl_out))?; } } + + + // Break the loop if a specific programme is discovered and program_str is not None. + if program_str.is_some() && program_found { + break; + } } // If a program string is provided but not found From ed264588fd177fee2d8f173976c5bde2223ccea0 Mon Sep 17 00:00:00 2001 From: Deep Mehta Date: Mon, 5 Jun 2023 21:41:46 +0530 Subject: [PATCH 10/10] chore: cargo fmt --- cli/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 2e3a505fcb..64fd99064c 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -3140,7 +3140,6 @@ fn deploy( write_idl(idl, OutFile::File(idl_out))?; } } - // Break the loop if a specific programme is discovered and program_str is not None. if program_str.is_some() && program_found {