From: valued mammal Date: Sun, 16 Feb 2025 15:35:31 +0000 (-0500) Subject: refactor(example_cli): clean up CLI docs X-Git-Tag: wallet-1.2.0~2^2 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/%22example_cli/enum.Commands.html/enum.Language.html?a=commitdiff_plain;h=c855a0942bafe1211308d887e8bc0de82c95cc68;p=bdk refactor(example_cli): clean up CLI docs `--psbt` is a required arg for both Sign, Extract. Change example_esplora --parallel-requests to 2 for easier testing, debugging. --- diff --git a/example-crates/example_cli/src/lib.rs b/example-crates/example_cli/src/lib.rs index b60a88f7..2cb27849 100644 --- a/example-crates/example_cli/src/lib.rs +++ b/example-crates/example_cli/src/lib.rs @@ -147,8 +147,10 @@ pub enum PsbtCmd { /// Create a new PSBT. New { /// Amount to send in satoshis + #[clap(required = true)] value: u64, /// Recipient address + #[clap(required = true)] address: Address, /// Set the feerate of the tx (sat/vbyte) #[clap(long, short, default_value = "1.0")] @@ -168,20 +170,21 @@ pub enum PsbtCmd { }, /// Sign with a hot signer Sign { - /// PSBT - #[clap(long)] - psbt: Option, - /// Private descriptor - #[clap(long, short = 'd')] + /// Private descriptor [env: DESCRIPTOR=] + #[clap(long, short)] descriptor: Option, + /// PSBT + #[clap(long, short, required = true)] + psbt: String, }, /// Extract transaction Extract { /// PSBT + #[clap(long, short, required = true)] psbt: String, /// Whether to try broadcasting the tx - #[clap(long, short = 'b')] - try_broadcast: bool, + #[clap(long, short)] + broadcast: bool, #[clap(flatten)] chain_specific: S, }, @@ -451,7 +454,7 @@ pub fn handle_commands( chain: &Mutex, db: &Mutex>, network: Network, - broadcast: impl FnOnce(S, &Transaction) -> anyhow::Result<()>, + broadcast_fn: impl FnOnce(S, &Transaction) -> anyhow::Result<()>, cmd: Commands, ) -> anyhow::Result<()> { match cmd { @@ -671,7 +674,7 @@ pub fn handle_commands( Ok(()) } PsbtCmd::Sign { psbt, descriptor } => { - let mut psbt = Psbt::from_str(psbt.unwrap_or_default().as_str())?; + let mut psbt = Psbt::from_str(&psbt)?; let desc_str = match descriptor { Some(s) => s, @@ -709,20 +712,20 @@ pub fn handle_commands( Ok(()) } PsbtCmd::Extract { - try_broadcast, + broadcast, chain_specific, psbt, } => { - let mut psbt = Psbt::from_str(psbt.as_str())?; + let mut psbt = Psbt::from_str(&psbt)?; psbt.finalize_mut(&Secp256k1::new()) .map_err(|errors| anyhow::anyhow!("failed to finalize PSBT {errors:?}"))?; let tx = psbt.extract_tx()?; - if try_broadcast { + if broadcast { let mut graph = graph.lock().unwrap(); - match broadcast(chain_specific, &tx) { + match broadcast_fn(chain_specific, &tx) { Ok(_) => { println!("Broadcasted Tx: {}", tx.compute_txid()); diff --git a/example-crates/example_esplora/src/main.rs b/example-crates/example_esplora/src/main.rs index b6a58e4c..8ef39c2f 100644 --- a/example-crates/example_esplora/src/main.rs +++ b/example-crates/example_esplora/src/main.rs @@ -87,7 +87,7 @@ impl EsploraArgs { #[derive(Parser, Debug, Clone, PartialEq)] pub struct ScanOptions { /// Max number of concurrent esplora server requests. - #[clap(long, default_value = "5")] + #[clap(long, default_value = "2")] pub parallel_requests: usize, }