Skip to content

Commit 9cc2372

Browse files
committed
[wallet] Add more getters
1 parent adf7d0c commit 9cc2372

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/wallet/mod.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,13 +454,41 @@ where
454454
signers.add_external(signer.id(&self.secp), ordering, signer);
455455
}
456456

457+
/// Get the signers
458+
///
459+
/// ## Example
460+
///
461+
/// ```
462+
/// # use bdk::{Wallet, KeychainKind};
463+
/// # use bdk::bitcoin::Network;
464+
/// # use bdk::database::MemoryDatabase;
465+
/// let wallet = Wallet::new_offline("wpkh(tprv8ZgxMBicQKsPe73PBRSmNbTfbcsZnwWhz5eVmhHpi31HW29Z7mc9B4cWGRQzopNUzZUT391DeDJxL2PefNunWyLgqCKRMDkU1s2s8bAfoSk/84'/0'/0'/0/*)", None, Network::Testnet, MemoryDatabase::new())?;
466+
/// for secret_key in wallet.get_signers(KeychainKind::External).signers().iter().filter_map(|s| s.descriptor_secret_key()) {
467+
/// // secret_key: tprv8ZgxMBicQKsPe73PBRSmNbTfbcsZnwWhz5eVmhHpi31HW29Z7mc9B4cWGRQzopNUzZUT391DeDJxL2PefNunWyLgqCKRMDkU1s2s8bAfoSk/84'/0'/0'/0/*
468+
/// println!("secret_key: {}", secret_key);
469+
/// }
470+
///
471+
/// Ok::<(), Box<dyn std::error::Error>>(())
472+
/// ```
473+
pub fn get_signers(&self, keychain: KeychainKind) -> Arc<SignersContainer> {
474+
match keychain {
475+
KeychainKind::External => Arc::clone(&self.signers),
476+
KeychainKind::Internal => Arc::clone(&self.change_signers),
477+
}
478+
}
479+
457480
/// Add an address validator
458481
///
459482
/// See [the `address_validator` module](address_validator) for an example.
460483
pub fn add_address_validator(&mut self, validator: Arc<dyn AddressValidator>) {
461484
self.address_validators.push(validator);
462485
}
463486

487+
/// Get the address validators
488+
pub fn get_address_validators(&self) -> &[Arc<dyn AddressValidator>] {
489+
&self.address_validators
490+
}
491+
464492
/// Start building a transaction.
465493
///
466494
/// This returns a blank [`TxBuilder`] from which you can specify the parameters for the transaction.
@@ -1132,6 +1160,11 @@ where
11321160
descriptor
11331161
}
11341162

1163+
/// Returns whether the wallet has a dedicated internal descriptor
1164+
pub fn has_internal_descriptor(&self) -> bool {
1165+
self.change_descriptor.is_some()
1166+
}
1167+
11351168
// Internals
11361169

11371170
fn _get_descriptor_for_keychain(

0 commit comments

Comments
 (0)