LtbLightning / bdk-flutter

Bitcoin Development Kit - Flutter Package
MIT License
60 stars 27 forks source link

How to create internal address #71

Closed awaik closed 1 year ago

awaik commented 1 year ago

Hi!

Do I understand correctly that with this method we can get only external address?

  ///Return a derived address using 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.
  Future<AddressInfo> getAddress({required AddressIndex addressIndex}) async {
    try {
      var res = await loaderApi.getAddress(
          wallet: _wallet!, addressIndex: addressIndex);
      return res;
    } on FfiException catch (e) {
      throw configException(e.message);
    }
  }

In the rust code there is a separate method

    pub(crate) fn get_internal_address(
        &self,
        address_index: AddressIndex,
    ) -> Result<AddressInfo, BdkError> {

So, the question is - how to get an internal address if I have an internal descriptor?

awaik commented 1 year ago

This is from BDK docs

A Wallet instance can be constructed given at least one descriptor which would be used to derive both External and Internal addresses, or two if one prefers to keep them separated. External addresses are the ones returned by the generic Wallet::get_address() call, while Internal addresses are generated internally to receive the change whenever a new transaction is created. But they can be generated on demand too using Wallet::get_internal_address()