From 148e8c6088f8d4f5549618fc3a19a3bdff778f02 Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Fri, 11 Dec 2020 14:10:11 -0800 Subject: [PATCH] [docs] Add docs to the 'wallet' module --- src/wallet/address_validator.rs | 5 +++++ src/wallet/coin_selection.rs | 6 ++++-- src/wallet/mod.rs | 6 +----- src/wallet/signer.rs | 3 +++ src/wallet/tx_builder.rs | 1 + 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/wallet/address_validator.rs b/src/wallet/address_validator.rs index 391e2ad9..26f15a25 100644 --- a/src/wallet/address_validator.rs +++ b/src/wallet/address_validator.rs @@ -84,10 +84,15 @@ use crate::types::KeychainKind; /// Errors that can be returned to fail the validation of an address #[derive(Debug, Clone, PartialEq, Eq)] pub enum AddressValidatorError { + /// User rejected the address UserRejected, + /// Network connection error ConnectionError, + /// Network request timeout error TimeoutError, + /// Invalid script InvalidScript, + /// A custom error message Message(String), } diff --git a/src/wallet/coin_selection.rs b/src/wallet/coin_selection.rs index c706ec9f..f964f5dc 100644 --- a/src/wallet/coin_selection.rs +++ b/src/wallet/coin_selection.rs @@ -45,6 +45,7 @@ //! # use bdk::wallet::coin_selection::*; //! # use bdk::database::Database; //! # use bdk::*; +//! # const TXIN_BASE_WEIGHT: usize = (32 + 4 + 4 + 1) * 4; //! #[derive(Debug)] //! struct AlwaysSpendEverything; //! @@ -114,9 +115,9 @@ pub type DefaultCoinSelectionAlgorithm = BranchAndBoundCoinSelection; #[cfg(test)] pub type DefaultCoinSelectionAlgorithm = LargestFirstCoinSelection; // make the tests more predictable -// Base weight of a Txin, not counting the weight needed for satisfaying it. +// Base weight of a Txin, not counting the weight needed for satisfying it. // prev_txid (32 bytes) + prev_vout (4 bytes) + sequence (4 bytes) + script_len (1 bytes) -pub const TXIN_BASE_WEIGHT: usize = (32 + 4 + 4 + 1) * 4; +pub(crate) const TXIN_BASE_WEIGHT: usize = (32 + 4 + 4 + 1) * 4; /// Result of a successful coin selection #[derive(Debug)] @@ -275,6 +276,7 @@ impl Default for BranchAndBoundCoinSelection { } impl BranchAndBoundCoinSelection { + /// Create new instance with target size for change output pub fn new(size_of_change: u64) -> Self { Self { size_of_change } } diff --git a/src/wallet/mod.rs b/src/wallet/mod.rs index de69357a..6db8f8d9 100644 --- a/src/wallet/mod.rs +++ b/src/wallet/mod.rs @@ -46,15 +46,11 @@ use miniscript::psbt::PsbtInputSatisfier; #[allow(unused_imports)] use log::{debug, error, info, trace}; -#[allow(missing_docs)] // TODO add missing docs and remove this allow pub mod address_validator; -#[allow(missing_docs)] // TODO add missing docs and remove this allow pub mod coin_selection; pub mod export; -#[allow(missing_docs)] // TODO add missing docs and remove this allow pub mod signer; pub mod time; -#[allow(missing_docs)] // TODO add missing docs and remove this allow pub mod tx_builder; pub(crate) mod utils; @@ -962,7 +958,7 @@ where Ok((psbt, finished)) } - #[allow(missing_docs)] // TODO add missing docs and remove this allow + /// Return the secp256k1 context used for all signing operations pub fn secp_ctx(&self) -> &SecpCtx { &self.secp } diff --git a/src/wallet/signer.rs b/src/wallet/signer.rs index 43cff45a..6ddf4162 100644 --- a/src/wallet/signer.rs +++ b/src/wallet/signer.rs @@ -113,7 +113,9 @@ use crate::descriptor::XKeyUtils; /// multiple of them #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum SignerId { + /// Bitcoin HASH160 (RIPEMD160 after SHA256) hash of an ECDSA public key PkHash(hash160::Hash), + /// The fingerprint of a BIP32 extended key Fingerprint(Fingerprint), } @@ -324,6 +326,7 @@ impl From<(SignerId, SignerOrdering)> for SignersContainerKey { pub struct SignersContainer(HashMap>); impl SignersContainer { + /// Create a map of public keys to secret keys pub fn as_key_map(&self, secp: &SecpCtx) -> KeyMap { self.0 .values() diff --git a/src/wallet/tx_builder.rs b/src/wallet/tx_builder.rs index 3cd784f0..921081a3 100644 --- a/src/wallet/tx_builder.rs +++ b/src/wallet/tx_builder.rs @@ -508,6 +508,7 @@ impl Default for TxOrdering { } impl TxOrdering { + /// Sort transaction inputs and outputs by [`TxOrdering`] variant pub fn sort_tx(&self, tx: &mut Transaction) { match self { TxOrdering::Untouched => {}