From: Alekos Filini Date: Sun, 10 May 2020 15:42:02 +0000 (+0200) Subject: [descriptors] Transform a descriptor into its "public" version X-Git-Tag: 0.1.0-beta.1~27 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/struct.EncoderStringWriter.html?a=commitdiff_plain;h=abd508dfe7f91d0870f2b98865c68a626c38f880;p=bdk-cli [descriptors] Transform a descriptor into its "public" version --- diff --git a/examples/repl.rs b/examples/repl.rs index 5a78bed..5eaf3f4 100644 --- a/examples/repl.rs +++ b/examples/repl.rs @@ -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); + } } } diff --git a/src/cli.rs b/src/cli.rs index 5b24544..9dc37a3 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -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 => "".into(), + }; + let internal = match wallet.public_descriptor(ScriptType::Internal)? { + Some(desc) => format!("{}", desc), + 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();