Skip to content

Conversation

ryanofsky
Copy link
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.

ryanofsky and others added 3 commits March 3, 2021 09:19
Make sure wallet receive requests are saved and deleted correctly by GUI
code

Co-authored-by: Jarol Rodriguez <jarolrod@tutanota.com>
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.
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, bitcoin#18608 could be considered as a followup.
Copy link
Member

@jarolrod jarolrod left a comment

Choose a reason for hiding this comment

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

ACK 53291c7, 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!

Copy link
Contributor Author

@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.

Updated 53291c7 -> 758cbfa (pr/nodestg.2 -> pr/nodestg.3, compare) with review suggestions

@@ -225,6 +225,7 @@ void TestGUI(interfaces::Node& node)
int initialRowCount = requestTableModel->rowCount({});
QPushButton* requestPaymentButton = receiveCoinsDialog.findChild<QPushButton*>("receiveButton");
requestPaymentButton->click();
std::string address;
Copy link
Member

Choose a reason for hiding this comment

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

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

diff --git a/src/qt/test/wallettests.cpp b/src/qt/test/wallettests.cpp
index 3acf9d6b2..708c3cc92 100644
--- a/src/qt/test/wallettests.cpp
+++ b/src/qt/test/wallettests.cpp
@@ -225,7 +225,7 @@ void TestGUI(interfaces::Node& node)
     int initialRowCount = requestTableModel->rowCount({});
     QPushButton* requestPaymentButton = receiveCoinsDialog.findChild<QPushButton*>("receiveButton");
     requestPaymentButton->click();
-    std::string address;
+    QString address;
     for (QWidget* widget : QApplication::topLevelWidgets()) {
         if (widget->inherits("ReceiveRequestDialog")) {
             ReceiveRequestDialog* receiveRequestDialog = qobject_cast<ReceiveRequestDialog*>(widget);
@@ -234,9 +234,9 @@ void TestGUI(interfaces::Node& node)
             QString uri = receiveRequestDialog->QObject::findChild<QLabel*>("uri_content")->text();
             QCOMPARE(uri.count("bitcoin:"), 2);
             QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("address_tag")->text(), QString("Address:"));
-            QVERIFY(address.empty());
-            address = receiveRequestDialog->QObject::findChild<QLabel*>("address_content")->text().toStdString();
-            QVERIFY(!address.empty());
+            QVERIFY(address.isEmpty());
+            address = receiveRequestDialog->QObject::findChild<QLabel*>("address_content")->text();
+            QVERIFY(!address.isEmpty());
 
             QCOMPARE(uri.count("amount=0.00000001"), 2);
             QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("amount_tag")->text(), QString("Amount:"));
@@ -271,7 +271,7 @@ void TestGUI(interfaces::Node& node)
     QCOMPARE(entry.nVersion, int{1});
     QCOMPARE(entry.id, int64_t{1});
     QVERIFY(entry.date.isValid());
-    QCOMPARE(entry.recipient.address, QString::fromStdString(address));
+    QCOMPARE(entry.recipient.address, address);
     QCOMPARE(entry.recipient.label, QString{"TEST_LABEL_1"});
     QCOMPARE(entry.recipient.amount, CAmount{1});
     QCOMPARE(entry.recipient.message, QString{"TEST_MESSAGE_1"});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Applied simplification

Copy link
Contributor Author

@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.

Updated 758cbfa -> f5ba424 (pr/nodestg.3 -> pr/nodestg.4, compare) with suggestion

@@ -225,6 +225,7 @@ void TestGUI(interfaces::Node& node)
int initialRowCount = requestTableModel->rowCount({});
QPushButton* requestPaymentButton = receiveCoinsDialog.findChild<QPushButton*>("receiveButton");
requestPaymentButton->click();
std::string address;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Applied simplification

@jarolrod
Copy link
Member

tACK f5ba424

@laanwj
Copy link
Member

laanwj commented Jun 3, 2021

Code review ACK f5ba424

@laanwj laanwj merged commit 907d636 into bitcoin:master Jun 3, 2021
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jun 3, 2021
f5ba424 wallet: Add IsAddressUsed / SetAddressUsed methods (Russell Yanofsky)
62252c9 interfaces: Stop exposing wallet destdata to gui (Russell Yanofsky)
985430d test: Add gui test for wallet receive requests (Russell Yanofsky)

Pull request description:

  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.

ACKs for top commit:
  jarolrod:
    tACK f5ba424
  laanwj:
    Code review ACK f5ba424

Tree-SHA512: 5423df4786e537a59013cb5bfb9e1bc29a7ca4b8835360c00cc2165a59f925fdc355907a4ceb8bca0285bb4946ba235bffa7645537a951ad03fd3b4cee17b6b0
gwillen pushed a commit to ElementsProject/elements that referenced this pull request Jun 1, 2022
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
@bitcoin bitcoin unlocked this conversation Apr 7, 2023
return batch.EraseDestData(EncodeDestination(dest), key);
}

const std::string value{"1"};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In commit "wallet: Add IsAddressUsed / SetAddressUsed methods" (f5ba424)

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

@bitcoin bitcoin locked and limited conversation to collaborators Apr 6, 2024
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