From f8c0f2e0206bc53c1577f758eb7926ce87d3e035 Mon Sep 17 00:00:00 2001 From: rajarshimaitra Date: Sun, 2 Oct 2022 19:25:18 +0530 Subject: [PATCH] Update recipient parsing in handlers. Clap doesn't support custom vector parsing. Not so ideal work around is to handle recipient parsing in create_tx handler at run time. --- src/handlers.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/handlers.rs b/src/handlers.rs index c630571..fbc080e 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -24,7 +24,7 @@ use crate::commands::*; use crate::utils::*; use bdk::{database::BatchDatabase, wallet::AddressIndex, Error, FeeRate, KeychainKind, Wallet}; -use structopt::StructOpt; +use clap::Parser; use bdk::bitcoin::consensus::encode::{deserialize, serialize, serialize_hex}; #[cfg(any( @@ -124,12 +124,21 @@ where add_data, add_string, } => { + // Handle string to recipient parsing + let parsed_recipients = recipients + .iter() + .map(|recpt| parse_recipient(recpt)) + .collect::, _>>() + .map_err(Error::Generic)?; + let mut tx_builder = wallet.build_tx(); if send_all { - tx_builder.drain_wallet().drain_to(recipients[0].0.clone()); + tx_builder + .drain_wallet() + .drain_to(parsed_recipients[0].0.clone()); } else { - tx_builder.set_recipients(recipients); + tx_builder.set_recipients(parsed_recipients); } if enable_rbf { -- 2.49.0