Browse Source

cli: add verifiable option in deploy command (#2705)

Aoi Kurokawa 1 year ago
parent
commit
c58d2f232e
3 changed files with 24 additions and 6 deletions
  1. 1 0
      CHANGELOG.md
  2. 8 2
      cli/src/config.rs
  3. 15 4
      cli/src/lib.rs

+ 1 - 0
CHANGELOG.md

@@ -13,6 +13,7 @@ The minor version will be incremented upon a breaking change and the patch versi
 ### Features
 
 - cli: Allow force `init` and `new` ([#2698](https://github.com/coral-xyz/anchor/pull/2698)).
+- cli: Add verifiable option when `deploy` ([#2705](https://github.com/coral-xyz/anchor/pull/2705)).
 
 ### Fixes
 

+ 8 - 2
cli/src/config.rs

@@ -1257,10 +1257,16 @@ impl Program {
         Ok(WithPath::new(file, path))
     }
 
-    pub fn binary_path(&self) -> PathBuf {
+    pub fn binary_path(&self, verifiable: bool) -> PathBuf {
+        let path = if verifiable {
+            format!("target/verifiable/{}.so", self.lib_name)
+        } else {
+            format!("target/deploy/{}.so", self.lib_name)
+        };
+
         std::env::current_dir()
             .expect("Must have current dir")
-            .join(format!("target/deploy/{}.so", self.lib_name))
+            .join(path)
     }
 }
 

+ 15 - 4
cli/src/lib.rs

@@ -246,6 +246,9 @@ pub enum Command {
         /// Keypair of the program (filepath) (requires program-name)
         #[clap(long, requires = "program_name")]
         program_keypair: Option<String>,
+        /// If true, deploy from path target/verifiable
+        #[clap(short, long)]
+        verifiable: bool,
     },
     /// Runs the deploy migration script.
     Migrate,
@@ -691,7 +694,13 @@ fn process_command(opts: Opts) -> Result<()> {
         Command::Deploy {
             program_name,
             program_keypair,
-        } => deploy(&opts.cfg_override, program_name, program_keypair),
+            verifiable,
+        } => deploy(
+            &opts.cfg_override,
+            program_name,
+            program_keypair,
+            verifiable,
+        ),
         Command::Expand {
             program_name,
             cargo_args,
@@ -3042,7 +3051,7 @@ fn test(
         // In either case, skip the deploy if the user specifies.
         let is_localnet = cfg.provider.cluster == Cluster::Localnet;
         if (!is_localnet || skip_local_validator) && !skip_deploy {
-            deploy(cfg_override, None, None)?;
+            deploy(cfg_override, None, None, false)?;
         }
         let mut is_first_suite = true;
         if cfg.scripts.get("test").is_some() {
@@ -3204,7 +3213,8 @@ fn validator_flags(
 
     let mut flags = Vec::new();
     for mut program in cfg.read_all_programs()? {
-        let binary_path = program.binary_path().display().to_string();
+        let verifiable = false;
+        let binary_path = program.binary_path(verifiable).display().to_string();
 
         // Use the [programs.cluster] override and fallback to the keypair
         // files if no override is given.
@@ -3574,6 +3584,7 @@ fn deploy(
     cfg_override: &ConfigOverride,
     program_name: Option<String>,
     program_keypair: Option<String>,
+    verifiable: bool,
 ) -> Result<()> {
     // Execute the code within the workspace
     with_workspace(cfg_override, |cfg| {
@@ -3585,7 +3596,7 @@ fn deploy(
         println!("Upgrade authority: {}", keypair);
 
         for mut program in cfg.get_programs(program_name)? {
-            let binary_path = program.binary_path().display().to_string();
+            let binary_path = program.binary_path(verifiable).display().to_string();
 
             println!("Deploying program {:?}...", program.lib_name);
             println!("Program path: {}...", binary_path);