Skip to content

Commit

Permalink
Move wallet commands under a wallet subcommand
Browse files Browse the repository at this point in the history
The PCZT commands are left at the top level, because only a couple of
them are connected to a wallet.
  • Loading branch information
str4d committed Dec 19, 2024
1 parent 7447c4d commit 8a396f3
Show file tree
Hide file tree
Showing 17 changed files with 424 additions and 367 deletions.
653 changes: 345 additions & 308 deletions src/cli.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/commands/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{

use super::select_account;

impl crate::cli::Balance {
impl crate::cli::wallet::Balance {
pub(crate) async fn run(self, wallet_dir: Option<String>) -> Result<(), anyhow::Error> {
let params = get_wallet_network(wallet_dir.as_ref())?;

Expand Down
2 changes: 1 addition & 1 deletion src/commands/enhance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async fn fetch_transaction(
.transpose()
}

impl crate::cli::Enhance {
impl crate::cli::wallet::Enhance {
pub(crate) async fn run(self, wallet_dir: Option<String>) -> Result<(), anyhow::Error> {
let params = get_wallet_network(wallet_dir.as_ref())?;
let (_, db_data) = get_db_paths(wallet_dir.as_ref());
Expand Down
2 changes: 1 addition & 1 deletion src/commands/import_ufvk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use zip32::fingerprint::SeedFingerprint;

use crate::{data::get_db_paths, error, remote::tor_client};

impl crate::cli::ImportUfvk {
impl crate::cli::wallet::ImportUfvk {
pub(crate) async fn run(self, wallet_dir: Option<String>) -> Result<(), anyhow::Error> {
let (network, ufvk) = unified::Ufvk::decode(&self.ufvk)?;
let ufvk = UnifiedFullViewingKey::parse(&ufvk).map_err(|e| anyhow!("{e}"))?;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use zcash_protocol::consensus::BlockHeight;

use crate::{config::WalletConfig, data::init_dbs, error, remote::tor_client};

impl crate::cli::Init {
impl crate::cli::wallet::Init {
pub(crate) async fn run(self, wallet_dir: Option<String>) -> Result<(), anyhow::Error> {
let opts = self;
let params = consensus::Network::from(opts.network);
Expand Down
4 changes: 2 additions & 2 deletions src/commands/init_fvk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use zip32::fingerprint::SeedFingerprint;

use crate::{config::WalletConfig, data::init_dbs, remote::tor_client};

impl crate::cli::InitFvk {
impl crate::cli::wallet::InitFvk {
pub(crate) async fn run(self, wallet_dir: Option<String>) -> Result<(), anyhow::Error> {
let opts = self;

Expand Down Expand Up @@ -55,7 +55,7 @@ impl crate::cli::InitFvk {
.try_into()
.expect("block heights must fit into u32");

let birthday = crate::cli::Init::get_wallet_birthday(
let birthday = crate::cli::wallet::Init::get_wallet_birthday(
client,
opts.birthday
.unwrap_or(chain_tip.saturating_sub(100))
Expand Down
2 changes: 1 addition & 1 deletion src/commands/list_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use zcash_client_sqlite::WalletDb;

use crate::{config::get_wallet_network, data::get_db_paths};

impl crate::cli::ListAccounts {
impl crate::cli::wallet::ListAccounts {
pub(crate) fn run(self, wallet_dir: Option<String>) -> anyhow::Result<()> {
let params = get_wallet_network(wallet_dir.as_ref())?;
let (_, db_data) = get_db_paths(wallet_dir.as_ref());
Expand Down
2 changes: 1 addition & 1 deletion src/commands/list_addresses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use zcash_keys::keys::UnifiedAddressRequest;

use crate::{commands::select_account, config::get_wallet_network, data::get_db_paths};

impl crate::cli::ListAddresses {
impl crate::cli::wallet::ListAddresses {
pub(crate) fn run(self, wallet_dir: Option<String>) -> anyhow::Result<()> {
let params = get_wallet_network(wallet_dir.as_ref())?;
let (_, db_data) = get_db_paths(wallet_dir.as_ref());
Expand Down
2 changes: 1 addition & 1 deletion src/commands/list_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use zcash_protocol::{

use crate::{data::get_db_paths, ui::format_zec};

impl crate::cli::ListTx {
impl crate::cli::wallet::ListTx {
pub(crate) fn run(self, wallet_dir: Option<String>) -> anyhow::Result<()> {
let (_, db_data) = get_db_paths(wallet_dir);

Expand Down
2 changes: 1 addition & 1 deletion src/commands/list_unspent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{config::get_wallet_network, data::get_db_paths, error, ui::format_ze

use super::select_account;

impl crate::cli::ListUnspent {
impl crate::cli::wallet::ListUnspent {
pub(crate) fn run(self, wallet_dir: Option<String>) -> Result<(), anyhow::Error> {
let params = get_wallet_network(wallet_dir.as_ref())?;

Expand Down
2 changes: 1 addition & 1 deletion src/commands/propose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
MIN_CONFIRMATIONS,
};

impl crate::cli::Propose {
impl crate::cli::wallet::Propose {
pub(crate) async fn run(self, wallet_dir: Option<String>) -> Result<(), anyhow::Error> {
let params = get_wallet_network(wallet_dir.as_ref())?;

Expand Down
13 changes: 8 additions & 5 deletions src/commands/reset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
remote::tor_client,
};

impl crate::cli::Reset {
impl crate::cli::wallet::Reset {
pub(crate) async fn run(self, wallet_dir: Option<String>) -> Result<(), anyhow::Error> {
// Load the wallet network, seed, and birthday from disk.
let mut config = WalletConfig::read(wallet_dir.as_ref())?;
Expand Down Expand Up @@ -51,9 +51,12 @@ impl crate::cli::Reset {
)
};

let birthday =
crate::cli::Init::get_wallet_birthday(client, config.birthday(), Some(chain_tip))
.await?;
let birthday = crate::cli::wallet::Init::get_wallet_birthday(
client,
config.birthday(),
Some(chain_tip),
)
.await?;

// Erase the wallet state (excluding key material).
erase_wallet_state(wallet_dir.as_ref()).await;
Expand All @@ -63,7 +66,7 @@ impl crate::cli::Reset {
config.decrypt(identities.iter().map(|i| i.as_ref() as _))?;

// Re-initialize the wallet state.
crate::cli::Init::init_dbs(
crate::cli::wallet::Init::init_dbs(
params,
wallet_dir.as_ref(),
account_name.as_deref().unwrap_or(""),
Expand Down
2 changes: 1 addition & 1 deletion src/commands/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::{
MIN_CONFIRMATIONS,
};

impl crate::cli::Send {
impl crate::cli::wallet::Send {
pub(crate) async fn run(self, wallet_dir: Option<String>) -> Result<(), anyhow::Error> {
let mut config = WalletConfig::read(wallet_dir.as_ref())?;
let params = config.network();
Expand Down
2 changes: 1 addition & 1 deletion src/commands/shield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
commands::select_account, config::WalletConfig, data::get_db_paths, error, remote::tor_client,
};

impl crate::cli::Shield {
impl crate::cli::wallet::Shield {
pub(crate) async fn run(self, wallet_dir: Option<String>) -> Result<(), anyhow::Error> {
let mut config = WalletConfig::read(wallet_dir.as_ref())?;
let params = config.network();
Expand Down
2 changes: 1 addition & 1 deletion src/commands/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ mod defrag;

const BATCH_SIZE: u32 = 10_000;

impl crate::cli::Sync {
impl crate::cli::wallet::Sync {
pub(crate) async fn run(
self,
mut shutdown: ShutdownListener,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
error,
};

impl crate::cli::Upgrade {
impl crate::cli::wallet::Upgrade {
pub(crate) fn run(self, wallet_dir: Option<String>) -> Result<(), anyhow::Error> {
let params = get_wallet_network(wallet_dir.as_ref())?;

Expand Down
95 changes: 56 additions & 39 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,18 @@ fn main() -> Result<(), anyhow::Error> {
let tui_logger: Option<()> = None;
#[cfg(feature = "tui")]
let tui_logger = match opts.command {
Some(Command::Sync(cli::Sync { defrag: true, .. })) => {
Some(Command::Wallet(cli::Wallet {
command: cli::wallet::Command::Sync(cli::wallet::Sync { defrag: true, .. }),
..
})) => {
tui_logger::init_logger(level_filter.parse().unwrap())?;
Some(tui_logger::tracing_subscriber_layer())
}
#[cfg(feature = "pczt-qr")]
Some(Command::Pczt(cli::Pczt::ToQr(cli::pczt::ToQr { tui: true, .. }))) => {
Some(Command::Pczt(cli::Pczt {
command: cli::pczt::Command::ToQr(cli::pczt::ToQr { tui: true, .. }),
..
})) => {
tui_logger::init_logger(level_filter.parse().unwrap())?;
Some(tui_logger::tracing_subscriber_layer())
}
Expand Down Expand Up @@ -80,41 +86,49 @@ fn main() -> Result<(), anyhow::Error> {
let shutdown = ShutdownListener::new();

match opts.command {
Some(Command::Init(command)) => command.run(opts.wallet_dir).await,
Some(Command::InitFvk(command)) => command.run(opts.wallet_dir).await,
Some(Command::Reset(command)) => command.run(opts.wallet_dir).await,
Some(Command::ImportUfvk(command)) => command.run(opts.wallet_dir).await,
Some(Command::Upgrade(command)) => command.run(opts.wallet_dir),
Some(Command::Sync(command)) => {
command
.run(
shutdown,
opts.wallet_dir,
#[cfg(feature = "tui")]
tui,
)
.await
}
Some(Command::Enhance(command)) => command.run(opts.wallet_dir).await,
Some(Command::Balance(command)) => command.run(opts.wallet_dir).await,
Some(Command::ListAccounts(command)) => command.run(opts.wallet_dir),
Some(Command::ListAddresses(command)) => command.run(opts.wallet_dir),
Some(Command::ListTx(command)) => command.run(opts.wallet_dir),
Some(Command::ListUnspent(command)) => command.run(opts.wallet_dir),
Some(Command::Shield(command)) => command.run(opts.wallet_dir).await,
Some(Command::Propose(command)) => command.run(opts.wallet_dir).await,
Some(Command::Send(command)) => command.run(opts.wallet_dir).await,
Some(Command::Pczt(command)) => match command {
cli::Pczt::Create(command) => command.run(opts.wallet_dir).await,
cli::Pczt::Shield(command) => command.run(opts.wallet_dir).await,
cli::Pczt::Inspect(command) => command.run(opts.wallet_dir).await,
cli::Pczt::Redact(command) => command.run().await,
cli::Pczt::Prove(command) => command.run(opts.wallet_dir).await,
cli::Pczt::Sign(command) => command.run(opts.wallet_dir).await,
cli::Pczt::Combine(command) => command.run().await,
cli::Pczt::Send(command) => command.run(opts.wallet_dir).await,
Some(Command::Wallet(cli::Wallet {
wallet_dir,
command,
})) => match command {
cli::wallet::Command::Init(command) => command.run(wallet_dir).await,
cli::wallet::Command::InitFvk(command) => command.run(wallet_dir).await,
cli::wallet::Command::Reset(command) => command.run(wallet_dir).await,
cli::wallet::Command::ImportUfvk(command) => command.run(wallet_dir).await,
cli::wallet::Command::Upgrade(command) => command.run(wallet_dir),
cli::wallet::Command::Sync(command) => {
command
.run(
shutdown,
wallet_dir,
#[cfg(feature = "tui")]
tui,
)
.await
}
cli::wallet::Command::Enhance(command) => command.run(wallet_dir).await,
cli::wallet::Command::Balance(command) => command.run(wallet_dir).await,
cli::wallet::Command::ListAccounts(command) => command.run(wallet_dir),
cli::wallet::Command::ListAddresses(command) => command.run(wallet_dir),
cli::wallet::Command::ListTx(command) => command.run(wallet_dir),
cli::wallet::Command::ListUnspent(command) => command.run(wallet_dir),
cli::wallet::Command::Shield(command) => command.run(wallet_dir).await,
cli::wallet::Command::Propose(command) => command.run(wallet_dir).await,
cli::wallet::Command::Send(command) => command.run(wallet_dir).await,
},
Some(Command::Pczt(cli::Pczt {
wallet_dir,
command,
})) => match command {
cli::pczt::Command::Create(command) => command.run(wallet_dir).await,
cli::pczt::Command::Shield(command) => command.run(wallet_dir).await,
cli::pczt::Command::Inspect(command) => command.run(wallet_dir).await,
cli::pczt::Command::Redact(command) => command.run().await,
cli::pczt::Command::Prove(command) => command.run(wallet_dir).await,
cli::pczt::Command::Sign(command) => command.run(wallet_dir).await,
cli::pczt::Command::Combine(command) => command.run().await,
cli::pczt::Command::Send(command) => command.run(wallet_dir).await,
#[cfg(feature = "pczt-qr")]
cli::Pczt::ToQr(command) => {
cli::pczt::Command::ToQr(command) => {
command
.run(
shutdown,
Expand All @@ -124,11 +138,14 @@ fn main() -> Result<(), anyhow::Error> {
.await
}
#[cfg(feature = "pczt-qr")]
cli::Pczt::FromQr(command) => command.run(shutdown).await,
cli::pczt::Command::FromQr(command) => command.run(shutdown).await,
},
#[cfg(feature = "pczt-qr")]
Some(Command::Keystone(command)) => match command {
cli::Keystone::Enroll(command) => command.run(shutdown, opts.wallet_dir).await,
Some(Command::Keystone(cli::Keystone {
wallet_dir,
command,
})) => match command {
cli::keystone::Command::Enroll(command) => command.run(shutdown, wallet_dir).await,
},
None => Ok(()),
}
Expand Down

0 comments on commit 8a396f3

Please sign in to comment.