Module bdk::wallet::address_validator[][src]

Address validation callbacks

The typical usage of those callbacks is for displaying the newly-generated address on a hardware wallet, so that the user can cross-check its correctness.

More generally speaking though, these callbacks can also be used to “do something” every time an address is generated, without necessarily checking or validating it.

An address validator can be attached to a Wallet by using the Wallet::add_address_validator method, and whenever a new address is generated (either explicitly by the user with Wallet::get_address or internally to create a change address) all the attached validators will be polled, in sequence. All of them must complete successfully to continue.


struct PrintAddressAndContinue;

impl AddressValidator for PrintAddressAndContinue {
    fn validate(
        keychain: KeychainKind,
        hd_keypaths: &HdKeyPaths,
        script: &Script
    ) -> Result<(), AddressValidatorError> {
        let address = Address::from_script(script, Network::Testnet)
        println!("New address of type {:?}: {}", keychain, address);
        println!("HD keypaths: {:#?}", hd_keypaths);


let descriptor = "wpkh(tpubD6NzVbkrYhZ4Xferm7Pz4VnjdcDPFyjVu5K4iZXQ4pVN8Cks4pHVowTBXBKRhX64pkRyJZJN5xAKj4UDNnLPb5p2sSKXhewoYx5GbTdUFWq/*)";
let mut wallet = Wallet::new_offline(descriptor, None, Network::Testnet, MemoryDatabase::default())?;

let address = wallet.get_address(New)?;
println!("Address: {}", address);



Errors that can be returned to fail the validation of an address



Trait to build address validators