aboutsummaryrefslogtreecommitdiff
path: root/src/qt
diff options
context:
space:
mode:
authorW. J. van der Laan <laanwj@protonmail.com>2021-06-03 15:56:43 +0200
committerW. J. van der Laan <laanwj@protonmail.com>2021-06-03 15:57:30 +0200
commit907d636e5e76bd884a4ca1a1ebd8db68a3e64705 (patch)
tree54d1f17db002b4f480853ef456bdfa93d5248943 /src/qt
parent8837f1ebde0537b0fdfa1353d06ae8e61a259982 (diff)
parentf5ba424cd44619d9b9be88b8593d69a7ba96db26 (diff)
downloadbitcoin-907d636e5e76bd884a4ca1a1ebd8db68a3e64705.tar.xz
Merge bitcoin/bitcoin#21353: interfaces: Stop exposing wallet destdata to gui
f5ba424cd44619d9b9be88b8593d69a7ba96db26 wallet: Add IsAddressUsed / SetAddressUsed methods (Russell Yanofsky) 62252c95e5aa55f33a5ef22292d5d8161fcb892a interfaces: Stop exposing wallet destdata to gui (Russell Yanofsky) 985430d9b2e183c1f59a34472e413a8d00a7e6da 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 f5ba424cd44619d9b9be88b8593d69a7ba96db26 laanwj: Code review ACK f5ba424cd44619d9b9be88b8593d69a7ba96db26 Tree-SHA512: 5423df4786e537a59013cb5bfb9e1bc29a7ca4b8835360c00cc2165a59f925fdc355907a4ceb8bca0285bb4946ba235bffa7645537a951ad03fd3b4cee17b6b0
Diffstat (limited to 'src/qt')
-rw-r--r--src/qt/recentrequeststablemodel.cpp12
-rw-r--r--src/qt/test/wallettests.cpp22
-rw-r--r--src/qt/walletmodel.cpp19
-rw-r--r--src/qt/walletmodel.h3
4 files changed, 29 insertions, 27 deletions
diff --git a/src/qt/recentrequeststablemodel.cpp b/src/qt/recentrequeststablemodel.cpp
index 1ecc2f67ef..ec3d970a7f 100644
--- a/src/qt/recentrequeststablemodel.cpp
+++ b/src/qt/recentrequeststablemodel.cpp
@@ -10,7 +10,10 @@
#include <qt/walletmodel.h>
#include <clientversion.h>
+#include <interfaces/wallet.h>
+#include <key_io.h>
#include <streams.h>
+#include <util/string.h>
#include <utility>
@@ -21,10 +24,9 @@ RecentRequestsTableModel::RecentRequestsTableModel(WalletModel *parent) :
QAbstractTableModel(parent), walletModel(parent)
{
// Load entries from wallet
- std::vector<std::string> vReceiveRequests;
- parent->loadReceiveRequests(vReceiveRequests);
- for (const std::string& request : vReceiveRequests)
+ for (const std::string& request : parent->wallet().getAddressReceiveRequests()) {
addNewRequest(request);
+ }
/* These columns must match the indices in the ColumnIndex enumeration */
columns << tr("Date") << tr("Label") << tr("Message") << getAmountTitle();
@@ -150,7 +152,7 @@ bool RecentRequestsTableModel::removeRows(int row, int count, const QModelIndex
for (int i = 0; i < count; ++i)
{
const RecentRequestEntry* rec = &list[row+i];
- if (!walletModel->saveReceiveRequest(rec->recipient.address.toStdString(), rec->id, ""))
+ if (!walletModel->wallet().setAddressReceiveRequest(DecodeDestination(rec->recipient.address.toStdString()), ToString(rec->id), ""))
return false;
}
@@ -179,7 +181,7 @@ void RecentRequestsTableModel::addNewRequest(const SendCoinsRecipient &recipient
CDataStream ss(SER_DISK, CLIENT_VERSION);
ss << newEntry;
- if (!walletModel->saveReceiveRequest(recipient.address.toStdString(), newEntry.id, ss.str()))
+ if (!walletModel->wallet().setAddressReceiveRequest(DecodeDestination(recipient.address.toStdString()), ToString(newEntry.id), ss.str()))
return;
addNewRequest(newEntry);
diff --git a/src/qt/test/wallettests.cpp b/src/qt/test/wallettests.cpp
index 26f568b16a..ea35f80cf5 100644
--- a/src/qt/test/wallettests.cpp
+++ b/src/qt/test/wallettests.cpp
@@ -224,6 +224,7 @@ void TestGUI(interfaces::Node& node)
int initialRowCount = requestTableModel->rowCount({});
QPushButton* requestPaymentButton = receiveCoinsDialog.findChild<QPushButton*>("receiveButton");
requestPaymentButton->click();
+ QString address;
for (QWidget* widget : QApplication::topLevelWidgets()) {
if (widget->inherits("ReceiveRequestDialog")) {
ReceiveRequestDialog* receiveRequestDialog = qobject_cast<ReceiveRequestDialog*>(widget);
@@ -232,6 +233,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.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:"));
@@ -258,12 +262,30 @@ void TestGUI(interfaces::Node& node)
int currentRowCount = requestTableModel->rowCount({});
QCOMPARE(currentRowCount, initialRowCount+1);
+ // Check addition to wallet
+ std::vector<std::string> requests = walletModel.wallet().getAddressReceiveRequests();
+ QCOMPARE(requests.size(), size_t{1});
+ RecentRequestEntry entry;
+ CDataStream{MakeUCharSpan(requests[0]), SER_DISK, CLIENT_VERSION} >> entry;
+ QCOMPARE(entry.nVersion, int{1});
+ QCOMPARE(entry.id, int64_t{1});
+ QVERIFY(entry.date.isValid());
+ 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"});
+ QCOMPARE(entry.recipient.sPaymentRequest, std::string{});
+ QCOMPARE(entry.recipient.authenticatedMerchant, QString{});
+
// Check Remove button
QTableView* table = receiveCoinsDialog.findChild<QTableView*>("recentRequestsView");
table->selectRow(currentRowCount-1);
QPushButton* removeRequestButton = receiveCoinsDialog.findChild<QPushButton*>("removeRequestButton");
removeRequestButton->click();
QCOMPARE(requestTableModel->rowCount({}), currentRowCount-1);
+
+ // Check removal from wallet
+ QCOMPARE(walletModel.wallet().getAddressReceiveRequests().size(), size_t{0});
}
} // namespace
diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp
index cc6db8d33e..7c58b8afd2 100644
--- a/src/qt/walletmodel.cpp
+++ b/src/qt/walletmodel.cpp
@@ -466,25 +466,6 @@ void WalletModel::UnlockContext::CopyFrom(UnlockContext&& rhs)
rhs.relock = false;
}
-void WalletModel::loadReceiveRequests(std::vector<std::string>& vReceiveRequests)
-{
- vReceiveRequests = m_wallet->getDestValues("rr"); // receive request
-}
-
-bool WalletModel::saveReceiveRequest(const std::string &sAddress, const int64_t nId, const std::string &sRequest)
-{
- CTxDestination dest = DecodeDestination(sAddress);
-
- std::stringstream ss;
- ss << nId;
- std::string key = "rr" + ss.str(); // "rr" prefix = "receive request" in destdata
-
- if (sRequest.empty())
- return m_wallet->eraseDestData(dest, key);
- else
- return m_wallet->addDestData(dest, key, sRequest);
-}
-
bool WalletModel::bumpFee(uint256 hash, uint256& new_hash)
{
CCoinControl coin_control;
diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h
index 4ca8643444..b2ce5d69fb 100644
--- a/src/qt/walletmodel.h
+++ b/src/qt/walletmodel.h
@@ -135,9 +135,6 @@ public:
UnlockContext requestUnlock();
- void loadReceiveRequests(std::vector<std::string>& vReceiveRequests);
- bool saveReceiveRequest(const std::string &sAddress, const int64_t nId, const std::string &sRequest);
-
bool bumpFee(uint256 hash, uint256& new_hash);
static bool isWalletEnabled();