Skip to content

Conversation

promag
Copy link
Contributor

@promag promag commented Jan 4, 2019

This PR is a subset of the work done in the context of #13100. This change consists in extracting from the application class the code that manages the wallet models.

The role of the WalletController instance is to coordinate wallet operations and the window.

@fanquake fanquake added the GUI label Jan 4, 2019
@promag promag force-pushed the 2019-01-walletcontroller branch 3 times, most recently from d7d57d7 to f9b606e Compare January 4, 2019 21:21
@promag
Copy link
Contributor Author

promag commented Jan 4, 2019

Split in multiple commits for easier review.

@promag promag force-pushed the 2019-01-walletcontroller branch 4 times, most recently from 4bb0233 to 23aae3d Compare January 5, 2019 15:30
@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 5, 2019

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

No conflicts as of last run.

Copy link
Member

@Sjors Sjors left a comment

Choose a reason for hiding this comment

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

tACK 23aae3d on macOS 10.14.2 with QT 5.11.2, also with --disable-wallet, with and without BIP70.

I'm not sure how to test unloading of wallets; it tends to return "unable to".

Without wallet there's a warning:

qt/rpcconsole.cpp:908:22: warning: unused variable 'wallet_model' [-Wunused-variable]
        WalletModel* wallet_model{nullptr};

#14784 is merged now, so you can edit the top comment

Maybe move qRegisterMetaType into the controller so you can remove the walletmodel.h dependency from qt/bitcoin.cpp?

@promag promag force-pushed the 2019-01-walletcontroller branch from 45ecc25 to 5e4cb35 Compare January 7, 2019 22:42
@Sjors
Copy link
Member

Sjors commented Jan 9, 2019

re-tACK 5e4cb35, it seems to fix the crashes we discussed on IRC.

I noticed you removed the qRegisterMetaType<WalletModel> line completely. What was its purpose? And why can this one be removed but not the other ones?

Copy link
Contributor

@jnewbery jnewbery 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. A few comments and questions inline.

I agree with Sjors that m_history is unnecessary and should be dropped from this PR.

@promag promag force-pushed the 2019-01-walletcontroller branch from 5e4cb35 to 744f0e3 Compare January 12, 2019 02:49
@promag promag force-pushed the 2019-01-walletcontroller branch from 744f0e3 to 20f11da Compare January 12, 2019 11:01
@promag
Copy link
Contributor Author

promag commented Jan 12, 2019

Rebased with #15149 to avoid conflicts.

@promag promag force-pushed the 2019-01-walletcontroller branch from 20f11da to 3c50d90 Compare January 12, 2019 11:12
@promag promag force-pushed the 2019-01-walletcontroller branch 4 times, most recently from e79abc7 to 89fa546 Compare January 14, 2019 14:11
Copy link
Contributor

@jnewbery jnewbery left a comment

Choose a reason for hiding this comment

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

Lightly tested ACK 89fa546e8211aa47c96e20ba2a80507acd125539.

One question inline.

@promag promag force-pushed the 2019-01-walletcontroller branch from 89fa546 to a9a3069 Compare January 14, 2019 22:27
@promag
Copy link
Contributor Author

promag commented Jan 14, 2019

@jnewbery done.

@promag
Copy link
Contributor Author

promag commented Jan 16, 2019

Rebased.

Copy link
Member

@Sjors Sjors left a comment

Choose a reason for hiding this comment

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

tACK 1316f57

By the way, I'm seeing the following warning when compiling with --disable-wallet, probably from a previous commit:

qt/rpcconsole.cpp:909:22: warning: unused variable 'wallet_model' [-Wunused-variable]
        WalletModel* wallet_model{nullptr};
                     ^

@@ -599,13 +615,19 @@ void BitcoinGUI::setCurrentWallet(WalletModel* wallet_model)
{
if (!walletFrame) return;
walletFrame->setCurrentWallet(wallet_model);
for (int index = 0; index < m_wallet_selector->count(); ++index) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: ->itemData() can give you an iterator, which you can use for the loop, to prevent out of bounds accidents: http://doc.qt.io/qt-5/qvariant.html

Maybe it also has a helper to just find the index you need directly.

/**
* WalletController
*/
class WalletController : public QObject
Copy link
Member

Choose a reason for hiding this comment

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

Nit: WalletsController?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

heh 😛avoid plural?

Copy link
Member

Choose a reason for hiding this comment

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

Plural makes it clear that this controls multiple wallets, rather than one controller per wallet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I prefer to interpret it as the "gui controller of the wallet related things". Let's see what others say and I'll happily rename.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think either is fine.

Copy link
Member

Choose a reason for hiding this comment

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

Tech language prefers a singular form; e.g., "window manager", "file manager" etc.

@promag
Copy link
Contributor Author

promag commented Jan 16, 2019

@Sjors in #15150 b669ba6 that warning is removed.

Thanks for reviewing!

@jnewbery
Copy link
Contributor

jnewbery commented Jan 17, 2019

Tested ACK 1316f5706891bb94428078e874e761931ff0e087

Only difference is rebasing on master and removing the unused WalletController::getWalletsAvailableToLoad()

EDIT: pasted incorrect commit id. Now fixed

@promag promag force-pushed the 2019-01-walletcontroller branch from 1316f57 to 1b82938 Compare January 17, 2019 23:31
@promag promag force-pushed the 2019-01-walletcontroller branch from 1b82938 to 0dd9bde Compare January 18, 2019 00:40
@promag
Copy link
Contributor Author

promag commented Jan 18, 2019

Refactored a bit to simplify follow ups.

Copy link
Member

@Sjors Sjors left a comment

Choose a reason for hiding this comment

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

re-tACK 0dd9bde

@@ -376,7 +376,7 @@ bool WalletModel::changePassphrase(const SecureString &oldPass, const SecureStri
static void NotifyUnload(WalletModel* walletModel)
{
qDebug() << "NotifyUnload";
QMetaObject::invokeMethod(walletModel, "unload", Qt::QueuedConnection);
QMetaObject::invokeMethod(walletModel, "unload");
Copy link
Member

@Sjors Sjors Jan 18, 2019

Choose a reason for hiding this comment

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

Can you elaborate on why this is safe? I'm still wrapping my head around how QT deals with threads: http://doc.qt.io/qt-5/qobject.html#thread-affinity

Is it similar to iOs where the UI can only be touched from the main thread, but notifications tend to arrive on different threads, leading to nasty crashes if you don't pay attention? How do you know which thread NotifyUnload is called on?

Copy link
Contributor Author

@promag promag Jan 18, 2019

Choose a reason for hiding this comment

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

I think https://woboq.com/blog/how-qt-signals-slots-work.html is a good read.

Each QObject belongs to one thread which must have one event loop spinning. With the default AutoConnection Qt ensures that the slot is executed in the receiver thread, so it either calls the slot directly (if the emit happens in the same thread) or enqueues an event (with all signal arguments) in the receiver event loop.

@jnewbery
Copy link
Contributor

utACK 0dd9bde

@jonasschnelli
Copy link
Contributor

Tested ACK 0dd9bde

@jonasschnelli jonasschnelli merged commit 0dd9bde into bitcoin:master Jan 18, 2019
jonasschnelli added a commit that referenced this pull request Jan 18, 2019
0dd9bde gui: Refactor to use WalletController (João Barbosa)
8fa271f gui: Add WalletController (João Barbosa)
cefb399 gui: Use AutoConnection for WalletModel::unload signal (João Barbosa)

Pull request description:

  This PR is a subset of the work done in the context of #13100. This change consists in extracting from the application class the code that manages the wallet models.

  The role of the `WalletController` instance is to coordinate wallet operations and the window.

Tree-SHA512: 6a824054376730eb7d16c643dd2003f5f60778e8ad3af707b82bc12c48438db179ca4446316b28fb17b206f4b9aba8998419aab8c5dd1f7c32467015732b5094
@promag promag deleted the 2019-01-walletcontroller branch January 18, 2019 20:38
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 8, 2021
0dd9bde gui: Refactor to use WalletController (João Barbosa)
8fa271f gui: Add WalletController (João Barbosa)
cefb399 gui: Use AutoConnection for WalletModel::unload signal (João Barbosa)

Pull request description:

  This PR is a subset of the work done in the context of bitcoin#13100. This change consists in extracting from the application class the code that manages the wallet models.

  The role of the `WalletController` instance is to coordinate wallet operations and the window.

Tree-SHA512: 6a824054376730eb7d16c643dd2003f5f60778e8ad3af707b82bc12c48438db179ca4446316b28fb17b206f4b9aba8998419aab8c5dd1f7c32467015732b5094
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 10, 2021
0dd9bde gui: Refactor to use WalletController (João Barbosa)
8fa271f gui: Add WalletController (João Barbosa)
cefb399 gui: Use AutoConnection for WalletModel::unload signal (João Barbosa)

Pull request description:

  This PR is a subset of the work done in the context of bitcoin#13100. This change consists in extracting from the application class the code that manages the wallet models.

  The role of the `WalletController` instance is to coordinate wallet operations and the window.

Tree-SHA512: 6a824054376730eb7d16c643dd2003f5f60778e8ad3af707b82bc12c48438db179ca4446316b28fb17b206f4b9aba8998419aab8c5dd1f7c32467015732b5094
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 10, 2021
0dd9bde gui: Refactor to use WalletController (João Barbosa)
8fa271f gui: Add WalletController (João Barbosa)
cefb399 gui: Use AutoConnection for WalletModel::unload signal (João Barbosa)

Pull request description:

  This PR is a subset of the work done in the context of bitcoin#13100. This change consists in extracting from the application class the code that manages the wallet models.

  The role of the `WalletController` instance is to coordinate wallet operations and the window.

Tree-SHA512: 6a824054376730eb7d16c643dd2003f5f60778e8ad3af707b82bc12c48438db179ca4446316b28fb17b206f4b9aba8998419aab8c5dd1f7c32467015732b5094
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 18, 2021
0dd9bde gui: Refactor to use WalletController (João Barbosa)
8fa271f gui: Add WalletController (João Barbosa)
cefb399 gui: Use AutoConnection for WalletModel::unload signal (João Barbosa)

Pull request description:

  This PR is a subset of the work done in the context of bitcoin#13100. This change consists in extracting from the application class the code that manages the wallet models.

  The role of the `WalletController` instance is to coordinate wallet operations and the window.

Tree-SHA512: 6a824054376730eb7d16c643dd2003f5f60778e8ad3af707b82bc12c48438db179ca4446316b28fb17b206f4b9aba8998419aab8c5dd1f7c32467015732b5094
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 18, 2021
0dd9bde gui: Refactor to use WalletController (João Barbosa)
8fa271f gui: Add WalletController (João Barbosa)
cefb399 gui: Use AutoConnection for WalletModel::unload signal (João Barbosa)

Pull request description:

  This PR is a subset of the work done in the context of bitcoin#13100. This change consists in extracting from the application class the code that manages the wallet models.

  The role of the `WalletController` instance is to coordinate wallet operations and the window.

Tree-SHA512: 6a824054376730eb7d16c643dd2003f5f60778e8ad3af707b82bc12c48438db179ca4446316b28fb17b206f4b9aba8998419aab8c5dd1f7c32467015732b5094
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 18, 2021
0dd9bde gui: Refactor to use WalletController (João Barbosa)
8fa271f gui: Add WalletController (João Barbosa)
cefb399 gui: Use AutoConnection for WalletModel::unload signal (João Barbosa)

Pull request description:

  This PR is a subset of the work done in the context of bitcoin#13100. This change consists in extracting from the application class the code that manages the wallet models.

  The role of the `WalletController` instance is to coordinate wallet operations and the window.

Tree-SHA512: 6a824054376730eb7d16c643dd2003f5f60778e8ad3af707b82bc12c48438db179ca4446316b28fb17b206f4b9aba8998419aab8c5dd1f7c32467015732b5094
UdjinM6 added a commit to dashpay/dash that referenced this pull request Sep 18, 2021
thelazier pushed a commit to thelazier/dash that referenced this pull request Sep 25, 2021
0dd9bde gui: Refactor to use WalletController (João Barbosa)
8fa271f gui: Add WalletController (João Barbosa)
cefb399 gui: Use AutoConnection for WalletModel::unload signal (João Barbosa)

Pull request description:

  This PR is a subset of the work done in the context of bitcoin#13100. This change consists in extracting from the application class the code that manages the wallet models.

  The role of the `WalletController` instance is to coordinate wallet operations and the window.

Tree-SHA512: 6a824054376730eb7d16c643dd2003f5f60778e8ad3af707b82bc12c48438db179ca4446316b28fb17b206f4b9aba8998419aab8c5dd1f7c32467015732b5094
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants