]> Untitled Git - bdk-cli/commitdiff
Reverse the recipient parsing string
authorrajarshimaitra <rajarshi149@gmail.com>
Sun, 30 Oct 2022 12:33:48 +0000 (18:03 +0530)
committerrajarshimaitra <rajarshi149@gmail.com>
Sat, 19 Nov 2022 11:18:08 +0000 (16:48 +0530)
Vector parsing is possible with multiple flags.

src/commands.rs
src/handlers.rs

index e30ee80a20eb5330dc3202a9e8f10d3b78159873..66b07f0865cf623eeadd097b250922e13d80f675 100644 (file)
@@ -16,9 +16,8 @@
 use clap::{AppSettings, Args, Parser, Subcommand};
 
 use bdk::bitcoin::util::bip32::{DerivationPath, ExtendedPrivKey};
-use bdk::bitcoin::{Address, Network, OutPoint};
+use bdk::bitcoin::{Address, Network, OutPoint, Script};
 
-use crate::utils::parse_outpoint;
 #[cfg(any(
     feature = "compact_filters",
     feature = "electrum",
@@ -26,6 +25,7 @@ use crate::utils::parse_outpoint;
     feature = "rpc"
 ))]
 use crate::utils::parse_proxy_auth;
+use crate::utils::{parse_outpoint, parse_recipient};
 
 #[derive(PartialEq, Clone, Debug, Parser)]
 /// The BDK Command Line Wallet App
@@ -370,8 +370,8 @@ pub enum OfflineWalletSubCommand {
         /// Adds a recipient to the transaction.
         // Clap Doesn't support complex vector parsing https://github.com/clap-rs/clap/issues/1704.
         // Address and amount parsing is done at run time in handler function.
-        #[clap(name = "ADDRESS:SAT", long = "to", required = true)]
-        recipients: Vec<String>,
+        #[clap(name = "ADDRESS:SAT", long = "to", required = true, value_parser = parse_recipient)]
+        recipients: Vec<(Script, u64)>,
         /// Sends all the funds (or all the selected utxos). Requires only one recipient with value 0.
         #[clap(long = "send_all", short = 'a')]
         send_all: bool,
@@ -964,7 +964,7 @@ mod test {
         let cli_args = vec!["bdk-cli", "--network", "testnet", "wallet",
                             "--descriptor", "wpkh(tpubDEnoLuPdBep9bzw5LoGYpsxUQYheRQ9gcgrJhJEcdKFB9cWQRyYmkCyRoTqeD4tJYiVVgt6A3rN6rWn9RYhR9sBsGxji29LYWHuKKbdb1ev/0/*)",
                             "--change_descriptor", "wpkh(tpubDEnoLuPdBep9bzw5LoGYpsxUQYheRQ9gcgrJhJEcdKFB9cWQRyYmkCyRoTqeD4tJYiVVgt6A3rN6rWn9RYhR9sBsGxji29LYWHuKKbdb1ev/1/*)",
-                            "create_tx", "--to", "n2Z3YNXtceeJhFkTknVaNjT1mnCGWesykJ:123456", //Fix Me: Clap isn't parsing vectors correctly "mjDZ34icH4V2k9GmC8niCrhzVuR3z8Mgkf:78910",
+                            "create_tx", "--to", "n2Z3YNXtceeJhFkTknVaNjT1mnCGWesykJ:123456", "--to", "mjDZ34icH4V2k9GmC8niCrhzVuR3z8Mgkf:78910",
                             "--utxos","87345e46bfd702d24d54890cc094d08a005f773b27c8f965dfe0eb1e23eef88e:1",
                             "--utxos","87345e46bfd702d24d54890cc094d08a005f773b27c8f965dfe0eb1e23eef88e:2",
                             "--add_string","Hello BDK",
@@ -972,6 +972,14 @@ mod test {
 
         let cli_opts = CliOpts::parse_from(&cli_args);
 
+        let script1 = Address::from_str("n2Z3YNXtceeJhFkTknVaNjT1mnCGWesykJ")
+            .unwrap()
+            .script_pubkey();
+
+        let script2 = Address::from_str("mjDZ34icH4V2k9GmC8niCrhzVuR3z8Mgkf")
+            .unwrap()
+            .script_pubkey();
+
         let outpoint1 = OutPoint::from_str(
             "87345e46bfd702d24d54890cc094d08a005f773b27c8f965dfe0eb1e23eef88e:1",
         )
@@ -1024,7 +1032,7 @@ mod test {
                     },
                 },
                 subcommand: WalletSubCommand::OfflineWalletSubCommand(CreateTx {
-                    recipients: vec!["n2Z3YNXtceeJhFkTknVaNjT1mnCGWesykJ:123456".to_string()],
+                    recipients: vec![(script1, 123456), (script2, 78910)],
                     send_all: false,
                     enable_rbf: false,
                     offline_signer: false,
index fbc080e3093b0dd2d6973ab67192d345c5ffc226..459586c626702bb5f2143fa67ab3e6bea02f6fb4 100644 (file)
@@ -124,21 +124,12 @@ where
             add_data,
             add_string,
         } => {
-            // Handle string to recipient parsing
-            let parsed_recipients = recipients
-                .iter()
-                .map(|recpt| parse_recipient(recpt))
-                .collect::<Result<Vec<_>, _>>()
-                .map_err(Error::Generic)?;
-
             let mut tx_builder = wallet.build_tx();
 
             if send_all {
-                tx_builder
-                    .drain_wallet()
-                    .drain_to(parsed_recipients[0].0.clone());
+                tx_builder.drain_wallet().drain_to(recipients[0].0.clone());
             } else {
-                tx_builder.set_recipients(parsed_recipients);
+                tx_builder.set_recipients(recipients);
             }
 
             if enable_rbf {