interfaces: Stop exposing wallet destdata to gui #21353

pull ryanofsky wants to merge 3 commits into bitcoin:master from ryanofsky:pr/nodestg changing 9 files +80 −81
  1. ryanofsky commented at 8:04 pm on March 3, 2021: contributor

    Stop giving GUI access to destdata rows in database. Replace with narrow API just for saving and reading receive request information.

    This simplifies code and should prevent the GUI from interfering with other destdata like address-used status. It also adds some more GUI test coverage.

    There are no changes in behavior.

  2. test: Add gui test for wallet receive requests
    Make sure wallet receive requests are saved and deleted correctly by GUI
    code
    
    Co-authored-by: Jarol Rodriguez <jarolrod@tutanota.com>
    985430d9b2
  3. interfaces: Stop exposing wallet destdata to gui
    Stop giving GUI access to destdata rows in database. Replace with narrow
    API just for saving and reading receive request information.
    
    This simplifies code and should prevent the GUI from interfering with
    other destdata like address-used status.
    
    Note: No user-visible behavior is changing in this commit. New
    CWallet::SetAddressReceiveRequest() implementation avoids a bug in
    CWallet::AddDestData() where a modification would leave the previous
    value in memory while writing the new value to disk. But it doesn't
    matter because the GUI doesn't currently expose the ability to modify
    receive requests, only to add and erase them.
    62252c95e5
  4. wallet: Add IsAddressUsed / SetAddressUsed methods
    This simplifies code and adds a less cumbersome interface for accessing
    address used information than CWallet AddDestData / EraseDestData /
    GetDestData methods.
    
    There is no change in behavior. Lower-level walletdb DestData methods
    are also still available and not affected by this change. If there is
    interest in consolidating destdata logic more and making it internal to
    walletdb, #18608 could be considered as a followup.
    f5ba424cd4
  5. DrahtBot added the label GUI on Mar 3, 2021
  6. DrahtBot added the label interfaces on Mar 3, 2021
  7. DrahtBot added the label Wallet on Mar 3, 2021
  8. maflcko added the label Refactoring on Mar 3, 2021
  9. jarolrod commented at 6:03 pm on March 4, 2021: member

    ACK 53291c71256d7d15347d2ea46c3cd2692b6ef138, tested on macOS 11.2 Qt 5.15.2

    Tested that the functionality remained the same between master and this PR. Specifically with populating the recentrequeststablemodel and actions like creating and removing a request.

    This is a nice refactor and yay, more GUI test coverage!

  10. in src/wallet/wallet.cpp:3820 in dd8a9d019a outdated
    3811@@ -3811,6 +3812,18 @@ std::vector<std::string> CWallet::GetDestValues(const std::string& prefix) const
    3812     return values;
    3813 }
    3814 
    3815+bool CWallet::SetAddressReceiveRequest(WalletBatch& batch, const CTxDestination& dest, const std::string& id, const std::string& value)
    3816+{
    3817+    const std::string key{"rr" + id}; // "rr" prefix = "receive request" in destdata
    3818+    CAddressBookData& data = m_address_book.at(dest);
    3819+    if (value.empty()) {
    3820+        return data.destdata.erase(key) && batch.EraseDestData(EncodeDestination(dest), key);
    


    promag commented at 2:48 pm on March 6, 2021:

    dd8a9d019aa449f3a6c5ad989cb6bdd9f03d1306

    Should erase from destdata iif EraseDestData succeeds?


    ryanofsky commented at 0:08 am on March 9, 2021:

    re: #21353 (review)

    dd8a9d0

    Should erase from destdata iif EraseDestData succeeds?

    Good suggestion! No need to keep previous behavior that makes a missing key look like a failed write.

  11. in src/wallet/wallet.cpp:3822 in dd8a9d019a outdated
    3817+    const std::string key{"rr" + id}; // "rr" prefix = "receive request" in destdata
    3818+    CAddressBookData& data = m_address_book.at(dest);
    3819+    if (value.empty()) {
    3820+        return data.destdata.erase(key) && batch.EraseDestData(EncodeDestination(dest), key);
    3821+    } else {
    3822+        data.destdata[key] = value;
    


    promag commented at 2:49 pm on March 6, 2021:

    dd8a9d019aa449f3a6c5ad989cb6bdd9f03d1306

    Should update destdata iff WriteDestData succeeds?


    ryanofsky commented at 0:08 am on March 9, 2021:

    re: #21353 (review)

    dd8a9d0

    Should update destdata iff WriteDestData succeeds?

    Thanks! Implemented

  12. ryanofsky force-pushed on Mar 9, 2021
  13. ryanofsky commented at 0:53 am on March 9, 2021: contributor
    Updated 53291c71256d7d15347d2ea46c3cd2692b6ef138 -> 758cbfa37e8e1805d7d53ef203d91db3733248e9 (pr/nodestg.2 -> pr/nodestg.3, compare) with review suggestions
  14. in src/qt/test/wallettests.cpp:228 in 758cbfa37e outdated
    224@@ -225,6 +225,7 @@ void TestGUI(interfaces::Node& node)
    225     int initialRowCount = requestTableModel->rowCount({});
    226     QPushButton* requestPaymentButton = receiveCoinsDialog.findChild<QPushButton*>("receiveButton");
    227     requestPaymentButton->click();
    228+    std::string address;
    


    jarolrod commented at 1:55 pm on May 18, 2021:

    Any reason to use std::string here? If we just use QString we could avoid conversions on lines 238 and 274

     0
     1diff --git a/src/qt/test/wallettests.cpp b/src/qt/test/wallettests.cpp
     2index 3acf9d6b2..708c3cc92 100644
     3--- a/src/qt/test/wallettests.cpp
     4+++ b/src/qt/test/wallettests.cpp
     5@@ -225,7 +225,7 @@ void TestGUI(interfaces::Node& node)
     6     int initialRowCount = requestTableModel->rowCount({});
     7     QPushButton* requestPaymentButton = receiveCoinsDialog.findChild<QPushButton*>("receiveButton");
     8     requestPaymentButton->click();
     9-    std::string address;
    10+    QString address;
    11     for (QWidget* widget : QApplication::topLevelWidgets()) {
    12         if (widget->inherits("ReceiveRequestDialog")) {
    13             ReceiveRequestDialog* receiveRequestDialog = qobject_cast<ReceiveRequestDialog*>(widget);
    14@@ -234,9 +234,9 @@ void TestGUI(interfaces::Node& node)
    15             QString uri = receiveRequestDialog->QObject::findChild<QLabel*>("uri_content")->text();
    16             QCOMPARE(uri.count("bitcoin:"), 2);
    17             QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("address_tag")->text(), QString("Address:"));
    18-            QVERIFY(address.empty());
    19-            address = receiveRequestDialog->QObject::findChild<QLabel*>("address_content")->text().toStdString();
    20-            QVERIFY(!address.empty());
    21+            QVERIFY(address.isEmpty());
    22+            address = receiveRequestDialog->QObject::findChild<QLabel*>("address_content")->text();
    23+            QVERIFY(!address.isEmpty());
    24 
    25             QCOMPARE(uri.count("amount=0.00000001"), 2);
    26             QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("amount_tag")->text(), QString("Amount:"));
    27@@ -271,7 +271,7 @@ void TestGUI(interfaces::Node& node)
    28     QCOMPARE(entry.nVersion, int{1});
    29     QCOMPARE(entry.id, int64_t{1});
    30     QVERIFY(entry.date.isValid());
    31-    QCOMPARE(entry.recipient.address, QString::fromStdString(address));
    32+    QCOMPARE(entry.recipient.address, address);
    33     QCOMPARE(entry.recipient.label, QString{"TEST_LABEL_1"});
    34     QCOMPARE(entry.recipient.amount, CAmount{1});
    35     QCOMPARE(entry.recipient.message, QString{"TEST_MESSAGE_1"});
    

    ryanofsky commented at 6:28 pm on May 19, 2021:
    Thanks! Applied simplification
  15. ryanofsky force-pushed on May 19, 2021
  16. ryanofsky commented at 7:46 pm on May 19, 2021: contributor
    Updated 758cbfa37e8e1805d7d53ef203d91db3733248e9 -> f5ba424cd44619d9b9be88b8593d69a7ba96db26 (pr/nodestg.3 -> pr/nodestg.4, compare) with suggestion
  17. jarolrod commented at 11:09 pm on May 19, 2021: member
    tACK f5ba424cd44619d9b9be88b8593d69a7ba96db26
  18. maflcko removed the label GUI on May 20, 2021
  19. maflcko removed the label Wallet on May 20, 2021
  20. maflcko added the label Wallet on May 20, 2021
  21. laanwj commented at 1:52 pm on June 3, 2021: member
    Code review ACK f5ba424cd44619d9b9be88b8593d69a7ba96db26
  22. laanwj merged this on Jun 3, 2021
  23. laanwj closed this on Jun 3, 2021

  24. sidhujag referenced this in commit 9f67513e92 on Jun 3, 2021
  25. gwillen referenced this in commit 18986689be on Jun 1, 2022
  26. bitcoin locked this on Aug 16, 2022
  27. bitcoin unlocked this on Apr 7, 2023
  28. in src/wallet/wallet.cpp:3774 in f5ba424cd4
    3770+    if (!used) {
    3771+        if (auto* data = util::FindKey(m_address_book, dest)) data->destdata.erase(key);
    3772+        return batch.EraseDestData(EncodeDestination(dest), key);
    3773+    }
    3774+
    3775+    const std::string value{"1"};
    


    ryanofsky commented at 3:08 pm on April 7, 2023:

    In commit “wallet: Add IsAddressUsed / SetAddressUsed methods” (f5ba424cd44619d9b9be88b8593d69a7ba96db26)

    Note: behavior accidentally changed here. Used addresses previously were written with “p” values, now they are written with “1” values. The change should not be significant because the values are currently ignored, but future code should continue to treat “1” and “p” the same

  29. bitcoin locked this on Apr 6, 2024

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-06 04:12 UTC

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