Bitcoin Core 31.99.0
P2P Digital Currency
wallettests.cpp
Go to the documentation of this file.
1// Copyright (c) 2015-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
6#include <qt/test/util.h>
7
9#include <interfaces/chain.h>
10#include <interfaces/node.h>
11#include <key_io.h>
13#include <qt/bitcoinunits.h>
14#include <qt/clientmodel.h>
15#include <qt/optionsmodel.h>
16#include <qt/overviewpage.h>
17#include <qt/platformstyle.h>
22#include <qt/sendcoinsdialog.h>
23#include <qt/sendcoinsentry.h>
25#include <qt/transactionview.h>
26#include <qt/walletmodel.h>
27#include <script/solver.h>
29#include <validation.h>
30#include <wallet/test/util.h>
31#include <wallet/wallet.h>
32
33#include <chrono>
34#include <memory>
35
36#include <QAbstractButton>
37#include <QAction>
38#include <QApplication>
39#include <QCheckBox>
40#include <QClipboard>
41#include <QObject>
42#include <QPushButton>
43#include <QTimer>
44#include <QVBoxLayout>
45#include <QTextEdit>
46#include <QListView>
47#include <QDialogButtonBox>
48
50using wallet::CWallet;
58
59namespace
60{
62void ConfirmSend(QString* text = nullptr, QMessageBox::StandardButton confirm_type = QMessageBox::Yes)
63{
64 QTimer::singleShot(0, [text, confirm_type]() {
65 for (QWidget* widget : QApplication::topLevelWidgets()) {
66 if (widget->inherits("SendConfirmationDialog")) {
67 SendConfirmationDialog* dialog = qobject_cast<SendConfirmationDialog*>(widget);
68 if (text) *text = dialog->text();
69 QAbstractButton* button = dialog->button(confirm_type);
70 button->setEnabled(true);
71 button->click();
72 }
73 }
74 });
75}
76
78Txid SendCoins(CWallet& wallet, SendCoinsDialog& sendCoinsDialog, const CTxDestination& address, CAmount amount,
79 QMessageBox::StandardButton confirm_type = QMessageBox::Yes)
80{
81 QVBoxLayout* entries = sendCoinsDialog.findChild<QVBoxLayout*>("entries");
82 SendCoinsEntry* entry = qobject_cast<SendCoinsEntry*>(entries->itemAt(0)->widget());
83 entry->findChild<QValidatedLineEdit*>("payTo")->setText(QString::fromStdString(EncodeDestination(address)));
84 entry->findChild<BitcoinAmountField*>("payAmount")->setValue(amount);
85 Txid txid;
86 btcsignals::scoped_connection c(wallet.NotifyTransactionChanged.connect([&txid](const Txid& hash, ChangeType status) {
87 if (status == CT_NEW) txid = hash;
88 }));
89 ConfirmSend(/*text=*/nullptr, confirm_type);
90 bool invoked = QMetaObject::invokeMethod(&sendCoinsDialog, "sendButtonClicked", Q_ARG(bool, false));
91 assert(invoked);
92 return txid;
93}
94
96QModelIndex FindTx(const QAbstractItemModel& model, const Txid& txid)
97{
98 QString hash = QString::fromStdString(txid.ToString());
99 int rows = model.rowCount({});
100 for (int row = 0; row < rows; ++row) {
101 QModelIndex index = model.index(row, 0, {});
102 if (model.data(index, TransactionTableModel::TxHashRole) == hash) {
103 return index;
104 }
105 }
106 return {};
107}
108
110void BumpFee(TransactionView& view, const Txid& txid, bool expectDisabled, std::string expectError, bool cancel)
111{
112 QTableView* table = view.findChild<QTableView*>("transactionView");
113 QModelIndex index = FindTx(*table->selectionModel()->model(), txid);
114 QVERIFY2(index.isValid(), "Could not find BumpFee txid");
115
116 // Select row in table, invoke context menu, and make sure bumpfee action is
117 // enabled or disabled as expected.
118 QAction* action = view.findChild<QAction*>("bumpFeeAction");
119 table->selectionModel()->select(index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
120 action->setEnabled(expectDisabled);
121 table->customContextMenuRequested({});
122 QCOMPARE(action->isEnabled(), !expectDisabled);
123
124 action->setEnabled(true);
125 QString text;
126 if (expectError.empty()) {
127 ConfirmSend(&text, cancel ? QMessageBox::Cancel : QMessageBox::Yes);
128 } else {
129 ConfirmMessage(&text, 0ms);
130 }
131 action->trigger();
132 QVERIFY(text.indexOf(QString::fromStdString(expectError)) != -1);
133}
134
135void CompareBalance(WalletModel& walletModel, CAmount expected_balance, QLabel* balance_label_to_check)
136{
137 BitcoinUnit unit = walletModel.getOptionsModel()->getDisplayUnit();
138 QString balanceComparison = BitcoinUnits::formatWithUnit(unit, expected_balance, false, BitcoinUnits::SeparatorStyle::ALWAYS);
139 QCOMPARE(balance_label_to_check->text().trimmed(), balanceComparison);
140}
141
142// Verify the 'useAvailableBalance' functionality. With and without manually selected coins.
143// Case 1: No coin control selected coins.
144// 'useAvailableBalance' should fill the amount edit box with the total available balance
145// Case 2: With coin control selected coins.
146// 'useAvailableBalance' should fill the amount edit box with the sum of the selected coins values.
147void VerifyUseAvailableBalance(SendCoinsDialog& sendCoinsDialog, const WalletModel& walletModel)
148{
149 // Verify first entry amount and "useAvailableBalance" button
150 QVBoxLayout* entries = sendCoinsDialog.findChild<QVBoxLayout*>("entries");
151 QVERIFY(entries->count() == 1); // only one entry
152 SendCoinsEntry* send_entry = qobject_cast<SendCoinsEntry*>(entries->itemAt(0)->widget());
153 QVERIFY(send_entry->getValue().amount == 0);
154 // Now click "useAvailableBalance", check updated balance (the entire wallet balance should be set)
155 Q_EMIT send_entry->useAvailableBalance(send_entry);
156 QVERIFY(send_entry->getValue().amount == walletModel.getCachedBalance().balance);
157
158 // Now manually select two coins and click on "useAvailableBalance". Then check updated balance
159 // (only the sum of the selected coins should be set).
160 int COINS_TO_SELECT = 2;
161 auto coins = walletModel.wallet().listCoins();
162 CAmount sum_selected_coins = 0;
163 int selected = 0;
164 QVERIFY(coins.size() == 1); // context check, coins received only on one destination
165 for (const auto& [outpoint, tx_out] : coins.begin()->second) {
166 sendCoinsDialog.getCoinControl()->Select(outpoint);
167 sum_selected_coins += tx_out.txout.nValue;
168 if (++selected == COINS_TO_SELECT) break;
169 }
170 QVERIFY(selected == COINS_TO_SELECT);
171
172 // Now that we have 2 coins selected, "useAvailableBalance" should update the balance label only with
173 // the sum of them.
174 Q_EMIT send_entry->useAvailableBalance(send_entry);
175 QVERIFY(send_entry->getValue().amount == sum_selected_coins);
176}
177
178void SyncUpWallet(const std::shared_ptr<CWallet>& wallet, interfaces::Node& node)
179{
180 WalletRescanReserver reserver(*wallet);
181 reserver.reserve();
182 CWallet::ScanResult result = wallet->ScanForWalletTransactions(Params().GetConsensus().hashGenesisBlock, /*start_height=*/0, /*max_height=*/{}, reserver, /*save_progress=*/false);
183 QCOMPARE(result.status, CWallet::ScanResult::SUCCESS);
184 QCOMPARE(result.last_scanned_block, WITH_LOCK(node.context()->chainman->GetMutex(), return node.context()->chainman->ActiveChain().Tip()->GetBlockHash()));
185 QVERIFY(result.last_failed_block.IsNull());
186}
187
188std::shared_ptr<CWallet> SetupDescriptorsWallet(interfaces::Node& node, TestChain100Setup& test, bool watch_only = false)
189{
190 std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), "", CreateMockableWalletDatabase());
191 LOCK(wallet->cs_wallet);
192 wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
193 if (watch_only) {
195 } else {
196 wallet->SetupDescriptorScriptPubKeyMans();
197 }
198
199 // Add the coinbase key
200 FlatSigningProvider provider;
201 std::string error;
202 std::string key_str;
203 if (watch_only) {
204 key_str = HexStr(test.coinbaseKey.GetPubKey());
205 } else {
206 key_str = EncodeSecret(test.coinbaseKey);
207 }
208 auto descs = Parse("combo(" + key_str + ")", provider, error, /* require_checksum=*/ false);
209 assert(!descs.empty());
210 assert(descs.size() == 1);
211 auto& desc = descs.at(0);
212 WalletDescriptor w_desc(std::move(desc), 0, 0, 1, 1);
213 Assert(wallet->AddWalletDescriptor(w_desc, provider, "", false));
214 const PKHash dest{test.coinbaseKey.GetPubKey()};
215 wallet->SetAddressBook(dest, "", wallet::AddressPurpose::RECEIVE);
216 wallet->SetLastBlockProcessed(105, WITH_LOCK(node.context()->chainman->GetMutex(), return node.context()->chainman->ActiveChain().Tip()->GetBlockHash()));
217 SyncUpWallet(wallet, node);
218 wallet->SetBroadcastTransactions(true);
219 return wallet;
220}
221
222struct MiniGUI {
223public:
224 SendCoinsDialog sendCoinsDialog;
225 TransactionView transactionView;
226 OptionsModel optionsModel;
227 std::unique_ptr<ClientModel> clientModel;
228 std::unique_ptr<WalletModel> walletModel;
229
230 MiniGUI(interfaces::Node& node, const PlatformStyle* platformStyle) : sendCoinsDialog(platformStyle), transactionView(platformStyle), optionsModel(node) {
231 bilingual_str error;
232 QVERIFY(optionsModel.Init(error));
233 clientModel = std::make_unique<ClientModel>(node, &optionsModel);
234 }
235
236 void initModelForWallet(interfaces::Node& node, const std::shared_ptr<CWallet>& wallet, const PlatformStyle* platformStyle)
237 {
238 WalletContext& context = *node.walletLoader().context();
239 AddWallet(context, wallet);
240 walletModel = std::make_unique<WalletModel>(interfaces::MakeWallet(context, wallet), *clientModel, platformStyle);
241 RemoveWallet(context, wallet, /* load_on_start= */ std::nullopt);
242 sendCoinsDialog.setModel(walletModel.get());
243 transactionView.setModel(walletModel.get());
244 }
245
246};
247
249//
250// Test widgets can be debugged interactively calling show() on them and
251// manually running the event loop, e.g.:
252//
253// sendCoinsDialog.show();
254// QEventLoop().exec();
255//
256// This also requires overriding the default minimal Qt platform:
257//
258// QT_QPA_PLATFORM=xcb build/bin/test_bitcoin-qt # Linux
259// QT_QPA_PLATFORM=windows build/bin/test_bitcoin-qt # Windows
260// QT_QPA_PLATFORM=cocoa build/bin/test_bitcoin-qt # macOS
261void TestGUI(interfaces::Node& node, const std::shared_ptr<CWallet>& wallet)
262{
263 // Create widgets for sending coins and listing transactions.
264 std::unique_ptr<const PlatformStyle> platformStyle(PlatformStyle::instantiate("other"));
265 MiniGUI mini_gui(node, platformStyle.get());
266 mini_gui.initModelForWallet(node, wallet, platformStyle.get());
267 WalletModel& walletModel = *mini_gui.walletModel;
268 SendCoinsDialog& sendCoinsDialog = mini_gui.sendCoinsDialog;
269 TransactionView& transactionView = mini_gui.transactionView;
270
271 // Update walletModel cached balance which will trigger an update for the 'labelBalance' QLabel.
272 walletModel.pollBalanceChanged();
273 // Check balance in send dialog
274 CompareBalance(walletModel, walletModel.wallet().getBalance(), sendCoinsDialog.findChild<QLabel*>("labelBalance"));
275
276 // Check 'UseAvailableBalance' functionality
277 VerifyUseAvailableBalance(sendCoinsDialog, walletModel);
278
279 // Send two transactions, and verify they are added to transaction list.
280 TransactionTableModel* transactionTableModel = walletModel.getTransactionTableModel();
281 QCOMPARE(transactionTableModel->rowCount({}), 105);
282 Txid txid1 = SendCoins(*wallet.get(), sendCoinsDialog, PKHash(), 5 * COIN);
283 Txid txid2 = SendCoins(*wallet.get(), sendCoinsDialog, PKHash(), 10 * COIN);
284 // Transaction table model updates on a QueuedConnection, so process events to ensure it's updated.
285 qApp->processEvents();
286 QCOMPARE(transactionTableModel->rowCount({}), 107);
287 QVERIFY(FindTx(*transactionTableModel, txid1).isValid());
288 QVERIFY(FindTx(*transactionTableModel, txid2).isValid());
289
290 // Call bumpfee. Test canceled fullrbf bump, canceled bip-125-rbf bump, passing bump, and then failing bump.
291 BumpFee(transactionView, txid1, /*expectDisabled=*/false, /*expectError=*/{}, /*cancel=*/true);
292 BumpFee(transactionView, txid2, /*expectDisabled=*/false, /*expectError=*/{}, /*cancel=*/true);
293 BumpFee(transactionView, txid2, /*expectDisabled=*/false, /*expectError=*/{}, /*cancel=*/false);
294 BumpFee(transactionView, txid2, /*expectDisabled=*/true, /*expectError=*/"already bumped", /*cancel=*/false);
295
296 // Check current balance on OverviewPage
297 OverviewPage overviewPage(platformStyle.get());
298 overviewPage.setWalletModel(&walletModel);
299 walletModel.pollBalanceChanged(); // Manual balance polling update
300 CompareBalance(walletModel, walletModel.wallet().getBalance(), overviewPage.findChild<QLabel*>("labelBalance"));
301
302 // Check Request Payment button
303 ReceiveCoinsDialog receiveCoinsDialog(platformStyle.get());
304 receiveCoinsDialog.setModel(&walletModel);
305 RecentRequestsTableModel* requestTableModel = walletModel.getRecentRequestsTableModel();
306
307 // Label input
308 QLineEdit* labelInput = receiveCoinsDialog.findChild<QLineEdit*>("reqLabel");
309 labelInput->setText("TEST_LABEL_1");
310
311 // Amount input
312 BitcoinAmountField* amountInput = receiveCoinsDialog.findChild<BitcoinAmountField*>("reqAmount");
313 amountInput->setValue(1);
314
315 // Message input
316 QLineEdit* messageInput = receiveCoinsDialog.findChild<QLineEdit*>("reqMessage");
317 messageInput->setText("TEST_MESSAGE_1");
318 int initialRowCount = requestTableModel->rowCount({});
319 QPushButton* requestPaymentButton = receiveCoinsDialog.findChild<QPushButton*>("receiveButton");
320 requestPaymentButton->click();
321 QString address;
322 for (QWidget* widget : QApplication::topLevelWidgets()) {
323 if (widget->inherits("ReceiveRequestDialog")) {
324 ReceiveRequestDialog* receiveRequestDialog = qobject_cast<ReceiveRequestDialog*>(widget);
325 QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("payment_header")->text(), QString("Payment information"));
326 QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("uri_tag")->text(), QString("URI:"));
327 QString uri = receiveRequestDialog->QObject::findChild<QLabel*>("uri_content")->text();
328 QCOMPARE(uri.count("bitcoin:"), 2);
329 QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("address_tag")->text(), QString("Address:"));
330 QVERIFY(address.isEmpty());
331 address = receiveRequestDialog->QObject::findChild<QLabel*>("address_content")->text();
332 QVERIFY(!address.isEmpty());
333
334 QCOMPARE(uri.count("amount=0.00000001"), 2);
335 QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("amount_tag")->text(), QString("Amount:"));
336 QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("amount_content")->text(), QString::fromStdString("0.00000001 " + CURRENCY_UNIT));
337
338 QCOMPARE(uri.count("label=TEST_LABEL_1"), 2);
339 QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("label_tag")->text(), QString("Label:"));
340 QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("label_content")->text(), QString("TEST_LABEL_1"));
341
342 QCOMPARE(uri.count("message=TEST_MESSAGE_1"), 2);
343 QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("message_tag")->text(), QString("Message:"));
344 QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("message_content")->text(), QString("TEST_MESSAGE_1"));
345 }
346 }
347
348 // Clear button
349 QPushButton* clearButton = receiveCoinsDialog.findChild<QPushButton*>("clearButton");
350 clearButton->click();
351 QCOMPARE(labelInput->text(), QString(""));
352 QCOMPARE(amountInput->value(), CAmount(0));
353 QCOMPARE(messageInput->text(), QString(""));
354
355 // Check addition to history
356 int currentRowCount = requestTableModel->rowCount({});
357 QCOMPARE(currentRowCount, initialRowCount+1);
358
359 // Check addition to wallet
360 std::vector<std::string> requests = walletModel.wallet().getAddressReceiveRequests();
361 QCOMPARE(requests.size(), size_t{1});
362 RecentRequestEntry entry;
363 SpanReader{MakeByteSpan(requests[0])} >> entry;
364 QCOMPARE(entry.nVersion, int{1});
365 QCOMPARE(entry.id, int64_t{1});
366 QVERIFY(entry.date.isValid());
367 QCOMPARE(entry.recipient.address, address);
368 QCOMPARE(entry.recipient.label, QString{"TEST_LABEL_1"});
369 QCOMPARE(entry.recipient.amount, CAmount{1});
370 QCOMPARE(entry.recipient.message, QString{"TEST_MESSAGE_1"});
371 QCOMPARE(entry.recipient.sPaymentRequest, std::string{});
372 QCOMPARE(entry.recipient.authenticatedMerchant, QString{});
373
374 // Check Remove button
375 QTableView* table = receiveCoinsDialog.findChild<QTableView*>("recentRequestsView");
376 table->selectRow(currentRowCount-1);
377 QPushButton* removeRequestButton = receiveCoinsDialog.findChild<QPushButton*>("removeRequestButton");
378 removeRequestButton->click();
379 QCOMPARE(requestTableModel->rowCount({}), currentRowCount-1);
380
381 // Check removal from wallet
382 QCOMPARE(walletModel.wallet().getAddressReceiveRequests().size(), size_t{0});
383}
384
385void TestGUIWatchOnly(interfaces::Node& node, TestChain100Setup& test)
386{
387 const std::shared_ptr<CWallet>& wallet = SetupDescriptorsWallet(node, test, /*watch_only=*/true);
388
389 // Create widgets and init models
390 std::unique_ptr<const PlatformStyle> platformStyle(PlatformStyle::instantiate("other"));
391 MiniGUI mini_gui(node, platformStyle.get());
392 mini_gui.initModelForWallet(node, wallet, platformStyle.get());
393 WalletModel& walletModel = *mini_gui.walletModel;
394 SendCoinsDialog& sendCoinsDialog = mini_gui.sendCoinsDialog;
395
396 // Update walletModel cached balance which will trigger an update for the 'labelBalance' QLabel.
397 walletModel.pollBalanceChanged();
398 // Check balance in send dialog
399 CompareBalance(walletModel, walletModel.wallet().getBalances().balance,
400 sendCoinsDialog.findChild<QLabel*>("labelBalance"));
401
402 // Set change address
403 sendCoinsDialog.getCoinControl()->destChange = PKHash{test.coinbaseKey.GetPubKey()};
404
405 // Time to reject "save" PSBT dialog ('SendCoins' locks the main thread until the dialog receives the event).
406 QTimer timer;
407 timer.setInterval(500);
408 QObject::connect(&timer, &QTimer::timeout, [&](){
409 for (QWidget* widget : QApplication::topLevelWidgets()) {
410 if (widget->inherits("QMessageBox") && widget->objectName().compare("psbt_copied_message") == 0) {
411 QMessageBox* dialog = qobject_cast<QMessageBox*>(widget);
412 QAbstractButton* button = dialog->button(QMessageBox::Discard);
413 button->setEnabled(true);
414 button->click();
415 timer.stop();
416 break;
417 }
418 }
419 });
420 timer.start(500);
421
422 // Send tx and verify PSBT copied to the clipboard.
423 SendCoins(*wallet.get(), sendCoinsDialog, PKHash(), 5 * COIN, QMessageBox::Save);
424 const std::string& psbt_string = QApplication::clipboard()->text().toStdString();
425 QVERIFY(!psbt_string.empty());
426
427 // Decode psbt
428 std::optional<std::vector<unsigned char>> decoded_psbt = DecodeBase64(psbt_string);
429 QVERIFY(decoded_psbt);
431 QVERIFY(psbt);
432}
433
434void TestGUI(interfaces::Node& node)
435{
436 // Set up wallet and chain with 105 blocks (5 mature blocks for spending).
438 for (int i = 0; i < 5; ++i) {
440 }
441 auto wallet_loader = interfaces::MakeWalletLoader(*test.m_node.chain, *Assert(test.m_node.args));
442 test.m_node.wallet_loader = wallet_loader.get();
443 node.setContext(&test.m_node);
444
445 // "Full" GUI tests, use descriptor wallet
446 const std::shared_ptr<CWallet>& desc_wallet = SetupDescriptorsWallet(node, test);
447 TestGUI(node, desc_wallet);
448
449 // Legacy watch-only wallet test
450 // Verify PSBT creation.
451 TestGUIWatchOnly(node, test);
452}
453
454} // namespace
455
457{
458#ifdef Q_OS_MACOS
459 if (QApplication::platformName() == "minimal") {
460 // Disable for mac on "minimal" platform to avoid crashes inside the Qt
461 // framework when it tries to look up unimplemented cocoa functions,
462 // and fails to handle returned nulls
463 // (https://bugreports.qt.io/browse/QTBUG-49686).
464 qWarning() << "Skipping WalletTests on mac build with 'minimal' platform set due to Qt bugs. To run AppTests, invoke "
465 "with 'QT_QPA_PLATFORM=cocoa test_bitcoin-qt' on mac, or else use a linux or windows build.";
466 return;
467 }
468#endif
469 TestGUI(m_node);
470}
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
Definition: addresstype.h:143
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
static constexpr CAmount COIN
The amount of satoshis in one BTC.
Definition: amount.h:15
const CChainParams & Params()
Return the currently selected parameters.
#define Assert(val)
Identity function.
Definition: check.h:116
Widget for entering bitcoin amounts.
void setValue(const CAmount &value)
static QString formatWithUnit(Unit unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD)
Format as string (with unit)
Unit
Bitcoin units.
Definition: bitcoinunits.h:42
CPubKey GetPubKey() const
Compute the public key from a private key.
Definition: key.cpp:182
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:44
bool Init(bilingual_str &error)
BitcoinUnit getDisplayUnit() const
Definition: optionsmodel.h:104
Overview ("home") page widget.
Definition: overviewpage.h:29
static const PlatformStyle * instantiate(const QString &platformId)
Get style associated with provided platform name, or 0 if not known.
Line edit that can be marked as "invalid" to show input validation feedback.
Dialog for requesting payment of bitcoins.
int64_t id
SendCoinsRecipient recipient
int nVersion
QDateTime date
Model for list of recently generated payment requests / bitcoin: URIs.
int rowCount(const QModelIndex &parent) const override
Dialog for sending bitcoins.
void setModel(WalletModel *model)
wallet::CCoinControl * getCoinControl()
A single entry in the dialog for sending bitcoins.
void useAvailableBalance(SendCoinsEntry *entry)
SendCoinsRecipient getValue()
std::string sPaymentRequest
Minimal stream for reading from an existing byte array by std::span.
Definition: streams.h:83
UI model for the transaction table of a wallet.
@ TxHashRole
Transaction hash.
int rowCount(const QModelIndex &parent) const override
Widget showing the transaction list for a wallet, including a filter row.
void setModel(WalletModel *model)
QTableView * transactionView
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:49
RecentRequestsTableModel * getRecentRequestsTableModel() const
void pollBalanceChanged()
Definition: walletmodel.cpp:92
TransactionTableModel * getTransactionTableModel() const
interfaces::Wallet & wallet() const
Definition: walletmodel.h:138
OptionsModel * getOptionsModel() const
interfaces::WalletBalances getCachedBalance() const
void walletTests()
interfaces::Node & m_node
Definition: wallettests.h:19
Top-level interface for a bitcoin node (bitcoind process).
Definition: node.h:71
virtual CoinsList listCoins()=0
virtual CAmount getBalance()=0
Get balance.
virtual WalletBalances getBalances()=0
Get balances.
virtual std::vector< std::string > getAddressReceiveRequests()=0
Get receive requests.
std::string ToString() const
PreselectedInput & Select(const COutPoint &outpoint)
Lock-in the given output for spending.
Definition: coincontrol.cpp:40
CTxDestination destChange
Custom change destination, if not set an address is generated.
Definition: coincontrol.h:87
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition: wallet.h:309
Descriptor with some wallet metadata.
Definition: walletutil.h:64
RAII object to check and reserve a wallet rescan.
Definition: wallet.h:1090
static UniValue Parse(std::string_view raw, ParamFormat format=ParamFormat::JSON)
Parse string to UniValue or throw runtime_error if string contains invalid JSON.
Definition: client.cpp:400
const std::string CURRENCY_UNIT
Definition: feerate.h:19
std::string HexStr(const std::span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
Definition: hex_base.cpp:30
std::string EncodeSecret(const CKey &key)
Definition: key_io.cpp:232
std::string EncodeDestination(const CTxDestination &dest)
Definition: key_io.cpp:295
std::unique_ptr< WalletLoader > MakeWalletLoader(Chain &chain, ArgsManager &args)
Return implementation of ChainClient interface for a wallet loader.
Definition: dummywallet.cpp:59
std::unique_ptr< Wallet > MakeWallet(wallet::WalletContext &context, const std::shared_ptr< wallet::CWallet > &wallet)
Return implementation of Wallet interface.
Definition: interfaces.cpp:668
Definition: messages.h:21
std::unique_ptr< WalletDatabase > CreateMockableWalletDatabase()
Definition: util.cpp:122
bool AddWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet)
Definition: wallet.cpp:152
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.
Definition: walletutil.h:53
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS
Definition: walletutil.h:30
bool RemoveWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
Definition: wallet.cpp:164
util::Result< PartiallySignedTransaction > DecodeRawPSBT(std::span< const std::byte > tx_data)
Decode a raw (binary blob) PSBT into a PartiallySignedTransaction.
Definition: psbt.cpp:873
void ConfirmMessage(QString *text, std::chrono::milliseconds msec)
Press "Ok" button in message box dialog.
Definition: util.cpp:16
CScript GetScriptForRawPubKey(const CPubKey &pubKey)
Generate a P2PK script for the given pubkey.
Definition: solver.cpp:213
auto MakeByteSpan(const V &v) noexcept
Definition: span.h:84
node::NodeContext m_node
Definition: setup_common.h:58
Testing fixture that pre-creates a 100-block REGTEST-mode block chain.
Definition: setup_common.h:137
CBlock CreateAndProcessBlock(const std::vector< CMutableTransaction > &txns, const CScript &scriptPubKey)
Create a new block with just given transactions, coinbase paying to scriptPubKey, and try to add it t...
Bilingual messages:
Definition: translation.h:24
ArgsManager * args
Definition: context.h:78
interfaces::WalletLoader * wallet_loader
Definition: context.h:91
std::unique_ptr< interfaces::Chain > chain
Definition: context.h:80
WalletContext struct containing references to state shared between CWallet instances,...
Definition: context.h:36
#define LOCK(cs)
Definition: sync.h:268
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:299
ChangeType
General change type (added, updated, removed).
Definition: ui_change_type.h:9
std::optional< std::vector< unsigned char > > DecodeBase64(std::string_view str)
assert(!tx.IsCoinBase())