Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API for internal addresses #522

Merged
merged 2 commits into from
Mar 2, 2022

Conversation

LLFourn
Copy link
Contributor

@LLFourn LLFourn commented Jan 11, 2022

There are good reasons for applications to need to get internal
addresses too. For example creating a transactions that splits an output
into several smaller ones.

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature
  • I've updated CHANGELOG.md

Copy link
Contributor

@rajarshimaitra rajarshimaitra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept + tACK 63f1ec0

I think it makes sense and the code looks good to me.

Copy link
Contributor

@w0xlt w0xlt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK 63f1ec0

I tested this commit with two wallets:

1 - with internal and external descriptors: worked as expected.

2- with external descriptor only: get_internal_address returns the same addresses as get_address.

Maybe if there is not an internal descriptor, a possible better approach would be to throw an error when calling get_internal_address .

But I think this behavior is not related to this PR. It happens because get_descriptor_for_keychain(keychain) apparently returns the same descriptor for internal and external keychain when the wallet is created with external descriptor only,

src/wallet/mod.rs Outdated Show resolved Hide resolved
@rajarshimaitra
Copy link
Contributor

Maybe if there is not an internal descriptor, a possible better approach would be to throw an error when calling get_internal_address .
But I think this behavior is not related to this PR. It happens because get_descriptor_for_keychain(keychain) apparently returns the same descriptor for internal and external keychain when the wallet is created with external descriptor only,

I think the get_descriptor_for_keychain() is written that way to make wallet api agnostic of change descriptor. Weather its there or not, all the logic will simply follow "use external if there's no internal". This simplifies internal logic handling at many places and doesn't force us to handle "no change desc case" separately. and the lib user just keep this in mind while using the wallet. Its also documented in many places.

So it makes sense to me to keep the behavior intact in peek_address too.

Copy link
Contributor

@rajarshimaitra rajarshimaitra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 89f88ce

Sorry I missed few others comment nits in last review, of the previous methods.

src/wallet/mod.rs Outdated Show resolved Hide resolved
src/wallet/mod.rs Outdated Show resolved Hide resolved
src/wallet/mod.rs Outdated Show resolved Hide resolved
@LLFourn
Copy link
Contributor Author

LLFourn commented Jan 25, 2022

comments addressed ready for further review.

@notmandatory
Copy link
Member

notmandatory commented Feb 2, 2022

I think docs are breaking because of a regression in rust +nightly, there seems to be a bug fix PR in the works so I think we should wait a couple days and see if that fixes it. See #538

@notmandatory
Copy link
Member

#538 is merged and fixes the docs issue, once you rebase this PR should be good to go.

Copy link
Member

@notmandatory notmandatory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, one small thing to fix in the new test.

.unwrap();

assert_eq!(
wallet.get_address(AddressIndex::New).unwrap().address,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't you be verifying that the internal address is the same as the external here?

Suggested change
wallet.get_address(AddressIndex::New).unwrap().address,
wallet.get_internal_address(AddressIndex::New).unwrap().address,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks fixed @notmandatory

@notmandatory
Copy link
Member

#538 is merged and fixes the docs issue, once you rebase this PR should be good to go.

I think you still need to rebase since this went in, that will fix the rust docs CI job.

@LLFourn
Copy link
Contributor Author

LLFourn commented Feb 16, 2022

@notmandatory new CI problem. Looks like tokio increased MSRV without major version bump. I think we should set MSRV for bdk to v1.56 (2021 edition) and leave it there.

@notmandatory
Copy link
Member

I guess we need to revisit and not close #331 .. at this point I agree the best option is set MSRV to rust 1.56, it's not the current stable for Debian.. but is being tested and should be shipped with next stable debian "bookworm" release. https://tracker.debian.org/pkg/rustc

LLFourn and others added 2 commits February 23, 2022 09:28
There are good reasons for applications to need to get internal
addresses too. For example creating a transactions that splits an output
into several smaller ones.
@LLFourn
Copy link
Contributor Author

LLFourn commented Feb 22, 2022

Rebased. Should be ready for merge after CI (hopefully) passes.

Copy link
Member

@notmandatory notmandatory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 022256c

@notmandatory notmandatory dismissed rajarshimaitra’s stale review March 2, 2022 04:48

Requested changes look to be resolved.

@bitcoindevkit bitcoindevkit deleted a comment from codecov bot Mar 2, 2022
@notmandatory notmandatory merged commit f0188f4 into bitcoindevkit:master Mar 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants