From 073f1c339be3057bb1d88ef1e925d5fd09611c98 Mon Sep 17 00:00:00 2001 From: rajarshimaitra Date: Fri, 1 Jul 2022 16:54:52 +0530 Subject: [PATCH] Update with review comments --- CHANGELOG.md | 4 ++++ Cargo.toml | 4 ++-- src/handlers.rs | 4 ++-- src/main.rs | 14 +++++++------- src/{backend.rs => nodes.rs} | 8 ++++---- src/utils.rs | 10 +++++----- 6 files changed, 24 insertions(+), 20 deletions(-) rename src/{backend.rs => nodes.rs} (76%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fb4ff9..41f1481 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - Add distinct `key-value-db` and `sqlite-db` features, keep default as `key-value-db` +- Reorganize existing codes in separate modules. Change crate type from lib to bin. +- Rewrite relevant doc comments as `structopt` help document. +- Update `bdk` and `bdk-reserves` to v0.19.0. +- Change default database to `sqlite`. ## [0.5.0] diff --git a/Cargo.toml b/Cargo.toml index 47e325a..f9cc694 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,11 +34,11 @@ default = ["repl", "sqlite-db"] # To use the app in a REPL mode repl = ["regex", "rustyline", "fd-lock"] -# Avaialable dataabse options +# Avaialable databse options key-value-db = ["bdk/key-value-db"] sqlite-db = ["bdk/sqlite"] -# Avialable blockchain backend options +# Avialable blockchain client options rpc = ["bdk/rpc"] electrum = ["bdk/electrum"] compact_filters = ["bdk/compact_filters"] diff --git a/src/handlers.rs b/src/handlers.rs index db69b04..9e0ded0 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -22,7 +22,7 @@ use crate::commands::OfflineWalletSubCommand::*; use crate::commands::OnlineWalletSubCommand::*; use crate::commands::*; use crate::utils::*; -use crate::Backend; +use crate::Nodes; use bdk::{database::BatchDatabase, wallet::AddressIndex, Error, FeeRate, KeychainKind, Wallet}; use structopt::StructOpt; @@ -559,7 +559,7 @@ pub fn get_outpoints_for_address( pub fn handle_command( cli_opts: CliOpts, network: Network, - _backend: Backend, + _backend: Nodes, ) -> Result { let result = match cli_opts.subcommand { #[cfg(any( diff --git a/src/main.rs b/src/main.rs index 154b42a..edb3e4d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,12 +10,12 @@ //! //! This module describes the app's main() function -mod backend; mod commands; mod handlers; +mod nodes; mod utils; -use backend::Backend; +use nodes::Nodes; use bitcoin::Network; @@ -53,7 +53,7 @@ fn main() { #[cfg(feature = "regtest-bitcoin")] let backend = { - Backend::Bitcoin { + Nodes::Bitcoin { rpc_url: bitcoind.params.rpc_socket.to_string(), rpc_auth: bitcoind .params @@ -71,7 +71,7 @@ fn main() { let elect_exe = electrsd::downloaded_exe_path().expect("We should always have downloaded path"); let electrsd = electrsd::ElectrsD::with_conf(elect_exe, &bitcoind, &elect_conf).unwrap(); - let backend = Backend::Electrum { + let backend = Nodes::Electrum { electrum_url: electrsd.electrum_url.clone(), }; (electrsd, backend) @@ -84,17 +84,17 @@ fn main() { let elect_exe = electrsd::downloaded_exe_path().expect("Electrsd downloaded binaries not found"); let electrsd = electrsd::ElectrsD::with_conf(elect_exe, &bitcoind, &elect_conf).unwrap(); - let backend = Backend::Esplora { + let backend = Nodes::Esplora { esplora_url: electrsd .esplora_url .clone() .expect("Esplora port not open in electrum"), }; - (electrsd, backend) + (electrsd, nodes) }; #[cfg(not(feature = "regtest-node"))] - let backend = Backend::None; + let backend = Nodes::None; match handle_command(cli_opts, network, backend) { Ok(result) => println!("{}", result), diff --git a/src/backend.rs b/src/nodes.rs similarity index 76% rename from src/backend.rs rename to src/nodes.rs index f965b43..f3873e8 100644 --- a/src/backend.rs +++ b/src/nodes.rs @@ -6,14 +6,14 @@ // You may not use this file except in accordance with one or both of these // licenses. -//! The Backend +//! The Node structures //! -//! This module defines the Backend struct and associated operations +//! This module defines the the backend node structures for `regtest-*` features #[allow(dead_code)] -// Different Backend types activated with `regtest-*` mode. +// Different regtest node types activated with `regtest-*` mode. // If `regtest-*` feature not activated, then default is `None`. -pub enum Backend { +pub enum Nodes { None, Bitcoin { rpc_url: String, rpc_auth: String }, Electrum { electrum_url: String }, diff --git a/src/utils.rs b/src/utils.rs index 46815b4..a8fb857 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -13,14 +13,14 @@ use std::path::PathBuf; use std::str::FromStr; +use crate::commands::WalletOpts; #[cfg(any( feature = "electrum", feature = "esplora", feature = "compact_filters", feature = "rpc" ))] -use crate::backend::Backend; -use crate::commands::WalletOpts; +use crate::nodes::Nodes; use bdk::bitcoin::secp256k1::Secp256k1; use bdk::bitcoin::{Address, Network, OutPoint, Script}; #[cfg(feature = "compact_filters")] @@ -199,12 +199,12 @@ pub(crate) fn open_database(wallet_opts: &WalletOpts) -> Result Result { #[cfg(feature = "electrum")] let config = { let url = match _backend { - Backend::Electrum { electrum_url } => electrum_url.to_owned(), + Nodes::Electrum { electrum_url } => electrum_url.to_owned(), _ => wallet_opts.electrum_opts.server.clone(), }; @@ -254,7 +254,7 @@ pub(crate) fn new_blockchain( #[cfg(feature = "rpc")] let config: AnyBlockchainConfig = { let (url, auth) = match _backend { - Backend::Bitcoin { rpc_url, rpc_auth } => ( + Nodes::Bitcoin { rpc_url, rpc_auth } => ( rpc_url, Auth::Cookie { file: rpc_auth.into(), -- 2.49.0