]> Untitled Git - bdk-cli/commitdiff
[cli] Add a flag to build PSBTs for offline signers
authorAlekos Filini <alekos.filini@gmail.com>
Mon, 30 Nov 2020 13:23:19 +0000 (14:23 +0100)
committerAlekos Filini <alekos.filini@gmail.com>
Tue, 1 Dec 2020 13:53:00 +0000 (14:53 +0100)
The `--offline_signer` flag forces the addition of `non_witness_utxo` and the full
witness and redeem script for every output, which makes it easier for the signer
to identify the change output.

Closes #199

src/cli.rs

index 350614ee8ac63dbe3d6c9e32f8f948872dbd214f..87a5ff682df964bde8ac7516c5cd497ad090b3f9 100644 (file)
@@ -163,6 +163,12 @@ pub fn make_cli_subcommands<'a, 'b>() -> App<'a, 'b> {
                         .help("Selects which policy should be used to satisfy the internal descriptor")
                         .takes_value(true)
                         .number_of_values(1),
+                )
+                .arg(
+                    Arg::with_name("offline_signer")
+                        .long("offline_signer")
+                        .help("Make a PSBT that can be signed by offline signers and hardware wallets. Forces the addition of `non_witness_utxo` and more details to let the signer identify the change output.")
+                        .takes_value(false),
                 ),
         )
         .subcommand(
@@ -210,6 +216,12 @@ pub fn make_cli_subcommands<'a, 'b>() -> App<'a, 'b> {
                         .value_name("SATS_VBYTE")
                         .help("The new targeted fee rate in sat/vbyte")
                         .takes_value(true),
+                )
+                .arg(
+                    Arg::with_name("offline_signer")
+                        .long("offline_signer")
+                        .help("Make a PSBT that can be signed by offline signers and hardware wallets. Forces the addition of `non_witness_utxo` and more details to let the signer identify the change output.")
+                        .takes_value(false),
                 ),
         )
         .subcommand(
@@ -444,6 +456,12 @@ where
             tx_builder = tx_builder.enable_rbf();
         }
 
+        if sub_matches.is_present("offline_signer") {
+            tx_builder = tx_builder
+                .force_non_witness_utxo()
+                .include_output_redeem_witness_script();
+        }
+
         if let Some(fee_rate) = sub_matches.value_of("fee_rate") {
             let fee_rate = f32::from_str(fee_rate).map_err(|s| Error::Generic(s.to_string()))?;
             tx_builder = tx_builder.fee_rate(FeeRate::from_sat_per_vb(fee_rate));
@@ -495,6 +513,12 @@ where
             tx_builder = tx_builder.maintain_single_recipient();
         }
 
+        if sub_matches.is_present("offline_signer") {
+            tx_builder = tx_builder
+                .force_non_witness_utxo()
+                .include_output_redeem_witness_script();
+        }
+
         if let Some(utxos) = sub_matches.values_of("utxos") {
             let utxos = utxos
                 .map(|i| parse_outpoint(i))