Skip to content

Commit 45bdfa5

Browse files
Merge dashpay#5979: backport: Merge bitcoin#21902, 22187, 21795, 22902,(followup) 19940, 22121, 21353, 21936
6c242da Merge bitcoin#21936: fuzz: Terminate immediately if a fuzzing harness tries to create a TCP socket (belt and suspenders) (MarcoFalke) 26ff28a Merge bitcoin#21353: interfaces: Stop exposing wallet destdata to gui (W. J. van der Laan) 348f4a8 Merge bitcoin#22121: doc: Various validation doc fixups (fanquake) 2996daa (followup) bitcoin#19940 (Vijay) b6dbd8b Merge bitcoin#22092: test: convert documentation into type annotations (fanquake) cc70886 Merge bitcoin#21795: fuzz: Terminate immediately if a fuzzing harness tries to perform a DNS lookup (belt and suspenders) (MarcoFalke) f3bc953 Merge bitcoin#22187: test: Add sync_blocks in wallet_orphanedreward.py (MarcoFalke) 16ccb90 Merge bitcoin#21902: refactor: Remove useless extern keyword (fanquake) Pull request description: backport: Merge bitcoin#21902, 22187, 21795, 22902,(followup) 19940, 22121, 21353, 21936 Top commit has no ACKs. Tree-SHA512: 26de87da5d18fd36a38253a077131b36a278bc681bb47a9b893b6caad8520fc535b1675c3d79d312d455d710dd6ae7235d6cef1fb031a76e0559a200c2fc9b04
2 parents eb7d244 + 6c242da commit 45bdfa5

23 files changed

+140
-129
lines changed

src/chain.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class CBlockIndex
179179
//!
180180
//! Note: this value is modified to show BLOCK_OPT_WITNESS during UTXO snapshot
181181
//! load to avoid the block index being spuriously rewound.
182-
//! @sa RewindBlockIndex
182+
//! @sa NeedsRedownload
183183
//! @sa ActivateSnapshot
184184
uint32_t nStatus{0};
185185

src/interfaces/wallet.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,11 @@ class Wallet
128128
//! Get wallet address list.
129129
virtual std::vector<WalletAddress> getAddresses() = 0;
130130

131-
//! Add dest data.
132-
virtual bool addDestData(const CTxDestination& dest, const std::string& key, const std::string& value) = 0;
131+
//! Get receive requests.
132+
virtual std::vector<std::string> getAddressReceiveRequests() = 0;
133133

134-
//! Erase dest data.
135-
virtual bool eraseDestData(const CTxDestination& dest, const std::string& key) = 0;
136-
137-
//! Get dest values with prefix.
138-
virtual std::vector<std::string> getDestValues(const std::string& prefix) = 0;
134+
//! Save or remove receive request.
135+
virtual bool setAddressReceiveRequest(const CTxDestination& dest, const std::string& id, const std::string& value) = 0;
139136

140137
//! Lock coin.
141138
virtual void lockCoin(const COutPoint& output) = 0;

src/qt/recentrequeststablemodel.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,20 @@
1010
#include <qt/walletmodel.h>
1111

1212
#include <clientversion.h>
13+
#include <interfaces/wallet.h>
14+
#include <key_io.h>
1315
#include <streams.h>
16+
#include <util/string.h>
1417

1518
#include <utility>
1619

1720
RecentRequestsTableModel::RecentRequestsTableModel(WalletModel *parent) :
1821
QAbstractTableModel(parent), walletModel(parent)
1922
{
2023
// Load entries from wallet
21-
std::vector<std::string> vReceiveRequests;
22-
parent->loadReceiveRequests(vReceiveRequests);
23-
for (const std::string& request : vReceiveRequests)
24+
for (const std::string& request : parent->wallet().getAddressReceiveRequests()) {
2425
addNewRequest(request);
26+
}
2527

2628
/* These columns must match the indices in the ColumnIndex enumeration */
2729
columns << tr("Date") << tr("Label") << tr("Message") << getAmountTitle();
@@ -143,7 +145,7 @@ bool RecentRequestsTableModel::removeRows(int row, int count, const QModelIndex
143145
for (int i = 0; i < count; ++i)
144146
{
145147
const RecentRequestEntry* rec = &list[row+i];
146-
if (!walletModel->saveReceiveRequest(rec->recipient.address.toStdString(), rec->id, ""))
148+
if (!walletModel->wallet().setAddressReceiveRequest(DecodeDestination(rec->recipient.address.toStdString()), ToString(rec->id), ""))
147149
return false;
148150
}
149151

@@ -172,7 +174,7 @@ void RecentRequestsTableModel::addNewRequest(const SendCoinsRecipient &recipient
172174
CDataStream ss(SER_DISK, CLIENT_VERSION);
173175
ss << newEntry;
174176

175-
if (!walletModel->saveReceiveRequest(recipient.address.toStdString(), newEntry.id, ss.str()))
177+
if (!walletModel->wallet().setAddressReceiveRequest(DecodeDestination(recipient.address.toStdString()), ToString(newEntry.id), ss.str()))
176178
return;
177179

178180
addNewRequest(newEntry);

src/qt/test/wallettests.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ void TestGUI(interfaces::Node& node)
187187
int initialRowCount = requestTableModel->rowCount({});
188188
QPushButton* requestPaymentButton = receiveCoinsDialog.findChild<QPushButton*>("receiveButton");
189189
requestPaymentButton->click();
190+
QString address;
190191
for (QWidget* widget : QApplication::topLevelWidgets()) {
191192
if (widget->inherits("ReceiveRequestDialog")) {
192193
ReceiveRequestDialog* receiveRequestDialog = qobject_cast<ReceiveRequestDialog*>(widget);
@@ -195,6 +196,9 @@ void TestGUI(interfaces::Node& node)
195196
QString uri = receiveRequestDialog->QObject::findChild<QLabel*>("uri_content")->text();
196197
QCOMPARE(uri.count("dash:"), 2);
197198
QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("address_tag")->text(), QString("Address:"));
199+
QVERIFY(address.isEmpty());
200+
address = receiveRequestDialog->QObject::findChild<QLabel*>("address_content")->text();
201+
QVERIFY(!address.isEmpty());
198202

199203
QCOMPARE(uri.count("amount=0.00000001"), 2);
200204
QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("amount_tag")->text(), QString("Amount:"));
@@ -221,13 +225,31 @@ void TestGUI(interfaces::Node& node)
221225
int currentRowCount = requestTableModel->rowCount({});
222226
QCOMPARE(currentRowCount, initialRowCount+1);
223227

228+
// Check addition to wallet
229+
std::vector<std::string> requests = walletModel.wallet().getAddressReceiveRequests();
230+
QCOMPARE(requests.size(), size_t{1});
231+
RecentRequestEntry entry;
232+
CDataStream{MakeUCharSpan(requests[0]), SER_DISK, CLIENT_VERSION} >> entry;
233+
QCOMPARE(entry.nVersion, int{1});
234+
QCOMPARE(entry.id, int64_t{1});
235+
QVERIFY(entry.date.isValid());
236+
QCOMPARE(entry.recipient.address, address);
237+
QCOMPARE(entry.recipient.label, QString{"TEST_LABEL_1"});
238+
QCOMPARE(entry.recipient.amount, CAmount{1});
239+
QCOMPARE(entry.recipient.message, QString{"TEST_MESSAGE_1"});
240+
QCOMPARE(entry.recipient.sPaymentRequest, std::string{});
241+
QCOMPARE(entry.recipient.authenticatedMerchant, QString{});
242+
224243
// Check Remove button
225244
QTableView* table = receiveCoinsDialog.findChild<QTableView*>("recentRequestsView");
226245
table->selectRow(currentRowCount-1);
227246
QPushButton* removeRequestButton = receiveCoinsDialog.findChild<QPushButton*>("removeRequestButton");
228247
removeRequestButton->click();
229248
QCOMPARE(requestTableModel->rowCount({}), currentRowCount-1);
230249
RemoveWallet(wallet, std::nullopt);
250+
251+
// Check removal from wallet
252+
QCOMPARE(walletModel.wallet().getAddressReceiveRequests().size(), size_t{0});
231253
}
232254

233255
} // namespace

src/qt/walletmodel.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -571,25 +571,6 @@ void WalletModel::UnlockContext::CopyFrom(UnlockContext&& rhs)
571571
rhs.was_mixing = false;
572572
}
573573

574-
void WalletModel::loadReceiveRequests(std::vector<std::string>& vReceiveRequests)
575-
{
576-
vReceiveRequests = m_wallet->getDestValues("rr"); // receive request
577-
}
578-
579-
bool WalletModel::saveReceiveRequest(const std::string &sAddress, const int64_t nId, const std::string &sRequest)
580-
{
581-
CTxDestination dest = DecodeDestination(sAddress);
582-
583-
std::stringstream ss;
584-
ss << nId;
585-
std::string key = "rr" + ss.str(); // "rr" prefix = "receive request" in destdata
586-
587-
if (sRequest.empty())
588-
return m_wallet->eraseDestData(dest, key);
589-
else
590-
return m_wallet->addDestData(dest, key, sRequest);
591-
}
592-
593574
bool WalletModel::isWalletEnabled()
594575
{
595576
return !gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET);

src/qt/walletmodel.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,6 @@ class WalletModel : public QObject
140140

141141
UnlockContext requestUnlock(bool fForMixingOnly=false);
142142

143-
void loadReceiveRequests(std::vector<std::string>& vReceiveRequests);
144-
bool saveReceiveRequest(const std::string &sAddress, const int64_t nId, const std::string &sRequest);
145-
146143
static bool isWalletEnabled();
147144

148145
int getNumISLocks() const;

src/rpc/util.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,23 @@ void RPCTypeCheckObj(const UniValue& o,
7474
* Utilities: convert hex-encoded Values
7575
* (throws error if not hex).
7676
*/
77-
extern uint256 ParseHashV(const UniValue& v, std::string strName);
78-
extern uint256 ParseHashO(const UniValue& o, std::string strKey);
79-
extern std::vector<unsigned char> ParseHexV(const UniValue& v, std::string strName);
80-
extern std::vector<unsigned char> ParseHexO(const UniValue& o, std::string strKey);
77+
uint256 ParseHashV(const UniValue& v, std::string strName);
78+
uint256 ParseHashO(const UniValue& o, std::string strKey);
79+
std::vector<unsigned char> ParseHexV(const UniValue& v, std::string strName);
80+
std::vector<unsigned char> ParseHexO(const UniValue& o, std::string strKey);
8181

82-
extern int32_t ParseInt32V(const UniValue& v, const std::string &strName);
83-
extern int64_t ParseInt64V(const UniValue& v, const std::string &strName);
84-
extern double ParseDoubleV(const UniValue& v, const std::string &strName);
85-
extern bool ParseBoolV(const UniValue& v, const std::string &strName);
82+
int32_t ParseInt32V(const UniValue& v, const std::string &strName);
83+
int64_t ParseInt64V(const UniValue& v, const std::string &strName);
84+
double ParseDoubleV(const UniValue& v, const std::string &strName);
85+
bool ParseBoolV(const UniValue& v, const std::string &strName);
8686

87-
extern CAmount AmountFromValue(const UniValue& value);
87+
CAmount AmountFromValue(const UniValue& value);
8888

8989
using RPCArgList = std::vector<std::pair<std::string, UniValue>>;
90-
extern std::string HelpExampleCli(const std::string& methodname, const std::string& args);
91-
extern std::string HelpExampleCliNamed(const std::string& methodname, const RPCArgList& args);
92-
extern std::string HelpExampleRpc(const std::string& methodname, const std::string& args);
93-
extern std::string HelpExampleRpcNamed(const std::string& methodname, const RPCArgList& args);
90+
std::string HelpExampleCli(const std::string& methodname, const std::string& args);
91+
std::string HelpExampleCliNamed(const std::string& methodname, const RPCArgList& args);
92+
std::string HelpExampleRpc(const std::string& methodname, const std::string& args);
93+
std::string HelpExampleRpcNamed(const std::string& methodname, const RPCArgList& args);
9494

9595
CPubKey HexToPubKey(const std::string& hex_in);
9696
CPubKey AddrToPubKey(const FillableSigningProvider& keystore, const std::string& addr_in);

src/test/base58_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
using namespace std::literals;
1818

19-
extern UniValue read_json(const std::string& jsondata);
19+
UniValue read_json(const std::string& jsondata);
2020

2121
BOOST_AUTO_TEST_SUITE(base58_tests)
2222

src/test/fuzz/fuzz.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@
44

55
#include <test/fuzz/fuzz.h>
66

7+
#include <netaddress.h>
8+
#include <netbase.h>
79
#include <test/util/setup_common.h>
810
#include <util/check.h>
11+
#include <util/sock.h>
912

1013
#include <cstdint>
14+
#include <string>
15+
#include <exception>
16+
#include <memory>
1117
#include <unistd.h>
1218
#include <vector>
1319

@@ -29,6 +35,17 @@ static TypeTestOneInput* g_test_one_input{nullptr};
2935

3036
void initialize()
3137
{
38+
// Terminate immediately if a fuzzing harness ever tries to create a TCP socket.
39+
CreateSock = [](const CService&) -> std::unique_ptr<Sock> { std::terminate(); };
40+
41+
// Terminate immediately if a fuzzing harness ever tries to perform a DNS lookup.
42+
g_dns_lookup = [](const std::string& name, bool allow_lookup) {
43+
if (allow_lookup) {
44+
std::terminate();
45+
}
46+
return WrappedGetAddrInfo(name, false);
47+
};
48+
3249
if (std::getenv("PRINT_ALL_FUZZ_TARGETS_AND_ABORT")) {
3350
for (const auto& t : FuzzTargets()) {
3451
if (std::get<2>(t.second)) continue;

src/test/key_io_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include <univalue.h>
1818

19-
extern UniValue read_json(const std::string& jsondata);
19+
UniValue read_json(const std::string& jsondata);
2020

2121
BOOST_FIXTURE_TEST_SUITE(key_io_tests, BasicTestingSetup)
2222

0 commit comments

Comments
 (0)