[docs] Add docs to the 'wallet' module

This commit is contained in:
Steve Myers 2020-12-11 14:10:11 -08:00
parent 1d1d539154
commit 148e8c6088
No known key found for this signature in database
GPG Key ID: 8105A46B22C2D051
5 changed files with 14 additions and 7 deletions

View File

@ -84,10 +84,15 @@ use crate::types::KeychainKind;
/// Errors that can be returned to fail the validation of an address /// Errors that can be returned to fail the validation of an address
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub enum AddressValidatorError { pub enum AddressValidatorError {
/// User rejected the address
UserRejected, UserRejected,
/// Network connection error
ConnectionError, ConnectionError,
/// Network request timeout error
TimeoutError, TimeoutError,
/// Invalid script
InvalidScript, InvalidScript,
/// A custom error message
Message(String), Message(String),
} }

View File

@ -45,6 +45,7 @@
//! # use bdk::wallet::coin_selection::*; //! # use bdk::wallet::coin_selection::*;
//! # use bdk::database::Database; //! # use bdk::database::Database;
//! # use bdk::*; //! # use bdk::*;
//! # const TXIN_BASE_WEIGHT: usize = (32 + 4 + 4 + 1) * 4;
//! #[derive(Debug)] //! #[derive(Debug)]
//! struct AlwaysSpendEverything; //! struct AlwaysSpendEverything;
//! //!
@ -114,9 +115,9 @@ pub type DefaultCoinSelectionAlgorithm = BranchAndBoundCoinSelection;
#[cfg(test)] #[cfg(test)]
pub type DefaultCoinSelectionAlgorithm = LargestFirstCoinSelection; // make the tests more predictable 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) // 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 /// Result of a successful coin selection
#[derive(Debug)] #[derive(Debug)]
@ -275,6 +276,7 @@ impl Default for BranchAndBoundCoinSelection {
} }
impl BranchAndBoundCoinSelection { impl BranchAndBoundCoinSelection {
/// Create new instance with target size for change output
pub fn new(size_of_change: u64) -> Self { pub fn new(size_of_change: u64) -> Self {
Self { size_of_change } Self { size_of_change }
} }

View File

@ -46,15 +46,11 @@ use miniscript::psbt::PsbtInputSatisfier;
#[allow(unused_imports)] #[allow(unused_imports)]
use log::{debug, error, info, trace}; use log::{debug, error, info, trace};
#[allow(missing_docs)] // TODO add missing docs and remove this allow
pub mod address_validator; pub mod address_validator;
#[allow(missing_docs)] // TODO add missing docs and remove this allow
pub mod coin_selection; pub mod coin_selection;
pub mod export; pub mod export;
#[allow(missing_docs)] // TODO add missing docs and remove this allow
pub mod signer; pub mod signer;
pub mod time; pub mod time;
#[allow(missing_docs)] // TODO add missing docs and remove this allow
pub mod tx_builder; pub mod tx_builder;
pub(crate) mod utils; pub(crate) mod utils;
@ -962,7 +958,7 @@ where
Ok((psbt, finished)) 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 { pub fn secp_ctx(&self) -> &SecpCtx {
&self.secp &self.secp
} }

View File

@ -113,7 +113,9 @@ use crate::descriptor::XKeyUtils;
/// multiple of them /// multiple of them
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum SignerId { pub enum SignerId {
/// Bitcoin HASH160 (RIPEMD160 after SHA256) hash of an ECDSA public key
PkHash(hash160::Hash), PkHash(hash160::Hash),
/// The fingerprint of a BIP32 extended key
Fingerprint(Fingerprint), Fingerprint(Fingerprint),
} }
@ -324,6 +326,7 @@ impl From<(SignerId, SignerOrdering)> for SignersContainerKey {
pub struct SignersContainer(HashMap<SignersContainerKey, Arc<dyn Signer>>); pub struct SignersContainer(HashMap<SignersContainerKey, Arc<dyn Signer>>);
impl SignersContainer { impl SignersContainer {
/// Create a map of public keys to secret keys
pub fn as_key_map(&self, secp: &SecpCtx) -> KeyMap { pub fn as_key_map(&self, secp: &SecpCtx) -> KeyMap {
self.0 self.0
.values() .values()

View File

@ -508,6 +508,7 @@ impl Default for TxOrdering {
} }
impl TxOrdering { impl TxOrdering {
/// Sort transaction inputs and outputs by [`TxOrdering`] variant
pub fn sort_tx(&self, tx: &mut Transaction) { pub fn sort_tx(&self, tx: &mut Transaction) {
match self { match self {
TxOrdering::Untouched => {} TxOrdering::Untouched => {}