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

refactor: Make paths to update Encryption and HD wallet statuses simpler #403

Merged
merged 4 commits into from
Aug 26, 2021

Conversation

hebasto
Copy link
Member

@hebasto hebasto commented Aug 11, 2021

This PR makes signal-slot paths to reach setHDStatus and setEncryptionStatus functions shorter and easier to reason about them.

Required to simplify #398 (see #398 (comment)).


Note for reviewers. Please verify that "Encrypt Wallet..." menu item, and the following icons

DeepinScreenshot_select-area_20210811202120

and updated properly in each and every possible scenario.

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

Code review ACK ba9a309. All these cleanups do look good and seem to simplify things without changing behavior.

@@ -103,7 +103,8 @@ void WalletFrame::setCurrentWallet(WalletModel* wallet_model)
walletView->updateGeometry();

walletStack->setCurrentWidget(walletView);
walletView->updateEncryptionStatus();
Copy link
Contributor

Choose a reason for hiding this comment

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

In commit "qt: Add WalletFrame::currentWalletSet signal" (c0f84d9)

Note: At was unclear to me at first if this commit was changing behavior. But it does not seem to change anything since the previous updateEncryptionStatus just called updateWalletStatus indirectly.

The connection of the WalletFrame::currentWalletSet signal to
the BitcoinGUI::updateWalletStatus is a shorter and more descriptive way
to call both the setHDStatus and setEncryptionStatus member functions of
the BitcoinGUI class in comparison to using of the
WalletView::updateEncryptionStatus slot.
This job will be done by WalletFrame::currentWalletSet signal being
emitted in the WalletFrame::setCurrentWallet function.
There are no ways BitcoinGUI::updateWalletStatus being called without
an instance of the WalletFrame class.
@hebasto
Copy link
Member Author

hebasto commented Aug 14, 2021

Rebased ba9a309 -> b8aa84b (pr403.01 -> pr403.02) due to the conflict with #399.

@@ -113,6 +113,7 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformSty
connect(walletFrame, &WalletFrame::message, [this](const QString& title, const QString& message, unsigned int style) {
this->message(title, message, style);
});
connect(walletFrame, &WalletFrame::currentWalletSet, [this] { updateWalletStatus(); });

Choose a reason for hiding this comment

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

Do we really need to wrap that call with lambda? I see that updateWalletStatus is already a slot, or am I missing something?

Copy link
Member Author

@hebasto hebasto Aug 17, 2021

Choose a reason for hiding this comment

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

UPDATED: #403 (comment)
No, we don't.

The small benefit is that my editor could easy find this call site of updateWalletStatus() function member. It fails to find it by pointer &BitcoinGUI::updateWalletStatus.

Are there any drawbacks of such an approach?

Copy link
Member

Choose a reason for hiding this comment

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

The drawback is writing more verbose / unnecessary code, for no reason other than to appease your editor. If it's been questioned during review, it's just as likely someone will open a PR to remove it later on, citing the same reasoning, that, it's confusing / unnecessary. We really shouldn't be bloating our codebase just because your editor doesn't work.

Copy link
Member Author

@hebasto hebasto Aug 25, 2021

Choose a reason for hiding this comment

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

I strictly prefer QObject::connect(const QObject *sender, PointerToMemberFunction signal, Functor functor) overload over QObject::connect(const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type) one for the following reasons:

  • the former states the used signal-slot parameters explicitly, i.e., here it is clear that we use no signal parameters
  • the former is less verbose, compare [this] { updateWalletStatus(); } vs this, &BitcoinGUI::updateWalletStatus

We really shouldn't be bloating our codebase just because your editor doesn't work.

Absolutely agree. But this is not that case, no?

Btw, this--very helpful--syntax is already actively used in the code base. E.g. bitcoin/bitcoin#14123 and other prs by @promag.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for providing the actual reasoning; this should have been the first comment. I don't really have an opinion on the code, but was always going to leave the response above, regardless of the change, because the justification "it's better for my editor", is not a good one.

Copy link
Member Author

Choose a reason for hiding this comment

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

I apologize for that.

Copy link
Member

Choose a reason for hiding this comment

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

No worries. No need for an apology. Feel free to mark as resolved and merge etc.

Choose a reason for hiding this comment

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

Are there any drawbacks of such an approach?

It simply looks like unnecessary indirection, and at least raises question "why?" for some random future code reader.

Also, "verbosiness" of [this] { updateWalletStatus(); } vs this, &BitcoinGUI::updateWalletStatus is, IMHO, debatable. Former has more of []{();} vs $:: "eye-piercing" stuff . But that's probably just personal preference :) .

I like argument that we explicitly see (absence of) arguments, though I would expect lambda usage for actually more complex invocation where you do have to fiddle with arguments, etc.

Anyway, not gonna resist too much, would still give ACK.

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

Code review ACK b8aa84b. Only change since last review was rebase

@jarolrod
Copy link
Member

tACK b8aa84b

tested on Ubuntu 20.04, and macOS 12. I compared the behavior of the icons as I expect them on master with this PR. I cannot guarantee that I tested every variation possible, but my test wallets do cover a wide range of scenarios.

Notes on commits

  • 7d0d4c0
    • This is infact a simplification of the logic here
    • as stated by @ryanofsky, updateEncryptionStatus calls updateWalletStatus and so there is no behavior change here
      connect(wallet_view, &WalletView::encryptionStatusChanged, this, &BitcoinGUI::updateWalletStatus);
  • 37dcf16
    • nice cleanup
  • fcdc8b0
    • these are in fact now made redundant
  • b8aa84b
    • this is not needed for the goals of this PR, but is a nice cleanup

@Talkless
Copy link

Code review ACK b8aa84b. Did build on Debian Sid with Qt 5.15.2 but no actual testing performed.

@hebasto hebasto merged commit 774a4f5 into bitcoin-core:master Aug 26, 2021
@hebasto hebasto deleted the 210811-hd branch August 26, 2021 13:41
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 28, 2021
@bitcoin-core bitcoin-core locked as resolved and limited conversation to collaborators Aug 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants