[wallet] Add more getters

This commit is contained in:
Alekos Filini 2022-03-09 18:38:11 +01:00
parent 3334c8da07
commit 63d5bcee93
No known key found for this signature in database
GPG Key ID: 431401E4A4530061

View File

@ -456,6 +456,29 @@ where
signers.add_external(signer.id(&self.secp), ordering, signer); signers.add_external(signer.id(&self.secp), ordering, signer);
} }
/// Get the signers
///
/// ## Example
///
/// ```
/// # use bdk::{Wallet, KeychainKind};
/// # use bdk::bitcoin::Network;
/// # use bdk::database::MemoryDatabase;
/// let wallet = Wallet::new("wpkh(tprv8ZgxMBicQKsPe73PBRSmNbTfbcsZnwWhz5eVmhHpi31HW29Z7mc9B4cWGRQzopNUzZUT391DeDJxL2PefNunWyLgqCKRMDkU1s2s8bAfoSk/84'/0'/0'/0/*)", None, Network::Testnet, MemoryDatabase::new())?;
/// for secret_key in wallet.get_signers(KeychainKind::External).signers().iter().filter_map(|s| s.descriptor_secret_key()) {
/// // secret_key: tprv8ZgxMBicQKsPe73PBRSmNbTfbcsZnwWhz5eVmhHpi31HW29Z7mc9B4cWGRQzopNUzZUT391DeDJxL2PefNunWyLgqCKRMDkU1s2s8bAfoSk/84'/0'/0'/0/*
/// println!("secret_key: {}", secret_key);
/// }
///
/// Ok::<(), Box<dyn std::error::Error>>(())
/// ```
pub fn get_signers(&self, keychain: KeychainKind) -> Arc<SignersContainer> {
match keychain {
KeychainKind::External => Arc::clone(&self.signers),
KeychainKind::Internal => Arc::clone(&self.change_signers),
}
}
/// Add an address validator /// Add an address validator
/// ///
/// See [the `address_validator` module](address_validator) for an example. /// See [the `address_validator` module](address_validator) for an example.
@ -463,6 +486,11 @@ where
self.address_validators.push(validator); self.address_validators.push(validator);
} }
/// Get the address validators
pub fn get_address_validators(&self) -> &[Arc<dyn AddressValidator>] {
&self.address_validators
}
/// Start building a transaction. /// Start building a transaction.
/// ///
/// This returns a blank [`TxBuilder`] from which you can specify the parameters for the transaction. /// This returns a blank [`TxBuilder`] from which you can specify the parameters for the transaction.
@ -1556,6 +1584,18 @@ where
Ok(()) Ok(())
} }
/// Return the checksum of the public descriptor associated to `keychain`
///
/// Internally calls [`Self::get_descriptor_for_keychain`] to fetch the right descriptor
pub fn descriptor_checksum(&self, keychain: KeychainKind) -> String {
self.get_descriptor_for_keychain(keychain)
.to_string()
.splitn(2, '#')
.next()
.unwrap()
.to_string()
}
} }
/// Return a fake wallet that appears to be funded for testing. /// Return a fake wallet that appears to be funded for testing.