Skip to content

Commit 4789fca

Browse files
temp 6: clean up constructors
1 parent e7cbf86 commit 4789fca

File tree

4 files changed

+16
-108
lines changed

4 files changed

+16
-108
lines changed

examples/example_n_keychains/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn main() -> Result<(), anyhow::Error> {
2727
println!("{:?}", keychain_ids);
2828

2929
// Create the wallet and peek addresses on each of the descriptors
30-
let mut wallet: Wallet = Wallet::new(keyring).create_wallet_no_persist()?;
30+
let mut wallet: Wallet = Wallet::create(keyring).create_wallet_no_persist()?;
3131
let address_1 = wallet.peek_address(KeychainKind::Default, 0).unwrap();
3232
let address_2 = wallet.peek_address(KeychainKind::Other(keychain_ids[1]), 0).unwrap();
3333
let address_3 = wallet.peek_address(KeychainKind::Other(keychain_ids[2]), 0).unwrap();

wallet/examples/n_keychains.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn main() -> Result<(), anyhow::Error> {
2222
println!("{:?}", keychain_ids);
2323

2424
// Create the wallet and peek addresses on each of the descriptors
25-
let wallet: Wallet = Wallet::new(keyring).create_wallet_no_persist()?;
25+
let mut wallet: Wallet = Wallet::create(keyring).create_wallet_no_persist()?;
2626
let address_1 = wallet.peek_address(KeychainKind::Default, 0).unwrap();
2727
let address_2 = wallet.peek_address(KeychainKind::Other(keychain_ids[1]), 0).unwrap();
2828
let address_3 = wallet.peek_address(KeychainKind::Other(keychain_ids[2]), 0).unwrap();

wallet/src/wallet/mod.rs

Lines changed: 10 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -288,58 +288,6 @@ impl std::error::Error for ApplyBlockError {}
288288
pub type WalletTx<'a> = CanonicalTx<'a, Arc<Transaction>, ConfirmationBlockTime>;
289289

290290
impl Wallet {
291-
pub fn new(key_ring: KeyRing) -> CreateParams {
292-
let network = key_ring.network();
293-
CreateParams::new_with_keyring(key_ring, network)
294-
}
295-
296-
/// Build a new single descriptor [`Wallet`].
297-
///
298-
/// If you have previously created a wallet, use [`load`](Self::load) instead.
299-
///
300-
/// # Note
301-
///
302-
/// Only use this method when creating a wallet designed to be used with a single
303-
/// descriptor and keychain. Otherwise the recommended way to construct a new wallet is
304-
/// by using [`Wallet::create`]. It's worth noting that not all features are available
305-
/// with single descriptor wallets, for example setting a [`change_policy`] on [`TxBuilder`]
306-
/// and related methods such as [`do_not_spend_change`]. This is because all payments are
307-
/// received on the external keychain (including change), and without a change keychain
308-
/// BDK lacks enough information to distinguish between change and outside payments.
309-
///
310-
/// Additionally because this wallet has no internal (change) keychain, all methods that
311-
/// require a [`KeychainKind`] as input, e.g. [`reveal_next_address`] should only be called
312-
/// using the [`External`] variant. In most cases passing [`Internal`] is treated as the
313-
/// equivalent of [`External`] but this behavior must not be relied on.
314-
///
315-
/// # Example
316-
///
317-
/// ```rust
318-
/// # use bdk_wallet::Wallet;
319-
/// # use bitcoin::Network;
320-
/// # const EXTERNAL_DESC: &str = "wpkh(tprv8ZgxMBicQKsPdy6LMhUtFHAgpocR8GC6QmwMSFpZs7h6Eziw3SpThFfczTDh5rW2krkqffa11UpX3XkeTTB2FvzZKWXqPY54Y6Rq4AQ5R8L/84'/1'/0'/0/*)";
321-
/// # let temp_dir = tempfile::tempdir().expect("must create tempdir");
322-
/// # let file_path = temp_dir.path().join("store.db");
323-
/// // Create a wallet that is persisted to SQLite database.
324-
/// use bdk_wallet::rusqlite::Connection;
325-
/// let mut conn = Connection::open(file_path)?;
326-
/// let wallet = Wallet::create_single(EXTERNAL_DESC)
327-
/// .network(Network::Testnet)
328-
/// .create_wallet(&mut conn)?;
329-
/// # Ok::<_, anyhow::Error>(())
330-
/// ```
331-
/// [`change_policy`]: TxBuilder::change_policy
332-
/// [`do_not_spend_change`]: TxBuilder::do_not_spend_change
333-
/// [`External`]: KeychainKind::External
334-
/// [`Internal`]: KeychainKind::Internal
335-
/// [`reveal_next_address`]: Self::reveal_next_address
336-
// pub fn create_single<D>(descriptor: D) -> CreateParams
337-
// where
338-
// D: IntoWalletDescriptor + Send + Clone + 'static,
339-
// {
340-
// CreateParams::new_single(descriptor)
341-
// }
342-
343291
/// Build a new [`Wallet`].
344292
///
345293
/// If you have previously created a wallet, use [`load`](Self::load) instead.
@@ -348,33 +296,30 @@ impl Wallet {
348296
///
349297
/// ```rust
350298
/// # use bdk_wallet::Wallet;
299+
/// # use bdk_wallet::keyring::KeyRing;
351300
/// # use bitcoin::Network;
352301
/// # fn main() -> anyhow::Result<()> {
353-
/// # const EXTERNAL_DESC: &str = "wpkh(tprv8ZgxMBicQKsPdy6LMhUtFHAgpocR8GC6QmwMSFpZs7h6Eziw3SpThFfczTDh5rW2krkqffa11UpX3XkeTTB2FvzZKWXqPY54Y6Rq4AQ5R8L/84'/1'/0'/0/*)";
354-
/// # const INTERNAL_DESC: &str = "wpkh(tprv8ZgxMBicQKsPdy6LMhUtFHAgpocR8GC6QmwMSFpZs7h6Eziw3SpThFfczTDh5rW2krkqffa11UpX3XkeTTB2FvzZKWXqPY54Y6Rq4AQ5R8L/84'/1'/0'/1/*)";
302+
/// # const MY_DESCRIPTOR: &str = "wpkh(tprv8ZgxMBicQKsPdy6LMhUtFHAgpocR8GC6QmwMSFpZs7h6Eziw3SpThFfczTDh5rW2krkqffa11UpX3XkeTTB2FvzZKWXqPY54Y6Rq4AQ5R8L/84'/1'/0'/0/*)";
303+
/// // Create a KeyRing
304+
/// let mut key_ring = KeyRing::new(MY_DESCRIPTOR, Network::Signet);
355305
/// // Create a non-persisted wallet.
356-
/// let wallet = Wallet::create(EXTERNAL_DESC, INTERNAL_DESC)
357-
/// .network(Network::Testnet)
306+
/// let wallet = Wallet::create(key_ring)
358307
/// .create_wallet_no_persist()?;
359308
///
360309
/// // Create a wallet that is persisted to SQLite database.
361310
/// # let temp_dir = tempfile::tempdir().expect("must create tempdir");
362311
/// # let file_path = temp_dir.path().join("store.db");
363312
/// use bdk_wallet::rusqlite::Connection;
364313
/// let mut conn = Connection::open(file_path)?;
365-
/// let wallet = Wallet::create(EXTERNAL_DESC, INTERNAL_DESC)
366-
/// .network(Network::Testnet)
314+
/// let wallet = Wallet::create(key_ring)
367315
/// .create_wallet(&mut conn)?;
368316
/// # Ok(())
369317
/// # }
370318
/// ```
371-
// pub fn create<D>(descriptor: D, change_descriptor: D) -> CreateParams
372-
// where
373-
// D: IntoWalletDescriptor + Send + Clone + 'static,
374-
// {
375-
// CreateParams::new(descriptor, change_descriptor)
376-
// }
377-
//
319+
pub fn create(key_ring: KeyRing) -> CreateParams {
320+
CreateParams::new(key_ring)
321+
}
322+
378323
// /// Create a new [`Wallet`] with given `params`.
379324
// ///
380325
// /// Refer to [`Wallet::create`] for more.

wallet/src/wallet/params.rs

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -34,53 +34,16 @@ pub struct CreateParams {
3434
}
3535

3636
impl CreateParams {
37-
/// Construct parameters with provided `descriptor`.
37+
/// Construct parameters with provided `KeyRing`.
3838
///
3939
/// Default values:
40-
/// * `change_descriptor` = `None`
41-
/// * `network` = [`Network::Bitcoin`]
40+
/// * `network` = Provided by your KeyRing
4241
/// * `genesis_hash` = `None`
4342
/// * `lookahead` = [`DEFAULT_LOOKAHEAD`]
44-
///
45-
/// Use this method only when building a wallet with a single descriptor. See
46-
/// also [`Wallet::create_single`].
47-
// pub fn new_single<D: IntoWalletDescriptor + Send + 'static>(descriptor: D) -> Self {
48-
// Self {
49-
// descriptor: make_descriptor_to_extract(descriptor),
50-
// descriptor_keymap: KeyMap::default(),
51-
// change_descriptor: None,
52-
// change_descriptor_keymap: KeyMap::default(),
53-
// network: Network::Bitcoin,
54-
// genesis_hash: None,
55-
// lookahead: DEFAULT_LOOKAHEAD,
56-
// }
57-
// }
58-
59-
/// Construct parameters with provided `descriptor` and `change_descriptor`.
60-
///
61-
/// Default values:
62-
/// * `network` = [`Network::Bitcoin`]
63-
/// * `genesis_hash` = `None`
64-
/// * `lookahead` = [`DEFAULT_LOOKAHEAD`]
65-
// pub fn new<D: IntoWalletDescriptor + Send + 'static>(
66-
// descriptor: D,
67-
// change_descriptor: D,
68-
// ) -> Self {
69-
// Self {
70-
// descriptor: make_descriptor_to_extract(descriptor),
71-
// descriptor_keymap: KeyMap::default(),
72-
// change_descriptor: Some(make_descriptor_to_extract(change_descriptor)),
73-
// change_descriptor_keymap: KeyMap::default(),
74-
// network: Network::Bitcoin,
75-
// genesis_hash: None,
76-
// lookahead: DEFAULT_LOOKAHEAD,
77-
// }
78-
// }
79-
80-
pub fn new_with_keyring(
43+
pub fn new(
8144
key_ring: KeyRing,
82-
network: Network,
8345
) -> Self {
46+
let network = key_ring.network();
8447
Self {
8548
key_ring,
8649
network,

0 commit comments

Comments
 (0)