[descriptors] Transform a descriptor into its "public" version

This commit is contained in:
Alekos Filini
2020-05-10 17:42:02 +02:00
parent 0e432f3b26
commit c1b01e4d8c
6 changed files with 267 additions and 106 deletions

View 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();