From b854c78dde8658ffae0c0c1f1be5679fc3bb516c Mon Sep 17 00:00:00 2001 From: Ed Ball Date: Sat, 28 Jan 2023 19:10:54 +0100 Subject: [PATCH] feat: expose get_internal_address --- bdk-ffi/src/bdk.udl | 3 +++ bdk-ffi/src/wallet.rs | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/bdk-ffi/src/bdk.udl b/bdk-ffi/src/bdk.udl index f9c38b2..374ba64 100644 --- a/bdk-ffi/src/bdk.udl +++ b/bdk-ffi/src/bdk.udl @@ -212,6 +212,9 @@ interface Wallet { [Throws=BdkError] AddressInfo get_address(AddressIndex address_index); + [Throws=BdkError] + AddressInfo get_internal_address(AddressIndex address_index); + [Throws=BdkError] Balance get_balance(); diff --git a/bdk-ffi/src/wallet.rs b/bdk-ffi/src/wallet.rs index 29daf4b..a5ef145 100644 --- a/bdk-ffi/src/wallet.rs +++ b/bdk-ffi/src/wallet.rs @@ -88,6 +88,22 @@ impl Wallet { .map(AddressInfo::from) } + /// Return a derived address using the internal (change) descriptor. + /// + /// If the wallet doesn't have an internal descriptor it will use the external descriptor. + /// + /// see [`AddressIndex`] for available address index selection strategies. If none of the keys + /// in the descriptor are derivable (i.e. does not end with /*) then the same address will always + /// be returned for any [`AddressIndex`]. + pub(crate) fn get_internal_address( + &self, + address_index: AddressIndex, + ) -> Result { + self.get_wallet() + .get_internal_address(address_index.into()) + .map(AddressInfo::from) + } + /// Return the balance, meaning the sum of this wallet’s unspent outputs’ values. Note that this method only operates /// on the internal database, which first needs to be Wallet.sync manually. pub(crate) fn get_balance(&self) -> Result {