From: rajarshimaitra Date: Fri, 1 Jul 2022 11:24:52 +0000 (+0530) Subject: Update with review comments X-Git-Tag: v0.6.0~9^2~1 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/database/struct.CommandStringError.html?a=commitdiff_plain;h=073f1c339be3057bb1d88ef1e925d5fd09611c98;p=bdk-cli Update with review comments --- 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/backend.rs b/src/backend.rs deleted file mode 100644 index f965b43..0000000 --- a/src/backend.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) 2020-2021 Bitcoin Dev Kit Developers -// -// This file is licensed under the Apache License, Version 2.0 or the MIT license -// , at your option. -// You may not use this file except in accordance with one or both of these -// licenses. - -//! The Backend -//! -//! This module defines the Backend struct and associated operations - -#[allow(dead_code)] -// Different Backend types activated with `regtest-*` mode. -// If `regtest-*` feature not activated, then default is `None`. -pub enum Backend { - None, - Bitcoin { rpc_url: String, rpc_auth: String }, - Electrum { electrum_url: String }, - Esplora { esplora_url: String }, -} 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/nodes.rs b/src/nodes.rs new file mode 100644 index 0000000..f3873e8 --- /dev/null +++ b/src/nodes.rs @@ -0,0 +1,21 @@ +// Copyright (c) 2020-2021 Bitcoin Dev Kit Developers +// +// This file is licensed under the Apache License, Version 2.0 or the MIT license +// , at your option. +// You may not use this file except in accordance with one or both of these +// licenses. + +//! The Node structures +//! +//! This module defines the the backend node structures for `regtest-*` features + +#[allow(dead_code)] +// Different regtest node types activated with `regtest-*` mode. +// If `regtest-*` feature not activated, then default is `None`. +pub enum Nodes { + None, + Bitcoin { rpc_url: String, rpc_auth: String }, + Electrum { electrum_url: String }, + Esplora { esplora_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(),