From 4f64d9ff05aac0781ddf03f828d7c649c0d04137 Mon Sep 17 00:00:00 2001 From: Eitan Chatav Date: Fri, 10 Oct 2025 14:01:10 -0700 Subject: [PATCH] Remove CLI Remove dead code for CLI app. --- zexcavator-cli/Cargo.toml | 21 ---- zexcavator-cli/src/application.rs | 89 ---------------- zexcavator-cli/src/bin/uzw-parser/main.rs | 11 -- zexcavator-cli/src/commands.rs | 92 ---------------- zexcavator-cli/src/commands/export.rs | 72 ------------- zexcavator-cli/src/commands/parse.rs | 124 ---------------------- zexcavator-cli/src/config.rs | 36 ------- zexcavator-cli/src/error.rs | 70 ------------ zexcavator-cli/src/lib.rs | 22 ---- zexcavator-cli/src/prelude.rs | 9 -- 10 files changed, 546 deletions(-) delete mode 100644 zexcavator-cli/Cargo.toml delete mode 100644 zexcavator-cli/src/application.rs delete mode 100644 zexcavator-cli/src/bin/uzw-parser/main.rs delete mode 100644 zexcavator-cli/src/commands.rs delete mode 100644 zexcavator-cli/src/commands/export.rs delete mode 100644 zexcavator-cli/src/commands/parse.rs delete mode 100644 zexcavator-cli/src/config.rs delete mode 100644 zexcavator-cli/src/error.rs delete mode 100644 zexcavator-cli/src/lib.rs delete mode 100644 zexcavator-cli/src/prelude.rs diff --git a/zexcavator-cli/Cargo.toml b/zexcavator-cli/Cargo.toml deleted file mode 100644 index 53d931e..0000000 --- a/zexcavator-cli/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "zexcavator-cli" -version = "0.1.0" -edition = "2024" - -[dependencies] -zexcavator-lib = { workspace = true } -clap = { workspace = true } -serde = { workspace = true, features = ["serde_derive"] } -thiserror = { workspace = true } -bc-envelope = { workspace = true } -tokio = { workspace = true } -http.workspace = true -zingolib = { workspace = true } -pepper-sync = { workspace = true } -rustls = { workspace = true } -abscissa_core = { workspace = true } - -[dev-dependencies] -abscissa_core = { workspace = true, features = ["testing"] } -once_cell = { workspace = true } diff --git a/zexcavator-cli/src/application.rs b/zexcavator-cli/src/application.rs deleted file mode 100644 index 6d757f8..0000000 --- a/zexcavator-cli/src/application.rs +++ /dev/null @@ -1,89 +0,0 @@ -//! ZexCavatorCli Abscissa Application - -use crate::{commands::EntryPoint, config::ZexCavatorCliConfig}; -use abscissa_core::{ - Application, FrameworkError, StandardPaths, - application::{self, AppCell}, - config::{self, CfgCell}, - trace, -}; - -/// Application state -pub static APP: AppCell = AppCell::new(); - -/// ZexCavatorCli Application -#[derive(Debug)] -pub struct ZexCavatorCli { - /// Application configuration. - config: CfgCell, - - /// Application state. - state: application::State, -} - -/// Initialize a new application instance. -/// -/// By default no configuration is loaded, and the framework state is -/// initialized to a default, empty state (no components, threads, etc). -impl Default for ZexCavatorCli { - fn default() -> Self { - Self { - config: CfgCell::default(), - state: application::State::default(), - } - } -} - -impl Application for ZexCavatorCli { - /// Entrypoint command for this application. - type Cmd = EntryPoint; - - /// Application configuration. - type Cfg = ZexCavatorCliConfig; - - /// Paths to resources within the application. - type Paths = StandardPaths; - - /// Accessor for application configuration. - fn config(&self) -> config::Reader { - self.config.read() - } - - /// Borrow the application state immutably. - fn state(&self) -> &application::State { - &self.state - } - - /// Register all components used by this application. - /// - /// If you would like to add additional components to your application - /// beyond the default ones provided by the framework, this is the place - /// to do so. - fn register_components(&mut self, command: &Self::Cmd) -> Result<(), FrameworkError> { - let framework_components = self.framework_components(command)?; - let mut app_components = self.state.components_mut(); - app_components.register(framework_components) - } - - /// Post-configuration lifecycle callback. - /// - /// Called regardless of whether config is loaded to indicate this is the - /// time in app lifecycle when configuration would be loaded if - /// possible. - fn after_config(&mut self, config: Self::Cfg) -> Result<(), FrameworkError> { - // Configure components - let mut components = self.state.components_mut(); - components.after_config(&config)?; - self.config.set_once(config); - Ok(()) - } - - /// Get tracing configuration from command-line options - fn tracing_config(&self, command: &EntryPoint) -> trace::Config { - if command.verbose { - trace::Config::verbose() - } else { - trace::Config::default() - } - } -} diff --git a/zexcavator-cli/src/bin/uzw-parser/main.rs b/zexcavator-cli/src/bin/uzw-parser/main.rs deleted file mode 100644 index 9de847b..0000000 --- a/zexcavator-cli/src/bin/uzw-parser/main.rs +++ /dev/null @@ -1,11 +0,0 @@ -//! Main entry point for ZexCavatorCli - -#![deny(warnings, missing_docs, trivial_casts, unused_qualifications)] -#![forbid(unsafe_code)] - -use zexcavator_cli::application::APP; - -/// Boot ZexCavatorCli -fn main() { - abscissa_core::boot(&APP); -} diff --git a/zexcavator-cli/src/commands.rs b/zexcavator-cli/src/commands.rs deleted file mode 100644 index ee63518..0000000 --- a/zexcavator-cli/src/commands.rs +++ /dev/null @@ -1,92 +0,0 @@ -//! ZexCavatorCli Subcommands -//! -//! This is where you specify the subcommands of your application. -//! -//! The default application comes with two subcommands: -//! -//! - `start`: launches the application -//! - `--version`: print application version -//! -//! See the `impl Configurable` below for how to specify the path to the -//! application's configuration file. - -mod export; -mod parse; - -use self::export::ExportCmd; -use self::parse::ParseCmd; -use crate::config::ZexCavatorCliConfig; -use abscissa_core::{Command, Configurable, FrameworkError, Runnable, config::Override}; -use std::path::PathBuf; - -/// ZexCavatorCli Configuration Filename -pub const CONFIG_FILE: &str = "my_cool_app.toml"; - -/// ZexCavatorCli Subcommands -/// Subcommands need to be listed in an enum. -#[derive(clap::Parser, Command, Debug, Runnable)] -pub enum ZexCavatorCliCmd { - /// The `parse` subcommand - Parse(ParseCmd), - - /// The `export` subcommand - Export(ExportCmd), -} - -/// Entry point for the application. It needs to be a struct to allow using subcommands! -#[derive(clap::Parser, Command, Debug)] -#[command(author, about, version)] -pub struct EntryPoint { - #[command(subcommand)] - cmd: ZexCavatorCliCmd, - - /// Enable verbose logging - #[arg(short, long)] - pub verbose: bool, - - /// Use the specified config file - #[arg(short, long)] - pub config: Option, -} - -impl Runnable for EntryPoint { - fn run(&self) { - self.cmd.run() - } -} - -/// This trait allows you to define how application configuration is loaded. -impl Configurable for EntryPoint { - /// Location of the configuration file - fn config_path(&self) -> Option { - // Check if the config file exists, and if it does not, ignore it. - // If you'd like for a missing configuration file to be a hard error - // instead, always return `Some(CONFIG_FILE)` here. - let filename = self - .config - .as_ref() - .map(PathBuf::from) - .unwrap_or_else(|| CONFIG_FILE.into()); - - if filename.exists() { - Some(filename) - } else { - None - } - } - - /// Apply changes to the config after it's been loaded, e.g. overriding - /// values in a config file using command-line options. - /// - /// This can be safely deleted if you don't want to override config - /// settings from command-line options. - fn process_config( - &self, - config: ZexCavatorCliConfig, - ) -> Result { - match &self.cmd { - ZexCavatorCliCmd::Parse(cmd) => cmd.override_config(config), - ZexCavatorCliCmd::Export(cmd) => cmd.override_config(config), - } - } -} diff --git a/zexcavator-cli/src/commands/export.rs b/zexcavator-cli/src/commands/export.rs deleted file mode 100644 index 84d9d1e..0000000 --- a/zexcavator-cli/src/commands/export.rs +++ /dev/null @@ -1,72 +0,0 @@ -//! `parse` subcommand - example of how to write a subcommand - -use std::{path::PathBuf, str::FromStr}; - -use crate::{config::ZexCavatorCliConfig, prelude::APP}; -use abscissa_core::{Application, Command, FrameworkError, Runnable, config}; -use bc_envelope::Envelope; - -/// `export` subcommand -/// -/// The `Parser` proc macro generates an option parser based on the struct -/// definition, and is defined in the `clap` crate. See their documentation -/// for a more comprehensive example: -/// -/// -#[derive(clap::Parser, Command, Debug)] -pub struct ExportCmd { - /// A wallet file. Currently only ZecWallet and YWallet are supported. - #[arg(required = true, value_name = "INPUT_FILE")] - input_file: String, - - /// Where to save the ZeWIF file. - #[arg(value_name = "OUTPUT_FILE")] - output_file: Option, -} - -impl Runnable for ExportCmd { - /// Start the application. - fn run(&self) { - let config = APP.config(); - - let _output = config.output_file.to_str().unwrap(); - - let erp_envelope = - Envelope::new("").add_assertion("generates", ""); - - let zc_object: Envelope = Envelope::new("wallet").add_assertion("hasSeed", erp_envelope); - - // Extension version - let zc_extension = - zc_object.add_assertion(bc_envelope::known_values::VERSION_VALUE, "0.0.1"); - - let sample_envelope = Envelope::new("Alice") - .add_assertion("Knows", "Bob") - .add_attachment( - zc_extension, - "org.zingolabs", - Some("https://github.com/zingolabs/zexcavator/blob/main/docs/zewif-extension-spec.md"), - ); - - println!("{:}", Envelope::format_flat(&sample_envelope)); - todo!() - } -} - -impl config::Override for ExportCmd { - // Process the given command line options, overriding settings from - // a configuration file using explicit flags taken from command-line - // arguments. - fn override_config( - &self, - mut config: ZexCavatorCliConfig, - ) -> Result { - config.input_file = PathBuf::from_str(&self.input_file).unwrap(); - - if let Some(output_file) = &self.output_file { - config.output_file = PathBuf::from_str(output_file).unwrap(); - } - - Ok(config) - } -} diff --git a/zexcavator-cli/src/commands/parse.rs b/zexcavator-cli/src/commands/parse.rs deleted file mode 100644 index 459443c..0000000 --- a/zexcavator-cli/src/commands/parse.rs +++ /dev/null @@ -1,124 +0,0 @@ -//! `parse` subcommand - example of how to write a subcommand - -/// App-local prelude includes `app_reader()`/`app_writer()`/`app_config()` -/// accessors along with logging macros. Customize as you see fit. -use crate::prelude::*; - -use crate::config::ZexCavatorCliConfig; -use abscissa_core::{Command, FrameworkError, Runnable, config}; -use http::Uri; -use pepper_sync::sync::{SyncConfig, TransparentAddressDiscovery}; -use zexcavator_lib::parser::WalletParserFactory; -use zingolib::{ - config::{ChainType, load_clientconfig}, - lightclient, - wallet::{LightWallet, WalletBase, WalletSettings}, -}; - -/// `parse` subcommand -/// -/// The `Parser` proc macro generates an option parser based on the struct -/// definition, and is defined in the `clap` crate. See their documentation -/// for a more comprehensive example: -/// -/// -#[derive(clap::Parser, Command, Debug)] -pub struct ParseCmd { - /// What wallet file are we parsing? - #[arg(required = true)] - wallet_path: String, - - /// Enable verbose mode. A flag `-v` or `--verbose` will enable verbose mode. - #[arg(short('v'), long("verbose"))] - verbose: bool, -} - -impl Runnable for ParseCmd { - /// Start the application. - fn run(&self) { - let config = APP.config(); - println!("Config: {:#?}", config); - let wallet_parser = WalletParserFactory::read(config.input_file.to_str().unwrap()).unwrap(); - - // println!("{:#?}", wallet_parser.parser.get_wallet_name()); - wallet_parser.parser.print_internal(); - - // LightClient initialization - - let seed = wallet_parser.parser.get_wallet_seed(); - let bd = wallet_parser.parser.get_birthday(); - - if let Err(e) = rustls::crypto::ring::default_provider().install_default() { - eprintln!("Error installing crypto provider: {:?}", e) - }; - - let rt = tokio::runtime::Runtime::new().unwrap(); - let zc = match load_clientconfig( - Uri::from_static("https://na.zec.rocks:443"), - None, - ChainType::Mainnet, - WalletSettings { - sync_config: SyncConfig { - transparent_address_discovery: TransparentAddressDiscovery::recovery(), - }, - }, - ) { - Ok(zc) => zc, - Err(e) => { - eprintln!("Error loading client config: {}", e); - return; - } - }; - - let initial_bh: u32 = bd.try_into().unwrap(); - let lw = LightWallet::new( - ChainType::Mainnet, - WalletBase::SeedBytes(seed), - initial_bh.into(), - WalletSettings { - sync_config: SyncConfig { - transparent_address_discovery: TransparentAddressDiscovery::recovery(), - }, - }, - ) - .unwrap(); - - let mut lc = lightclient::LightClient::create_from_wallet(lw, zc, true).unwrap(); - // let latest_block = - // get_latest_block_height(config.lightwalletd_uri.read().unwrap().clone()).unwrap(); - - rt.block_on(async { - println!("Reading from birthday: {}", bd); - // println!("Upto block: {}", latest_block); - match lc.sync().await { - Ok(_) => {} - Err(e) => { - println!("Error syncing: {}", e); - } - } - - lc.await_sync().await.unwrap(); - let balances = lc.do_balance().await; - - println!("Balances: {}", balances); - }); - } -} - -impl config::Override for ParseCmd { - // Process the given command line options, overriding settings from - // a configuration file using explicit flags taken from command-line - // arguments. - fn override_config( - &self, - mut config: ZexCavatorCliConfig, - ) -> Result { - if !self.wallet_path.is_empty() { - config.input_file = self.wallet_path.to_string().into(); - } - - config.verbose = self.verbose; - - Ok(config) - } -} diff --git a/zexcavator-cli/src/config.rs b/zexcavator-cli/src/config.rs deleted file mode 100644 index 5dc42b7..0000000 --- a/zexcavator-cli/src/config.rs +++ /dev/null @@ -1,36 +0,0 @@ -//! ZexCavatorCli Config -//! -//! See instructions in `commands.rs` to specify the path to your -//! application's configuration file and/or command-line options -//! for specifying it. - -use std::path::PathBuf; - -use serde::{Deserialize, Serialize}; - -const DEFAULT_OUTPUT_FILE: &str = "export.zewif"; - -/// ZexCavatorCli Configuration -#[derive(Clone, Debug, Deserialize, Serialize)] -#[serde(deny_unknown_fields)] -pub struct ZexCavatorCliConfig { - /// Input file where to read from - pub input_file: PathBuf, - - /// Output file. Defaults to `export.zewif` - pub output_file: PathBuf, - - /// verbose mode - pub verbose: bool, -} - -/// Default configuration settings. -impl Default for ZexCavatorCliConfig { - fn default() -> Self { - Self { - input_file: String::from("").into(), - output_file: String::from(DEFAULT_OUTPUT_FILE).into(), - verbose: false, - } - } -} diff --git a/zexcavator-cli/src/error.rs b/zexcavator-cli/src/error.rs deleted file mode 100644 index cdc847f..0000000 --- a/zexcavator-cli/src/error.rs +++ /dev/null @@ -1,70 +0,0 @@ -//! Error types - -use abscissa_core::error::{BoxError, Context}; -use std::{ - fmt::{self, Display}, - io, - ops::Deref, -}; -use thiserror::Error; - -/// Kinds of errors -#[derive(Copy, Clone, Debug, Eq, Error, PartialEq)] -pub enum ErrorKind { - /// Error in configuration file - #[error("config error")] - Config, - - /// Input/output error - #[error("I/O error")] - Io, -} - -impl ErrorKind { - /// Create an error context from this error - pub fn context(self, source: impl Into) -> Context { - Context::new(self, Some(source.into())) - } -} - -/// Error type -#[derive(Debug)] -pub struct Error(Box>); - -impl Deref for Error { - type Target = Context; - - fn deref(&self) -> &Context { - &self.0 - } -} - -impl Display for Error { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - self.0.fmt(f) - } -} - -impl std::error::Error for Error { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - self.0.source() - } -} - -impl From for Error { - fn from(kind: ErrorKind) -> Self { - Context::new(kind, None).into() - } -} - -impl From> for Error { - fn from(context: Context) -> Self { - Error(Box::new(context)) - } -} - -impl From for Error { - fn from(err: io::Error) -> Self { - ErrorKind::Io.context(err).into() - } -} diff --git a/zexcavator-cli/src/lib.rs b/zexcavator-cli/src/lib.rs deleted file mode 100644 index 9469f43..0000000 --- a/zexcavator-cli/src/lib.rs +++ /dev/null @@ -1,22 +0,0 @@ -//! ZexCavatorCli -//! -//! Application based on the [Abscissa] framework. -//! -//! [Abscissa]: https://github.com/iqlusioninc/abscissa - -// Tip: Deny warnings with `RUSTFLAGS="-D warnings"` environment variable in CI - -#![forbid(unsafe_code)] -#![warn( - missing_docs, - rust_2018_idioms, - trivial_casts, - unused_lifetimes, - unused_qualifications -)] - -pub mod application; -pub mod commands; -pub mod config; -pub mod error; -pub mod prelude; diff --git a/zexcavator-cli/src/prelude.rs b/zexcavator-cli/src/prelude.rs deleted file mode 100644 index 025040d..0000000 --- a/zexcavator-cli/src/prelude.rs +++ /dev/null @@ -1,9 +0,0 @@ -//! Application-local prelude: conveniently import types/functions/macros -//! which are generally useful and should be available in every module with -//! `use crate::prelude::*; - -/// Abscissa core prelude -pub use abscissa_core::prelude::*; - -/// Application state -pub use crate::application::APP;