Skip to content

Change the visibility of the derived module and of the AsDerived trait#520

Closed
w0xlt wants to merge 1 commit intobitcoindevkit:masterfrom
w0xlt:change_derived_mod_visibility
Closed

Change the visibility of the derived module and of the AsDerived trait#520
w0xlt wants to merge 1 commit intobitcoindevkit:masterfrom
w0xlt:change_derived_mod_visibility

Conversation

@w0xlt
Copy link
Copy Markdown
Contributor

@w0xlt w0xlt commented Jan 9, 2022

There is currently no way to retrieve change addresses, so this PR changes the visibility of the derived module and the AsDerived trait.

With this change, the addresses can be retrieved using the function below, for example:

use bdk::descriptor::derived::AsDerived;

// ...

fn peek_change_address(&self, wallet: &Wallet<ElectrumBlockchain, MemoryDatabase>, index: u32) -> Result<AddressInfo, Error> {

        let result_descriptor = wallet.get_descriptor_for_keychain(bdk::KeychainKind::Internal);

        result_descriptor
            .as_derived(index, wallet.secp_ctx())
            .address(wallet.network())
            .map(|address| AddressInfo { index, address })
            .map_err(|_| Error::ScriptDoesntHaveAddressForm)
    }

Currently this module is visible only in the crate, so it
can't be accessed externally.
@LLFourn
Copy link
Copy Markdown
Collaborator

LLFourn commented Jan 10, 2022

I happened to need this feature for gun. Here's the (slightly messy) commit that adds the feature: LLFourn@e0950b9

I think this is a better way to do this. I'll see if I can clean up this commit and upstream it.

@LLFourn
Copy link
Copy Markdown
Collaborator

LLFourn commented Jan 11, 2022

Here I've made a PR that allows you to do this: #522

@rajarshimaitra
Copy link
Copy Markdown
Contributor

rajarshimaitra commented Jan 11, 2022

ACK, #522 is much cleaner way to do it.

@w0xlt
Copy link
Copy Markdown
Contributor Author

w0xlt commented Jan 11, 2022

Agree.
#522 is a better approach to achieve this change.
I will close this PR.

@w0xlt w0xlt closed this Jan 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants