1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//! # WalletD Bitcoin
//!
//! Provides a wallet implementation for Bitcoin including the ability to create a new wallet or import an existing wallet, check balances, and handle transactions.
//! It supports a hierarchical deterministic (HD) wallet structure and provides the ability to search for previously used addresses associated with the wallet as well as the creation of new addresses.
//! It also facilitates obtaining blockchain information.
//!
//! ## Quickstart Guide
//!
//! The [BitcoinWallet] struct is the main entry point to access walletD functionality for Bitcoin.
//!
//! ### Import from Seed
//!
//! Here's how you can access a bitcoin wallet based on a master [Seed].
//! The [Seed] can be derived from a [Mnemonic] using the [Mnemonic::to_seed] method.
//! ```
//! use walletd_bitcoin::prelude::*;
//! use walletd_hd_key::prelude::*;
//! # fn import_btc_hd_wallet() -> Result<(), walletd_bitcoin::Error> {
//! let master_seed = Seed::from_str("a2fd9c0522d84d52ee4c8533dc02d4b69b4df9b6255e1af20c9f1d4d691689f2a38637eb1ec778972bf845c32d5ae83c7536999b5666397ac32021b21e0accee")?;
//! let network_type = HDNetworkType::TestNet;
//! let master_hd_key = HDKey::new_master(master_seed, network_type)?;
//! let mut btc_wallet = BitcoinWallet::builder().master_hd_key(master_hd_key).build()?;
//! # Ok(())
//! # }
//! ```
//!
//! ### Default Derivation Path
//!
//! Deriving a [BitcoinWallet] is simple and uses some default settings under the hood.
//! When using [BitcoinWalletBuilder], the default settings set the [AddressType] as ['P2wpkh`][bitcoin::AddressType::P2wpkh] and the corresponding default [HDPurpose] for the derivation path is set as [HDPurpose::BIP49].
//!```
//! # use walletd_bitcoin::prelude::*;
//! # use walletd_hd_key::prelude::*;
//! use walletd_bitcoin::bitcoin;
//! # fn import_btc_hd_wallet() -> Result<(), walletd_bitcoin::Error> {
//! # let master_seed = Seed::from_str("a2fd9c0522d84d52ee4c8533dc02d4b69b4df9b6255e1af20c9f1d4d691689f2a38637eb1ec778972bf845c32d5ae83c7536999b5666397ac32021b21e0accee")?;
//! # let network_type = HDNetworkType::TestNet;
//! # let master_hd_key = HDKey::new_master(master_seed, network_type)?;
//! # let mut btc_wallet = BitcoinWallet::builder().master_hd_key(master_hd_key).build()?;
//! assert_eq!(btc_wallet.address_format(), bitcoin::AddressType::P2wpkh);
//! assert_eq!(btc_wallet.hd_path_builder()?.purpose, Some(HDPurpose::BIP84.to_shortform_num()));
//!
//! # Ok(())
//! # }
//!```
//!
//! ### Using Blockstream as Blockchain Connector
//!
//! The [BitcoinWallet] struct can be used to access blockchain data through a [BlockchainConnector] such as [Blockstream].
//! The [Blockstream] instance can be used on its own to access blockchain data such as fee estimates.
//! It can be affiliated with a [BitcoinWallet] to enable the [BitcoinWallet] to access blockchain data and send transactions.
//! ```no_run
//! # use walletd_bitcoin::prelude::*;
//! # use walletd_hd_key::prelude::*;
//! # use walletd_bitcoin::bitcoin;
//! # async fn import_btc_hd_wallet() -> Result<(), walletd_bitcoin::Error> {
//! # let master_seed = Seed::from_str("a2fd9c0522d84d52ee4c8533dc02d4b69b4df9b6255e1af20c9f1d4d691689f2a38637eb1ec778972bf845c32d5ae83c7536999b5666397ac32021b21e0accee")?;
//! # let network_type = HDNetworkType::TestNet;
//! # let master_hd_key = HDKey::new_master(master_seed, network_type)?;
//! # let mut btc_wallet = BitcoinWallet::builder().master_hd_key(master_hd_key).build()?;
//! let btc_client = Blockstream::new("https://blockstream.info/testnet/api")?;
//! let fee_estimates = btc_client.fee_estimates().await?;
//! println!("fee estimates: {:?}", fee_estimates);
//! btc_wallet.set_blockchain_client(btc_client);
//! # Ok(())
//! # }
//! ```
//!
//! ### Sync BitcoinWallet, Load BitcoinAddresses
//!
//! The [BitcoinWallet] struct can be used to sync the wallet with the blockchain and load the associated [BitcoinAddress]es.
//! ```no_run
//! # use walletd_bitcoin::prelude::*;
//! # use walletd_hd_key::prelude::*;
//! # use walletd_bitcoin::bitcoin;
//! # async fn import_btc_hd_wallet() -> Result<(), walletd_bitcoin::Error> {
//! # let master_seed = Seed::from_str("a2fd9c0522d84d52ee4c8533dc02d4b69b4df9b6255e1af20c9f1d4d691689f2a38637eb1ec778972bf845c32d5ae83c7536999b5666397ac32021b21e0accee")?;
//! # let network_type = HDNetworkType::TestNet;
//! # let master_hd_key = HDKey::new_master(master_seed, network_type)?;
//! # let mut btc_wallet = BitcoinWallet::builder().master_hd_key(master_hd_key).build()?;
//! let btc_client = Blockstream::new("https://blockstream.info/testnet/api")?;
//! let fee_estimates = btc_client.fee_estimates().await?;
//! println!("fee estimates: {:?}", fee_estimates);
//! btc_wallet.set_blockchain_client(btc_client);
//! for addr in btc_wallet.associated_info() {
//! println!("address: {}, derivation path {}",
//! addr.address.public_address(), addr.hd_key().derivation_path().to_string());
//! }
//! println!("next receive address: {}", btc_wallet.receive_address()?);
//! println!("next change address: {}", btc_wallet.next_change_address()?.public_address());
//!
//!
//!
//! let balance = btc_wallet.balance().await?;
//! println!(
//! "bitcoin wallet balance: {} BTC, ({} satoshi",
//! balance.btc(),
//! balance.satoshi()
//! );
//! # Ok(())
//! # }
//! ```
pub use bitcoin;
pub use ;
pub use BitcoinAddress;
pub use ;
pub use BitcoinAmount;
pub use Blockstream;
pub use Error;
pub use ;
pub use ;
pub use ;