#![allow(clippy::large_enum_variant)]
#[cfg(feature = "message_signer")]
use crate::handlers::offline::{SignMessageCommand, VerifyMessageCommand};
use crate::handlers::{
config::{ListWalletsCommand, SaveConfigCommand},
descriptor::DescriptorCommand,
key::{DeriveKeyCommand, GenerateKeyCommand, RestoreKeyCommand},
offline::{
BalanceCommand, BumpFeeCommand, CombinePsbtCommand, CreateTxCommand, ExtractPsbtCommand,
FinalizePsbtCommand, LockUtxoCommand, LockedUtxosCommand, NewAddressCommand,
PoliciesCommand, PublicDescriptorCommand, SignCommand, TransactionsCommand,
UnlockUtxoCommand, UnspentCommand, UnusedAddressCommand,
},
};
#[cfg(feature = "silent-payments")]
use crate::handlers::{descriptor::SilentPaymentCodeCommand, offline::CreateSpTxCommand};
#[cfg(any(
feature = "electrum",
feature = "esplora",
feature = "rpc",
feature = "cbf"
))]
use crate::{
client::ClientType,
handlers::online::{
BroadcastCommand, FullScanCommand, PayjoinHistoryCommand, ReceivePayjoinCommand,
ResumePayjoinCommand, SendPayjoinCommand, SyncCommand,
},
};
#[cfg(feature = "compiler")]
use crate::handlers::descriptor::CompileCommand;
#[cfg(any(feature = "sqlite", feature = "redb"))]
use crate::persister::DatabaseType;
use bdk_wallet::bitcoin::Network;
use clap::{Args, Parser, Subcommand, value_parser};
use clap_complete::Shell;
#[cfg(feature = "dns_payment")]
use crate::handlers::dns::{CreateDnsTxCommand, ResolveDnsRecipientCommand};
#[cfg(any(feature = "electrum", feature = "esplora", feature = "rpc"))]
use crate::utils::parse_proxy_auth;
#[derive(PartialEq, Clone, Debug, Parser)]
#[command(version, about, long_about = None)]
pub struct CliOpts {
#[arg(
env = "NETWORK",
short = 'n',
long = "network",
default_value = "testnet",
value_parser = value_parser!(Network)
)]
pub network: Network,
#[arg(env = "DATADIR", short = 'd', long = "datadir")]
pub datadir: Option<std::path::PathBuf>,
#[command(subcommand)]
pub subcommand: CliSubCommand,
}
#[derive(Debug, Subcommand, Clone, PartialEq)]
#[command(rename_all = "snake")]
pub enum CliSubCommand {
Wallet {
#[arg(env = "WALLET_NAME", short = 'w', long = "wallet", required = true)]
wallet: String,
#[command(subcommand)]
subcommand: WalletSubCommand,
},
Key {
#[clap(subcommand)]
subcommand: KeySubCommand,
},
#[cfg(feature = "compiler")]
#[clap(long_about = "Miniscript policy compiler")]
Compile(CompileCommand),
#[cfg(feature = "repl")]
Repl {
#[arg(env = "WALLET_NAME", short = 'w', long = "wallet", required = true)]
wallet: String,
},
Descriptor(DescriptorCommand),
Wallets(ListWalletsCommand),
#[command(verbatim_doc_comment)]
Completions {
#[arg(value_enum)]
shell: Shell,
},
#[cfg(feature = "silent-payments")]
SilentPaymentCode(SilentPaymentCodeCommand),
#[cfg(feature = "dns_payment")]
ResolveDnsRecipient(ResolveDnsRecipientCommand),
}
#[derive(Debug, Subcommand, Clone, PartialEq)]
pub enum WalletSubCommand {
Config(SaveConfigCommand),
#[cfg(any(
feature = "electrum",
feature = "esplora",
feature = "cbf",
feature = "rpc"
))]
#[command(flatten)]
OnlineWalletSubCommand(OnlineWalletSubCommand),
#[command(flatten)]
OfflineWalletSubCommand(OfflineWalletSubCommand),
}
#[derive(Debug, Args, Clone, PartialEq, Eq)]
pub struct WalletOpts {
#[arg(skip)]
pub wallet: Option<String>,
#[arg(env = "EXT_DESCRIPTOR", short = 'e', long, required = true)]
pub ext_descriptor: String,
#[arg(env = "INT_DESCRIPTOR", short = 'i', long)]
pub int_descriptor: Option<String>,
#[cfg(any(
feature = "electrum",
feature = "esplora",
feature = "rpc",
feature = "cbf"
))]
#[arg(env = "CLIENT_TYPE", short = 'c', long, value_enum, required = true)]
pub client_type: ClientType,
#[cfg(any(feature = "sqlite", feature = "redb"))]
#[arg(env = "DATABASE_TYPE", short = 'd', long, value_enum, required = true)]
pub database_type: DatabaseType,
#[cfg(any(feature = "electrum", feature = "esplora", feature = "rpc"))]
#[arg(env = "SERVER_URL", short = 'u', long, required = true)]
pub url: String,
#[cfg(feature = "electrum")]
#[arg(env = "ELECTRUM_BATCH_SIZE", short = 'b', long, default_value = "10")]
pub batch_size: usize,
#[cfg(feature = "esplora")]
#[arg(
env = "ESPLORA_PARALLEL_REQUESTS",
short = 'p',
long,
default_value = "5"
)]
pub parallel_requests: usize,
#[cfg(feature = "rpc")]
#[arg(
env = "USER:PASSWD",
short = 'a',
long,
value_parser = parse_proxy_auth,
default_value = "user:password",
)]
pub basic_auth: (String, String),
#[cfg(feature = "rpc")]
#[arg(env = "COOKIE")]
pub cookie: Option<String>,
#[cfg(feature = "cbf")]
#[clap(flatten)]
pub compactfilter_opts: CompactFilterOpts,
#[cfg(any(feature = "electrum", feature = "esplora"))]
#[command(flatten)]
pub proxy_opts: ProxyOpts,
}
#[cfg(any(feature = "electrum", feature = "esplora"))]
#[derive(Debug, Args, Clone, PartialEq, Eq)]
pub struct ProxyOpts {
#[arg(env = "PROXY_ADDRS:PORT", long = "proxy")]
pub proxy: Option<String>,
#[arg(env = "PROXY_USER:PASSWD", long="proxy_auth", value_parser = parse_proxy_auth)]
pub proxy_auth: Option<(String, String)>,
#[arg(
env = "PROXY_RETRIES",
short = 'r',
long = "retries",
default_value = "5"
)]
pub retries: u8,
#[arg(env = "PROXY_TIMEOUT", short = 't', long = "timeout")]
pub timeout: Option<u8>,
}
#[cfg(feature = "cbf")]
#[derive(Debug, Args, Clone, PartialEq, Eq)]
pub struct CompactFilterOpts {
#[clap(name = "CONNECTIONS", long = "cbf-conn-count", default_value = "2", value_parser = value_parser!(u8).range(1..=15))]
pub conn_count: u8,
}
#[derive(Debug, Subcommand, Clone, PartialEq)]
#[command(rename_all = "snake")]
pub enum OfflineWalletSubCommand {
NewAddress(NewAddressCommand),
UnusedAddress(UnusedAddressCommand),
Unspent(UnspentCommand),
Transactions(TransactionsCommand),
Balance(BalanceCommand),
CreateTx(CreateTxCommand),
#[cfg(feature = "silent-payments")]
CreateSpTx(CreateSpTxCommand),
BumpFee(BumpFeeCommand),
Policies(PoliciesCommand),
PublicDescriptor(PublicDescriptorCommand),
Sign(SignCommand),
ExtractPsbt(ExtractPsbtCommand),
FinalizePsbt(FinalizePsbtCommand),
CombinePsbt(CombinePsbtCommand),
#[cfg(feature = "message_signer")]
SignMessage(SignMessageCommand),
#[cfg(feature = "message_signer")]
VerifyMessage(VerifyMessageCommand),
LockUtxo(LockUtxoCommand),
UnlockUtxo(UnlockUtxoCommand),
LockedUtxos(LockedUtxosCommand),
#[cfg(feature = "dns_payment")]
CreateDnsTx(CreateDnsTxCommand),
}
#[derive(Debug, Subcommand, Clone, PartialEq, Eq)]
#[command(rename_all = "snake")]
#[cfg(any(
feature = "electrum",
feature = "esplora",
feature = "cbf",
feature = "rpc"
))]
pub enum OnlineWalletSubCommand {
FullScan(FullScanCommand),
Sync(SyncCommand),
Broadcast(BroadcastCommand),
ReceivePayjoin(ReceivePayjoinCommand),
SendPayjoin(SendPayjoinCommand),
ResumePayjoin(ResumePayjoinCommand),
PayjoinHistory(PayjoinHistoryCommand),
}
#[derive(Debug, Subcommand, Clone, PartialEq, Eq)]
pub enum KeySubCommand {
Generate(GenerateKeyCommand),
Restore(RestoreKeyCommand),
Derive(DeriveKeyCommand),
}
#[cfg(any(feature = "repl", target_arch = "wasm32"))]
#[derive(Debug, Parser)]
#[command(rename_all = "lower", multicall = true)]
pub enum ReplSubCommand {
Wallet {
#[command(subcommand)]
subcommand: WalletSubCommand,
},
Key {
#[command(subcommand)]
subcommand: KeySubCommand,
},
Descriptor(DescriptorCommand),
Exit,
}