gui: Add WalletController #15101

pull promag wants to merge 3 commits into bitcoin:master from promag:2019-01-walletcontroller changing 8 files +202 −63
  1. promag commented at 12:25 pm on January 4, 2019: member

    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.

  2. fanquake added the label GUI on Jan 4, 2019
  3. promag force-pushed on Jan 4, 2019
  4. promag force-pushed on Jan 4, 2019
  5. promag force-pushed on Jan 4, 2019
  6. promag commented at 9:23 pm on January 4, 2019: member
    Split in multiple commits for easier review.
  7. promag force-pushed on Jan 4, 2019
  8. promag force-pushed on Jan 4, 2019
  9. promag force-pushed on Jan 4, 2019
  10. promag force-pushed on Jan 5, 2019
  11. DrahtBot commented at 4:42 pm on January 5, 2019: member

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

    Conflicts

    No conflicts as of last run.

  12. in src/qt/rpcconsole.cpp:706 in 6d545162c9 outdated
    701@@ -702,7 +702,7 @@ void RPCConsole::addWallet(WalletModel * const walletModel)
    702         // First wallet added, set to default so long as the window isn't presently visible (and potentially in use)
    703         ui->WalletSelector->setCurrentIndex(1);
    704     }
    705-    if (ui->WalletSelector->count() > 2) {
    


    Sjors commented at 3:16 pm on January 7, 2019:
    Why was this 2 in the past?

    promag commented at 4:23 pm on January 7, 2019:
    Before the wallet selector would be visible with only 2 wallets. However I think it makes sense to show the selector even with 1 wallet only because otherwise you can’t decide to execute unloadwallet with or without a wallet.

    promag commented at 11:06 am on January 12, 2019:
    Moved this to #15150.
  13. in src/qt/walletcontroller.h:54 in 0da9457583 outdated
    49+private:
    50+    interfaces::Node& m_node;
    51+    const PlatformStyle* const m_platform_style;
    52+    OptionsModel* const m_options_model;
    53+    std::vector<WalletModel*> m_wallets;
    54+    std::list<WalletModel*> m_history;
    


    Sjors commented at 3:55 pm on January 7, 2019:
    I’m confused, what is this m_history?

    promag commented at 4:33 pm on January 7, 2019:

    Sorry, should have some comment there. I’m also willing to remove this now and add it later.

    This is like the stack of wallets, the smaller the index the most recent viewed wallet. With this when the user closes a the current wallet it goes to the previous used wallet.


    Sjors commented at 1:16 pm on January 9, 2019:
    I have a light preference for dropping that functionality, unless someone is willing to write tests for it. I don’t expect users to be loading and unloading so often that a lack of history gets annoying.

    jnewbery commented at 6:58 pm on January 9, 2019:
    Agree that this is unnecessary.
  14. Sjors approved
  15. Sjors commented at 4:08 pm on January 7, 2019: member

    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:

    0qt/rpcconsole.cpp:908:22: warning: unused variable 'wallet_model' [-Wunused-variable]
    1        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?

  16. promag force-pushed on Jan 7, 2019
  17. Sjors commented at 1:33 pm on January 9, 2019: member

    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?

  18. in src/qt/bitcoingui.cpp:574 in 5e4cb35d16 outdated
    573+void BitcoinGUI::addWallet(WalletModel* walletModel)
    574 {
    575-    if(!walletFrame)
    576-        return false;
    577-    const QString display_name = walletModel->getDisplayName();
    578+    assert(walletFrame);
    


    jnewbery commented at 6:20 pm on January 9, 2019:
    I think this and the other assertions are ok (I’ve gone through and checked where walletFrame is set and where addWallet() is called), but why not just return early to minimize code change?

    promag commented at 11:05 am on January 12, 2019:
    I’ll leave these changes for later with a good rationale.
  19. in src/qt/bitcoingui.cpp:487 in 5e4cb35d16 outdated
    483@@ -483,7 +484,10 @@ void BitcoinGUI::createToolBars()
    484         toolbar->addWidget(spacer);
    485 
    486         m_wallet_selector = new QComboBox();
    487-        connect(m_wallet_selector, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &BitcoinGUI::setCurrentWalletBySelectorIndex);
    488+        connect(m_wallet_selector, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [this](int index) {
    


    jnewbery commented at 6:46 pm on January 9, 2019:
    I’m not sure if this lambda makes this any clearer. What’s the motivation for this change?
  20. in src/qt/walletcontroller.h:55 in 5e4cb35d16 outdated
    50+    interfaces::Node& m_node;
    51+    const PlatformStyle* const m_platform_style;
    52+    OptionsModel* const m_options_model;
    53+    std::vector<WalletModel*> m_wallets;
    54+    std::list<WalletModel*> m_history;
    55+    BitcoinGUI* m_window{nullptr};
    


    jnewbery commented at 6:59 pm on January 9, 2019:
    is this used?
  21. in src/qt/walletcontroller.h:51 in 5e4cb35d16 outdated
    45+    void currentWalletChanged(WalletModel* wallet_model);
    46+
    47+    void coinsSent(WalletModel* wallet_model, SendCoinsRecipient recipient, QByteArray transaction);
    48+
    49+private:
    50+    interfaces::Node& m_node;
    


    jnewbery commented at 7:20 pm on January 9, 2019:
    do m_node, m_platform_style, m_options_model and m_handler_load_wallet need to be member variables?

    promag commented at 11:03 am on January 12, 2019:
    Yes, to create WalletModel instances. And m_handler_load_wallet is needed to keep the signal/slot connection.
  22. jnewbery commented at 7:20 pm on January 9, 2019: member

    Looks good. A few comments and questions inline.

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

  23. DrahtBot added the label Needs rebase on Jan 9, 2019
  24. promag force-pushed on Jan 12, 2019
  25. DrahtBot removed the label Needs rebase on Jan 12, 2019
  26. promag force-pushed on Jan 12, 2019
  27. promag commented at 11:02 am on January 12, 2019: member
    Rebased with #15149 to avoid conflicts.
  28. promag force-pushed on Jan 12, 2019
  29. promag force-pushed on Jan 12, 2019
  30. promag force-pushed on Jan 14, 2019
  31. promag force-pushed on Jan 14, 2019
  32. promag force-pushed on Jan 14, 2019
  33. DrahtBot added the label Needs rebase on Jan 14, 2019
  34. in src/qt/walletcontroller.cpp:42 in 89fa546e82 outdated
    37+        wallet_models.push_back(it.second);
    38+    }
    39+    return wallet_models;
    40+}
    41+
    42+std::vector<std::string> WalletController::getWalletsAvailableToLoad() const
    


    jnewbery commented at 5:30 pm on January 14, 2019:
    Is this unused?

    promag commented at 5:40 pm on January 14, 2019:
    Used in #15153, I can move there if you prefer?

    jnewbery commented at 5:56 pm on January 14, 2019:
    I’d recommend moving it there. I think it’s best not to have unused code in PRs.
  35. jnewbery commented at 5:30 pm on January 14, 2019: member

    Lightly tested ACK 89fa546e8211aa47c96e20ba2a80507acd125539.

    One question inline.

  36. promag force-pushed on Jan 14, 2019
  37. promag commented at 10:27 pm on January 14, 2019: member
    @jnewbery done.
  38. DrahtBot removed the label Needs rebase on Jan 14, 2019
  39. promag force-pushed on Jan 14, 2019
  40. DrahtBot added the label Needs rebase on Jan 15, 2019
  41. promag force-pushed on Jan 15, 2019
  42. DrahtBot removed the label Needs rebase on Jan 15, 2019
  43. promag force-pushed on Jan 15, 2019
  44. Sjors commented at 7:08 pm on January 15, 2019: member
    Will re-test after #15149 rebase, but looking good.
  45. promag force-pushed on Jan 16, 2019
  46. promag commented at 0:58 am on January 16, 2019: member
    Rebased.
  47. in src/qt/bitcoingui.cpp:618 in 1316f57068 outdated
    614@@ -599,13 +615,19 @@ void BitcoinGUI::setCurrentWallet(WalletModel* wallet_model)
    615 {
    616     if (!walletFrame) return;
    617     walletFrame->setCurrentWallet(wallet_model);
    618+    for (int index = 0; index < m_wallet_selector->count(); ++index) {
    


    Sjors commented at 3:55 pm on January 16, 2019:

    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.

  48. in src/qt/walletcontroller.h:26 in c0fae8e311 outdated
    21+class Handler;
    22+class Node;
    23+} // namespace interfaces
    24+
    25+/**
    26+ * WalletController
    


    Sjors commented at 4:00 pm on January 16, 2019:
    Explain in more detail (in a followup PR) what this controller is for.

    promag commented at 4:14 pm on January 16, 2019:
    Fair enough, I’ll bring more code here so I can also improve this.
  49. in src/qt/walletcontroller.h:28 in c0fae8e311 outdated
    23+} // namespace interfaces
    24+
    25+/**
    26+ * WalletController
    27+ */
    28+class WalletController : public QObject
    


    Sjors commented at 4:01 pm on January 16, 2019:
    Nit: WalletsController?

    promag commented at 4:14 pm on January 16, 2019:
    heh 😛avoid plural?

    Sjors commented at 5:26 pm on January 16, 2019:
    Plural makes it clear that this controls multiple wallets, rather than one controller per wallet.

    promag commented at 5:31 pm on January 16, 2019:
    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.

    jnewbery commented at 4:18 pm on January 17, 2019:
    I think either is fine.

    hebasto commented at 6:40 pm on January 18, 2019:
    Tech language prefers a singular form; e.g., “window manager”, “file manager” etc.
  50. Sjors approved
  51. Sjors commented at 4:09 pm on January 16, 2019: member

    tACK 1316f57

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

    0qt/rpcconsole.cpp:909:22: warning: unused variable 'wallet_model' [-Wunused-variable]
    1        WalletModel* wallet_model{nullptr};
    2                     ^
    
  52. promag commented at 4:16 pm on January 16, 2019: member
  53. jnewbery commented at 4:18 pm on January 17, 2019: member

    Tested ACK 1316f5706891bb94428078e874e761931ff0e087

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

    EDIT: pasted incorrect commit id. Now fixed

  54. in src/qt/walletcontroller.cpp:59 in 1316f57068 outdated
    54+
    55+    connect(wallet_model, &WalletModel::unload, [this, it, wallet_model] {
    56+        // Unregister wallet model and update current if necessary.
    57+        {
    58+            QMutexLocker locker(&m_mutex);
    59+            m_wallet_models.erase(it);
    


    jonasschnelli commented at 7:38 pm on January 17, 2019:
    Is it safe to transport the iterator from outside the lambda to this point? Assume m_wallet_models did had additions or deletions during time of iteration creation and inner-usage?

    promag commented at 8:09 pm on January 17, 2019:
    From https://stackoverflow.com/a/6442829 I think it is safe, map iterator aren’t invalidated.

    promag commented at 10:31 pm on January 17, 2019:
    I’m going to change this to simplify other PR (close wallet action) I’m about to submit.
  55. promag force-pushed on Jan 17, 2019
  56. gui: Use AutoConnection for WalletModel::unload signal cefb399e21
  57. gui: Add WalletController 8fa271f089
  58. gui: Refactor to use WalletController 0dd9bdefa1
  59. promag force-pushed on Jan 18, 2019
  60. promag commented at 0:51 am on January 18, 2019: member
    Refactored a bit to simplify follow ups.
  61. in src/qt/walletmodel.cpp:379 in cefb399e21 outdated
    375@@ -376,7 +376,7 @@ bool WalletModel::changePassphrase(const SecureString &oldPass, const SecureStri
    376 static void NotifyUnload(WalletModel* walletModel)
    377 {
    378     qDebug() << "NotifyUnload";
    379-    QMetaObject::invokeMethod(walletModel, "unload", Qt::QueuedConnection);
    380+    QMetaObject::invokeMethod(walletModel, "unload");
    


    Sjors commented at 10:14 am on January 18, 2019:

    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?


    promag commented at 10:46 am on January 18, 2019:

    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.

  62. Sjors approved
  63. Sjors commented at 10:27 am on January 18, 2019: member
    re-tACK 0dd9bde
  64. jnewbery commented at 6:18 pm on January 18, 2019: member
    utACK 0dd9bdefa1427746ae94b4dd3da1a5257c1ec68e
  65. jonasschnelli commented at 8:20 pm on January 18, 2019: contributor
    Tested ACK 0dd9bdefa1427746ae94b4dd3da1a5257c1ec68e
  66. jonasschnelli merged this on Jan 18, 2019
  67. jonasschnelli closed this on Jan 18, 2019

  68. jonasschnelli referenced this in commit 63144335be on Jan 18, 2019
  69. promag deleted the branch on Jan 18, 2019
  70. PastaPastaPasta referenced this in commit bc3d461c44 on Sep 8, 2021
  71. PastaPastaPasta referenced this in commit 85503c821b on Sep 10, 2021
  72. PastaPastaPasta referenced this in commit 90e8487af9 on Sep 10, 2021
  73. PastaPastaPasta referenced this in commit 43744dc130 on Sep 18, 2021
  74. PastaPastaPasta referenced this in commit 68ad472996 on Sep 18, 2021
  75. PastaPastaPasta referenced this in commit 4197db6a7e on Sep 18, 2021
  76. UdjinM6 referenced this in commit 67514120a1 on Sep 18, 2021
  77. thelazier referenced this in commit 76c77bc265 on Sep 25, 2021
  78. MarcoFalke locked this on Dec 16, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-07-01 10:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me