Based on this comment #26761 (review).
This PR stores the currently inlined address purposes as constants and use them accordingly.
Based on this comment #26761 (review).
This PR stores the currently inlined address purposes as constants and use them accordingly.
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--021abf342d371248e50ceaed478a90ca-->
See the guideline for information on the review process. A summary of reviews will appear here.
<!--174a7506f384e20aa4161008e828411d-->
Reviewers, 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.
40 | @@ -41,6 +41,11 @@ struct WalletContext; 41 | using isminefilter = std::underlying_type<isminetype>::type; 42 | } // namespace wallet 43 | 44 | +static const std::string PURPOSE_CHANGE = "change";
there isn't a "change" purpose.
Whoops, thanks pushed.
5 | @@ -6,6 +6,7 @@ 6 | #define BITCOIN_WALLET_SPEND_H 7 | 8 | #include <consensus/amount.h> 9 | +#include <interfaces/wallet.h>
This introduces a circular dependency,
interfaces/wallet.h is implemented by wallet/interfaces.cpp which includes wallet/spend.h which, with this change, includes interfaces/wallet.h.
Thus why suggested to decouple it into a separate file (should check if we already have a file that serves this purpose).
wallet/spend.h doesn't even need to include this, so it could just be removed from there and not have any issues.
I don't think interfaces/wallet.h is the correct place for these constants to live, better would be perhaps wallet/wallet.h or wallet/walletutil.h. Additionally, there are some places in the GUI code that use the hardcoded strings, these should use the new constants too. The string constants could also be put inside of a AddressBookPurpose (or similar) namespace, in the same way that DBKeys are.
I moved the constants to src/wallet/wallet.h inside the new AddressBookPurposes namespace.
Additionally, there are some places in the GUI code that use the hardcoded strings, these should use the new constants too.
This should be a separate pull request in https://github.com/bitcoin-core/gui once this one is merged?
This should be a separate pull request in https://github.com/bitcoin-core/gui once this one is merged?
I think it's fine to do those at the same time here.
I don't think that we should continue adding wallet.h dependency on any GUI widget/view. It breaks the layers division structure. The GUI should be as abstracted as possible from the wallet/node internals (this is why all the interfaces and models classes exist).
Would suggest to move the strings to a separate file, or at least to walletutil.h so the required backend dependency is much smaller.
With wallet.h dependency the GUI can access the wallet context (calling the static function GetWallet()), and with it access any wallet directly, breaking the entire requirement of requesting data through the different layers of the system (in other words, could by-pass the need to call the interface/model methods to get backend data which is not desirable for the system architecture).
Closing in favor of #27217.