aboutsummaryrefslogtreecommitdiff
path: root/src/qt
diff options
context:
space:
mode:
authorRussell Yanofsky <russ@yanofsky.org>2020-04-12 13:40:43 -0400
committerRussell Yanofsky <russ@yanofsky.org>2021-03-03 10:19:35 -0400
commit62252c95e5aa55f33a5ef22292d5d8161fcb892a (patch)
treef234ce0a5a2d8bdeb32cd2a57188f34c4bf9fc50 /src/qt
parent985430d9b2e183c1f59a34472e413a8d00a7e6da (diff)
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.
Diffstat (limited to 'src/qt')
-rw-r--r--src/qt/recentrequeststablemodel.cpp12
-rw-r--r--src/qt/test/wallettests.cpp4
-rw-r--r--src/qt/walletmodel.cpp19
-rw-r--r--src/qt/walletmodel.h3
4 files changed, 9 insertions, 29 deletions
diff --git a/src/qt/recentrequeststablemodel.cpp b/src/qt/recentrequeststablemodel.cpp
index 03531a1381..c47b34a2b0 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>
@@ -18,10 +21,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();
@@ -143,7 +145,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;
}
@@ -172,7 +174,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 0ef1fb318a..708c3cc92b 100644
--- a/src/qt/test/wallettests.cpp
+++ b/src/qt/test/wallettests.cpp
@@ -264,7 +264,7 @@ void TestGUI(interfaces::Node& node)
QCOMPARE(currentRowCount, initialRowCount+1);
// Check addition to wallet
- std::vector<std::string> requests = walletModel.wallet().getDestValues("rr");
+ 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;
@@ -286,7 +286,7 @@ void TestGUI(interfaces::Node& node)
QCOMPARE(requestTableModel->rowCount({}), currentRowCount-1);
// Check removal from wallet
- QCOMPARE(walletModel.wallet().getDestValues("rr").size(), size_t{0});
+ QCOMPARE(walletModel.wallet().getAddressReceiveRequests().size(), size_t{0});
}
} // namespace
diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp
index 02254da3ce..381d1ce654 100644
--- a/src/qt/walletmodel.cpp
+++ b/src/qt/walletmodel.cpp
@@ -463,25 +463,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 9a3c3f2f66..72a1671146 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();