Skip to content

Commit d24ccb9

Browse files
committed
Add warm(missing_docs), cli module docs
1 parent 7425985 commit d24ccb9

File tree

3 files changed

+103
-1
lines changed

3 files changed

+103
-1
lines changed

src/blockchain/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ impl Progress for NoopProgress {
217217
#[derive(Clone)]
218218
pub struct LogProgress;
219219

220-
/// Create a nwe instance of [`LogProgress`]
220+
/// Create a new instance of [`LogProgress`]
221221
pub fn log_progress() -> LogProgress {
222222
LogProgress
223223
}

src/cli.rs

+100
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,29 @@
2222
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2323
// SOFTWARE.
2424

25+
//! Command line interface
26+
//!
27+
//! This module provides a simple cli interface using [clap](https://docs.rs/clap/) to access
28+
//! basic wallet functionality. See the `repl.rs` example app for how to use this module to create
29+
//! a custom `bdk` based command line wallet application.
30+
//!
31+
//! # Example
32+
//!
33+
//! ```rust
34+
//! let app = cli::make_cli_subcommands();
35+
//! let app = cli::add_global_flags(app);
36+
//!
37+
//! let matches = app.get_matches();
38+
//!
39+
//! let network = match matches.value_of("network") {
40+
//! Some("regtest") => Network::Regtest,
41+
//! Some("testnet") | _ => Network::Testnet,
42+
//! };
43+
//!
44+
//! // etc.
45+
//! ```
46+
//! See [`make_cli_subcommands()`] for list of sub-commands, and [`add_global_flags()`] for list of global flags.
47+
2548
use std::collections::BTreeMap;
2649
use std::str::FromStr;
2750

@@ -70,6 +93,47 @@ fn outpoint_validator(s: String) -> Result<(), String> {
7093
parse_outpoint(&s).map(|_| ())
7194
}
7295

96+
/// Create new [clap](https://docs.rs/clap/) `App` with wallet sub-commands
97+
///
98+
/// Configuration such as name, version, author, about can be overridden. Additional sub-commands
99+
/// sub-commands can also be added. See [clap](https://docs.rs/clap/) for more information on how
100+
/// to customize an `App`.
101+
///
102+
/// # Wallet sub-commands
103+
///
104+
/// | Sub-command | Description |
105+
/// |--------------------|----------------------------------------------- |
106+
/// | broadcast | Broadcasts a transaction to the network. Takes either a raw transaction or a PSBT to extract |
107+
/// | bump_fee | Bumps the fees of an RBF transaction |
108+
/// | combine_psbt | Combines multiple PSBTs into one |
109+
/// | create_tx | Creates a new unsigned tranasaction |
110+
/// | extract_psbt | Extracts a raw transaction from a PSBT |
111+
/// | finalize_psbt | Finalizes a psbt |
112+
/// | get_balance | Returns the current wallet balance |
113+
/// | get_new_address | Generates a new external address |
114+
/// | help | Prints this message or the help of the given subcommand(s) |
115+
/// | list_transactions | Lists all the incoming and outgoing transactions of the wallet |
116+
/// | list_unspent | Lists the available spendable UTXOs |
117+
/// | policies | Returns the available spending policies for the descriptor |
118+
/// | public_descriptor | Returns the public version of the wallet's descriptor(s) |
119+
/// | repl | Opens an interactive shell |
120+
/// | sign | Signs and tries to finalize a PSBT |
121+
/// | sync | Syncs with the chosen Electrum server |
122+
///
123+
/// # Example
124+
///
125+
/// ```rust
126+
/// let app = cli::make_cli_subcommands();
127+
/// let app = app.name("Demo App")
128+
/// .version("0.1.0")
129+
/// .author("Demo Author")
130+
/// .about("A demo cli wallet based on the bdk library.");
131+
///
132+
/// let app = app.subcommand(
133+
/// SubCommand::with_name("do_something").about("Do something else with your app"),
134+
/// );
135+
/// ```
136+
73137
pub fn make_cli_subcommands<'a, 'b>() -> App<'a, 'b> {
74138
App::new("Magical Bitcoin Wallet")
75139
.version(option_env!("CARGO_PKG_VERSION").unwrap_or("unknown"))
@@ -308,6 +372,42 @@ pub fn make_cli_subcommands<'a, 'b>() -> App<'a, 'b> {
308372
)
309373
}
310374

375+
/// Add [clap](https://docs.rs/clap/) global wallet options to an `App`
376+
///
377+
/// Additional app specific options can be added. See [clap](https://docs.rs/clap/) for more
378+
/// information on how to customize the global flags for an `App`.
379+
///
380+
/// # Wallet global flags
381+
///
382+
/// | Short | Long | Description |
383+
/// |-------|-------|-------------|
384+
/// | -c | --change_descriptor <DESCRIPTOR> | Sets the descriptor to use for internal addresses |
385+
/// | -d | --descriptor <DESCRIPTOR> | Sets the descriptor to use for the external addresses |
386+
/// | -e | --esplora <ESPLORA> | Use the esplora server if given as parameter |
387+
/// | | --esplora_concurrency <ESPLORA_CONCURRENCY> | Concurrency of requests made to the esplora server [default: 4] |
388+
/// | -n | --network <NETWORK> | Sets the network [default: testnet] [possible values: testnet, regtest] |
389+
/// | -p | --proxy <SERVER:PORT> | Sets the SOCKS5 proxy for the Electrum client |
390+
/// | -s | --server <SERVER:PORT> | Sets the Electrum server to use [default: ssl://electrum.blockstream.info:60002] |
391+
/// | -w | --wallet <WALLET_NAME> | Selects the wallet to use [default: main] |
392+
///
393+
/// # Example
394+
///
395+
/// ```rust
396+
/// let app = cli::make_cli_subcommands();
397+
/// let app = cli::add_global_flags(app);
398+
///
399+
/// let app = app.arg(
400+
/// Arg::with_name("custom")
401+
/// .short("c")
402+
/// .long("custom")
403+
/// .value_name("CUSTOM")
404+
/// .help("Sets the custom option")
405+
/// .takes_value(true)
406+
/// .default_value("option1")
407+
/// .possible_values(&["option1", "option2"]),
408+
/// );
409+
/// ```
410+
311411
pub fn add_global_flags<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
312412
let mut app = app
313413
.arg(

src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2323
// SOFTWARE.
2424

25+
// rustdoc will fail if there is missing docs
26+
#![warn(missing_docs)]
2527
// only enables the `doc_cfg` feature when
2628
// the `docsrs` configuration attribute is defined
2729
#![cfg_attr(docsrs, feature(doc_cfg))]

0 commit comments

Comments
 (0)