]> Untitled Git - bdk-cli/commitdiff
[descriptors] Transform a descriptor into its "public" version
authorAlekos Filini <alekos.filini@gmail.com>
Sun, 10 May 2020 15:42:02 +0000 (17:42 +0200)
committerAlekos Filini <alekos.filini@gmail.com>
Sun, 10 May 2020 15:46:54 +0000 (17:46 +0200)
examples/repl.rs
src/cli.rs

index 5a78bed3ff5f724f16f7c48aa0ecbc1913083319..5eaf3f4275931c86b24f4a7b71efb36743bb9454 100644 (file)
@@ -101,7 +101,12 @@ async fn main() {
                         continue;
                     }
 
-                    cli::handle_matches(&Arc::clone(&wallet), matches.unwrap()).await;
+                    if let Some(s) = cli::handle_matches(&Arc::clone(&wallet), matches.unwrap())
+                        .await
+                        .unwrap()
+                    {
+                        println!("{}", s);
+                    }
                 }
                 Err(ReadlineError::Interrupted) => continue,
                 Err(ReadlineError::Eof) => break,
@@ -114,6 +119,8 @@ async fn main() {
 
     // rl.save_history("history.txt").unwrap();
     } else {
-        cli::handle_matches(&wallet, matches).await;
+        if let Some(s) = cli::handle_matches(&wallet, matches).await.unwrap() {
+            println!("{}", s);
+        }
     }
 }
index 5b24544ca70cfcd16416c64e2c1b9273dbee8d4a..9dc37a3206272dcbd511091a900ab9557dde4b4c 100644 (file)
@@ -119,6 +119,10 @@ pub fn make_cli_subcommands<'a, 'b>() -> App<'a, 'b> {
             SubCommand::with_name("policies")
                 .about("Returns the available spending policies for the descriptor")
             )
+        .subcommand(
+            SubCommand::with_name("public_descriptor")
+                .about("Returns the public version of the wallet's descriptor(s)")
+            )
         .subcommand(
             SubCommand::with_name("sign")
                 .about("Signs and tries to finalize a PSBT")
@@ -271,6 +275,20 @@ where
             serde_json::to_string(&wallet.policies(ScriptType::External)?).unwrap(),
             serde_json::to_string(&wallet.policies(ScriptType::Internal)?).unwrap(),
         )))
+    } else if let Some(_sub_matches) = matches.subcommand_matches("public_descriptor") {
+        let external = match wallet.public_descriptor(ScriptType::External)? {
+            Some(desc) => format!("{}", desc),
+            None => "<NONE>".into(),
+        };
+        let internal = match wallet.public_descriptor(ScriptType::Internal)? {
+            Some(desc) => format!("{}", desc),
+            None => "<NONE>".into(),
+        };
+
+        Ok(Some(format!(
+            "External: {}\nInternal:{}",
+            external, internal
+        )))
     } else if let Some(sub_matches) = matches.subcommand_matches("sign") {
         let psbt = base64::decode(sub_matches.value_of("psbt").unwrap()).unwrap();
         let psbt: PartiallySignedTransaction = deserialize(&psbt).unwrap();