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

docs(wallet): reword the next_unused_address doc #1680

Conversation

oleonardolima
Copy link
Contributor

@oleonardolima oleonardolima commented Nov 12, 2024

Description

Adds an example on what used stands for, and make it explicit that it
has the same behavior as Wallet::reveal_next_address in the scenario
where all previously revealed addresses have been used.

Notes to the reviewers

Is there any other behavior of next_unused_address we'd need to make clear through documentation ?

Changelog notice

  • Improve the Wallet::next_unused_address documentation to better describe expected behavior/usage.

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

Bugfixes:

  • This pull request breaks the existing API
  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

@notmandatory notmandatory added module-wallet api A breaking API change labels Nov 15, 2024
@notmandatory notmandatory added this to the 1.0.0-beta milestone Nov 15, 2024
@oleonardolima oleonardolima force-pushed the refactor/next-unused-address-rename-to-last-unused-address branch from 168fbbe to 83f86cd Compare November 19, 2024 03:30
@oleonardolima oleonardolima marked this pull request as ready for review November 19, 2024 03:34
@oleonardolima oleonardolima force-pushed the refactor/next-unused-address-rename-to-last-unused-address branch from 83f86cd to 07b85ca Compare November 19, 2024 03:36
notmandatory
notmandatory previously approved these changes Nov 19, 2024
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 07b85ca

New name looks good to me.

@evanlinjin
Copy link
Member

Okay thinking about it, this method actually returns the earliest unused...

@notmandatory
Copy link
Member

lets make this a doc only change

@notmandatory notmandatory added documentation Improvements or additions to documentation and removed api A breaking API change labels Nov 20, 2024
@notmandatory notmandatory removed this from the 1.0.0-beta milestone Nov 20, 2024
@oleonardolima
Copy link
Contributor Author

As per last call discussion, I'll repurpose this PR to keep next_unused_address API, focusing only on improving the current documentation.

@notmandatory notmandatory dismissed their stale review November 21, 2024 18:15

Will re-review after new direction changes pushed.

@Ademan
Copy link

Ademan commented Dec 3, 2024

FWIW the docs tripped me up a bit, such that I was confused what the actual difference between next_unused_address() and reveal_next_address() was for a short while.

On subsequent readings it's perfectly clear, so I might have just been careless in my first reading...

But I think the distinction between "used" and "derived" was not in my mind on my first reading.

    /// This will attempt to derive and reveal a new address if no newly revealed addresses
    /// are available. See also [`reveal_next_address`](Self::reveal_next_address).

Maybe instead of "available" it could be "unused" ? ("available" sent my mind to the generated key pools of pre-HD wallet bitcoin core)

and/or at the risk of repeating nearly the same thing as the first and second lines, add something like

"If any previously derived addresses are unused, next_unused_address() returns the one with the lowest derivation index, otherwise it derives a new address."

@ValuedMammal
Copy link
Contributor

@Ademan That's a great suggestion, thanks for weighing in on this. Here's another way we could word it as well:

    /// This will attempt to reveal a new address if all previously revealed addresses have
    /// been used, in which case the returned address will be the same as calling
    /// [`reveal_next_address`].

@Ademan
Copy link

Ademan commented Dec 4, 2024

@Ademan That's a great suggestion, thanks for weighing in on this. Here's another way we could word it as well:

    /// This will attempt to reveal a new address if all previously revealed addresses have
    /// been used, in which case the returned address will be the same as calling
    /// [`reveal_next_address`].

I like that! It directly contrasts the two calls.

As a side note, is there are reason why BDK uses the word "reveal" instead of "derive" in the API?

@ValuedMammal
Copy link
Contributor

As a side note, is there are reason why BDK uses the word "reveal" instead of "derive" in the API?

When you create a wallet we first derive a number of addresses (script pubkeys) and store them internally. When you reveal an address, it comes from the pool of derived scripts. The concept of "revealing" exists for the purpose of keeping track of the highest index that we've uncovered. An address is considered "used" when you receive a transaction paying to that address.

@oleonardolima oleonardolima force-pushed the refactor/next-unused-address-rename-to-last-unused-address branch from 07b85ca to 7ece14a Compare December 4, 2024 18:35
@oleonardolima oleonardolima changed the title refactor(wallet)!: rename method to last_unused_address docs(wallet): reword the next_unused_address doc Dec 4, 2024
@oleonardolima
Copy link
Contributor Author

oleonardolima commented Dec 4, 2024

Thanks for the suggestions.

I repurposed the PR to have only the documentation change: i) added a statement on what used stands for, and ii) applied the VM's suggestion in the second section.

Copy link
Member

@thunderbiscuit thunderbiscuit left a comment

Choose a reason for hiding this comment

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

ACK 7ece14a.

@oleonardolima
Copy link
Contributor Author

@notmandatory @ValuedMammal do we want to get this one in for 1.0? Any other required changes?

@oleonardolima oleonardolima force-pushed the refactor/next-unused-address-rename-to-last-unused-address branch from 7ece14a to bcc5329 Compare December 12, 2024 19:16
Copy link
Contributor

@ValuedMammal ValuedMammal left a comment

Choose a reason for hiding this comment

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

self-ACK d051e73

@notmandatory
Copy link
Member

@oleonardolima please just squash the commits and then we can merge this one.

@notmandatory notmandatory added this to the 1.0.0-beta milestone Dec 13, 2024
docs(wallet): reword the `next_unused_address` doc

Adds an example on what `used` stands for, and make it explicit that it
has the same behavior as `Wallet::reveal_next_address` in the scenario
where all previously revealed addresses have been used.

docs(wallet): fix typo in doc comment
@oleonardolima oleonardolima force-pushed the refactor/next-unused-address-rename-to-last-unused-address branch from d051e73 to b39cf08 Compare December 13, 2024 12:45
@oleonardolima
Copy link
Contributor Author

oleonardolima commented Dec 13, 2024

@oleonardolima please just squash the commits and then we can merge this one.

Done b39cf08, sorry for the typo.

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 b39cf08

Copy link
Contributor

@ValuedMammal ValuedMammal left a comment

Choose a reason for hiding this comment

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

ACK b39cf08

@notmandatory notmandatory merged commit c53781b into bitcoindevkit:master Dec 13, 2024
21 checks passed
@oleonardolima oleonardolima deleted the refactor/next-unused-address-rename-to-last-unused-address branch December 13, 2024 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation module-wallet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants