pub fn export_wallet<B, D: BatchDatabase>(
        wallet: &Wallet<B, D>,
        label: &str,
        include_blockheight: bool,
    ) -> Result<Self, &'static str> {
        let descriptor = wallet
            .descriptor
            .to_string_with_secret(&wallet.signers.as_key_map(wallet.secp_ctx()));
        let descriptor = remove_checksum(descriptor);
        Self::is_compatible_with_core(&descriptor)?;

        let blockheight = match wallet.database.borrow().iter_txs(false) {
            _ if !include_blockheight => 0,
            Err(_) => 0,
            Ok(txs) => {
                let mut heights = txs
                    .into_iter()
                    .map(|tx| tx.confirmation_time.map(|c| c.height).unwrap_or(0))
                    .collect::<Vec<_>>();
                heights.sort_unstable();

                *heights.last().unwrap_or(&0)
            }
        };

        let export = WalletExport {
            descriptor,
            label: label.into(),
            blockheight,
        };

        let desc_to_string = |d: &Descriptor<DescriptorPublicKey>| {
            let descriptor =
                d.to_string_with_secret(&wallet.change_signers.as_key_map(wallet.secp_ctx()));
            remove_checksum(descriptor)
        };
        if export.change_descriptor() != wallet.change_descriptor.as_ref().map(desc_to_string) {
            return Err("Incompatible change descriptor");
        }

        Ok(export)
    }
/// Export a wallet
///
/// This function returns an error if it determines that the `wallet`'s descriptor(s) are not
/// supported by Bitcoin Core or don't follow the standard derivation paths defined by BIP44
/// and others.
///
/// If `include_blockheight` is `true`, this function will look into the `wallet`'s database
/// for the oldest transaction it knows and use that as the earliest block to rescan.
///
/// If the database is empty or `include_blockheight` is false, the `blockheight` field
/// returned will be `0`.
Export a wallet
This function returns an error if it determines that the `wallet`'s descriptor(s) are not
supported by Bitcoin Core or don't follow the standard derivation paths defined by BIP44
and others.




Export a wallet This function returns an error if it determines that the ` wallet ` ' s descriptor ( s ) are not supported by Bitcoin Core or don ' t follow the standard derivation paths defined by BIP44 and others .
pub fn export_wallet<B, D: BatchDatabase>(
        wallet: &Wallet<B, D>,
        label: &str,
        include_blockheight: bool,
    ) -> Result<Self, &'static str> {
        let descriptor = wallet
            .descriptor
            .to_string_with_secret(&wallet.signers.as_key_map(wallet.secp_ctx()));
        let descriptor = remove_checksum(descriptor);
        Self::is_compatible_with_core(&descriptor)?;
        let blockheight = match wallet.database.borrow().iter_txs(false) {
            _ if !include_blockheight => 0,
            Err(_) => 0,
            Ok(txs) => {
                let mut heights = txs
                    .into_iter()
                    .map(|tx| tx.confirmation_time.map(|c| c.height).unwrap_or(0))
                    .collect::<Vec<_>>();
                heights.sort_unstable();
                *heights.last().unwrap_or(&0)
            }
        };
        let export = WalletExport {
            descriptor,
            label: label.into(),
            blockheight,
        };
        let desc_to_string = |d: &Descriptor<DescriptorPublicKey>| {
            let descriptor =
                d.to_string_with_secret(&wallet.change_signers.as_key_map(wallet.secp_ctx()));
            remove_checksum(descriptor)
        };
        if export.change_descriptor() != wallet.change_descriptor.as_ref().map(desc_to_string) {
            return Err("Incompatible change descriptor");
        }
        Ok(export)
    }
pub fn export_wallet < B , D : BatchDatabase > ( wallet : & Wallet < B , D > , label : & str , include_blockheight : bool , ) -> Result < Self , & ' static str > { let descriptor = wallet . descriptor . to_string_with_secret ( & wallet . signers . as_key_map ( wallet . secp_ctx ( ) ) ) ; let descriptor = remove_checksum ( descriptor ) ; Self :: is_compatible_with_core ( & descriptor ) ? ; let blockheight = match wallet . database . borrow ( ) . iter_txs ( false ) { _ if ! include_blockheight => 0 , Err ( _ ) => 0 , Ok ( txs ) => { let mut heights = txs . into_iter ( ) . map ( | tx | tx . confirmation_time . map ( | c | c . height ) . unwrap_or ( 0 ) ) . collect :: < Vec < _ > > ( ) ; heights . sort_unstable ( ) ; * heights . last ( ) . unwrap_or ( & 0 ) } } ; let export = WalletExport { descriptor , label : label . into ( ) , blockheight , } ; let desc_to_string = | d : & Descriptor < DescriptorPublicKey > | { let descriptor = d . to_string_with_secret ( & wallet . change_signers . as_key_map ( wallet . secp_ctx ( ) ) ) ; remove_checksum ( descriptor ) } ; if export . change_descriptor ( ) != wallet . change_descriptor . as_ref ( ) . map ( desc_to_string ) { return Err ( " " ) ; } Ok ( export ) }
Export a wallet
This function returns an error if it determines that the `wallet`'s descriptor(s) are not
supported by Bitcoin Core or don't follow the standard derivation paths defined by BIP44
and others.
Export a wallet This function returns an error if it determines that the ` wallet ` ' s descriptor ( s ) are not supported by Bitcoin Core or don ' t follow the standard derivation paths defined by BIP44 and others .
wallet
&Wallet<B, D>
label
&str
include_blockheight
bool
wallet
&Wallet<B, D>
label
&str
include_blockheight
bool