Skip to content

Commit

Permalink
ref(example_cli): clean up CLI docs
Browse files Browse the repository at this point in the history
Extract command takes an optional `--psbt` arg
(even though it's required) which is more consistent
with Sign and makes the UX more clear.

Change `example_esplora` parallel requests to 2, as it
can make syncing easier to debug.
  • Loading branch information
ValuedMammal committed Feb 25, 2025
1 parent 7cfbe8f commit f0824e2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
27 changes: 15 additions & 12 deletions example-crates/example_cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@ pub enum PsbtCmd<S: clap::Args> {
/// Create a new PSBT.
New {
/// Amount to send in satoshis
#[clap(required = true)]
value: u64,
/// Recipient address
#[clap(required = true)]
address: Address<NetworkUnchecked>,
/// Set the feerate of the tx (sat/vbyte)
#[clap(long, short, default_value = "1.0")]
Expand All @@ -168,20 +170,21 @@ pub enum PsbtCmd<S: clap::Args> {
},
/// Sign with a hot signer
Sign {
/// Private descriptor [env: DESCRIPTOR=]
#[clap(long, short)]
descriptor: Option<String>,
/// PSBT
#[clap(long)]
#[clap(long, short)]
psbt: Option<String>,
/// Private descriptor
#[clap(long, short = 'd')]
descriptor: Option<String>,
},
/// Extract transaction
Extract {
/// PSBT
psbt: String,
#[clap(long, short)]
psbt: Option<String>,
/// Whether to try broadcasting the tx
#[clap(long, short = 'b')]
try_broadcast: bool,
#[clap(long, short)]
broadcast: bool,
#[clap(flatten)]
chain_specific: S,
},
Expand Down Expand Up @@ -451,7 +454,7 @@ pub fn handle_commands<CS: clap::Subcommand, S: clap::Args>(
chain: &Mutex<LocalChain>,
db: &Mutex<Store<ChangeSet>>,
network: Network,
broadcast: impl FnOnce(S, &Transaction) -> anyhow::Result<()>,
broadcast_fn: impl FnOnce(S, &Transaction) -> anyhow::Result<()>,
cmd: Commands<CS, S>,
) -> anyhow::Result<()> {
match cmd {
Expand Down Expand Up @@ -709,20 +712,20 @@ pub fn handle_commands<CS: clap::Subcommand, S: clap::Args>(
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.unwrap_or_default())?;
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());

Expand Down
2 changes: 1 addition & 1 deletion example-crates/example_esplora/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down

0 comments on commit f0824e2

Please sign in to comment.