Skip to content

Commit

Permalink
cli: add address commands
Browse files Browse the repository at this point in the history
  • Loading branch information
edouardparis committed Nov 14, 2023
1 parent 34b33dd commit 0d2f618
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions cli/src/bin/hwi.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::error::Error;

use async_hwi::AddressScript;
use async_hwi_cli::command;

use bitcoin::{
Expand All @@ -25,6 +26,8 @@ struct Args {

#[derive(Debug, Subcommand)]
enum Commands {
#[command(subcommand)]
Address(AddressCommands),
#[command(subcommand)]
Device(DeviceCommands),
#[command(subcommand)]
Expand All @@ -35,6 +38,20 @@ enum Commands {
Xpub(XpubCommands),
}

#[derive(Debug, Subcommand)]
enum AddressCommands {
Display {
#[arg(long)]
index: u32,
#[arg(long)]
wallet_name: Option<String>,
#[arg(long)]
wallet_policy: Option<String>,
#[arg(long)]
hmac: Option<String>,
},
}

#[derive(Debug, Subcommand)]
enum DeviceCommands {
List,
Expand Down Expand Up @@ -76,6 +93,30 @@ enum XpubCommands {
async fn main() -> Result<(), Box<dyn Error>> {
let args = Args::parse();
match args.command {
Commands::Address(AddressCommands::Display {
index,
wallet_name,
wallet_policy,
hmac,
}) => {
for device in command::list(
args.network,
Some(command::Wallet {
name: wallet_name.as_ref(),
policy: &wallet_policy.unwrap(),
hmac: hmac.as_ref(),
}),
)
.await?
{
if let Some(fg) = args.fingerprint {
if fg != device.get_master_fingerprint().await? {
continue;
}
}
device.display_address(&AddressScript::WSH, index).await?;
}
}
Commands::Device(DeviceCommands::List) => {
for device in command::list(args.network, None).await? {
eprintln!(
Expand Down

0 comments on commit 0d2f618

Please sign in to comment.