-
Notifications
You must be signed in to change notification settings - Fork 37.7k
wallet: Replace use of purpose strings with an enum #27217
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
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nits
87f8f8b
to
44a2ae1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nice change, and I started reviewing 44a2ae1, but it looks like there are a lot of functions taking optional<AddressPurpose>
values that should more properly take AddressPurpose
values for simplicity and better type checking. (Basically NotifyAddressBookChanged
and all the functions it calls). I think this might stem from not having separate SetAddressBook and UpdateAddressBook functions, so I want to look into this before reviewing more of the PR. (Having separate functions could help because Set function could make purpose a required parameter, while the Update function could let it be it optional).
I made some changes to this in a branch that could be adopted https://github.com/ryanofsky/bitcoin/commits/review.27217.1-edit
|
44a2ae1
to
db521d3
Compare
I've adopted these changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK db521d3. Thanks for adopting suggested changes. I left some new suggestions, but they are not important and can be ignored.
I think this PR should be straightforward for others to review now, and nice because it should demystify the purpose field and wallet address book as a whole.
|
||
WalletAddress(CTxDestination dest, wallet::isminetype is_mine, std::string name, std::string purpose) | ||
: dest(std::move(dest)), is_mine(is_mine), name(std::move(name)), purpose(std::move(purpose)) | ||
WalletAddress(CTxDestination dest, wallet::isminetype is_mine, wallet::AddressPurpose purpose, std::string name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "wallet: Replace use of purpose strings with an enum" (db521d3)
Note for reviewers: in a few places in this PR, struct order or argument order is changed so the AddressPurpose
field follows IsMine or IsChange fields. This is done because the fields hold overlapping information, and in most cases new code should rely on the other fields instead of AddressPurpose
.
@@ -677,7 +677,7 @@ RPCHelpMan getaddressesbylabel() | |||
// std::set in O(log(N))), UniValue::__pushKV is used instead, | |||
// which currently is O(1). | |||
UniValue value(UniValue::VOBJ); | |||
value.pushKV("purpose", _purpose); | |||
value.pushKV("purpose", _purpose ? PurposeToString(*_purpose) : "unknown"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "wallet: Replace use of purpose strings with an enum" (db521d3)
Note for reviewers: this is preserving previous behavior. Default value for CAddressBook::purpose
field previously was "unknown"
when a purpose was not recorded, and now it is null which is translated to "unknown"
a797f99
to
0d18142
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK 0d18142. Suggested a few comment/whitespace tweaks, but this is also fine as-is.
0d18142
to
a48010f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK a48010f. Just comment and whitespace changes since last review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK a48010f, looks good to me.
a48010f
to
98821a7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK 98821a7. Just suggested changes since last review, the main one being changing translateTransactionType
to use a switch statement.
This had 3 reviews before, so it would be nice to have reacks and hopefully merge this soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 98821a7
98821a7
to
635c50a
Compare
ACK 635c50a |
reACK 635c50a but appears to need rebase |
Move isminetype and isminefilter there this commit, add WalletPurpose type next commit.
Instead of storing and passing around fixed strings for the purpose of an address, use an enum. This also rationalizes the CAddressBookData struct, documenting all fields and making them public, and simplifying the representation to avoid bugs like bitcoin#26761 (comment) and make it not possible to invalid address data like change addresses with labels. Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
635c50a
to
18fc71a
Compare
reACK 18fc71a |
bool invoked = QMetaObject::invokeMethod(walletmodel, "updateAddressBook", | ||
Q_ARG(QString, strAddress), | ||
Q_ARG(QString, strLabel), | ||
Q_ARG(bool, isMine), | ||
Q_ARG(QString, strPurpose), | ||
Q_ARG(wallet::AddressPurpose, purpose), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change appears to trigger this assert when executing "getnewaddress" from the Console:
Assertion failed: (invoked), function NotifyAddressBookChanged, file walletmodel.cpp, line 392.
debug.log shows this error message:
GUI: QMetaMethod::invoke: Unable to handle unregistered datatype 'wallet::AddressPurpose'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, opened an issue here to follow up: bitcoin-core/gui#725.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in bitcoin-core/gui#726.
a45b544 qt: Register `wallet::AddressPurpose` type (Hennadii Stepanov) Pull request description: This PR is a follow up of bitcoin/bitcoin#27217. Fixes #725. ACKs for top commit: achow101: ACK a45b544 furszy: Tested ACK a45b544 Tree-SHA512: c670f4bf56442613d3fe038b0ba21acfcd4c69aa5340072e9a77d83f5fab1bf2facd87a9e1f42d88f496d277b27b79e7090444d59a9b9e71f3b486e171daa669
a45b544 qt: Register `wallet::AddressPurpose` type (Hennadii Stepanov) Pull request description: This PR is a follow up of bitcoin#27217. Fixes bitcoin#725. ACKs for top commit: achow101: ACK a45b544 furszy: Tested ACK a45b544 Tree-SHA512: c670f4bf56442613d3fe038b0ba21acfcd4c69aa5340072e9a77d83f5fab1bf2facd87a9e1f42d88f496d277b27b79e7090444d59a9b9e71f3b486e171daa669
Instead of storing and passing around fixed strings for the purpose of an address, use an enum.