Bitcoin Core 29.99.0
P2P Digital Currency
wallettests.cpp
Go to the documentation of this file.
1// Copyright (c) 2015-2022 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, bool rbf,
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 sendCoinsDialog.findChild<QFrame*>("frameFee")
86 ->findChild<QFrame*>("frameFeeSelection")
87 ->findChild<QCheckBox*>("optInRBF")
88 ->setCheckState(rbf ? Qt::Checked : Qt::Unchecked);
89 Txid txid;
90 boost::signals2::scoped_connection c(wallet.NotifyTransactionChanged.connect([&txid](const Txid& hash, ChangeType status) {
91 if (status == CT_NEW) txid = hash;
92 }));
93 ConfirmSend(/*text=*/nullptr, confirm_type);
94 bool invoked = QMetaObject::invokeMethod(&sendCoinsDialog, "sendButtonClicked", Q_ARG(bool, false));
95 assert(invoked);
96 return txid;
97}
98
100QModelIndex FindTx(const QAbstractItemModel& model, const Txid& txid)
101{
102 QString hash = QString::fromStdString(txid.ToString());
103 int rows = model.rowCount({});
104 for (int row = 0; row < rows; ++row) {
105 QModelIndex index = model.index(row, 0, {});
106 if (model.data(index, TransactionTableModel::TxHashRole) == hash) {
107 return index;
108 }
109 }
110 return {};
111}
112
114void BumpFee(TransactionView& view, const Txid& txid, bool expectDisabled, std::string expectError, bool cancel)
115{
116 QTableView* table = view.findChild<QTableView*>("transactionView");
117 QModelIndex index = FindTx(*table->selectionModel()->model(), txid);
118 QVERIFY2(index.isValid(), "Could not find BumpFee txid");
119
120 // Select row in table, invoke context menu, and make sure bumpfee action is
121 // enabled or disabled as expected.
122 QAction* action = view.findChild<QAction*>("bumpFeeAction");
123 table->selectionModel()->select(index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
124 action->setEnabled(expectDisabled);
125 table->customContextMenuRequested({});
126 QCOMPARE(action->isEnabled(), !expectDisabled);
127
128 action->setEnabled(true);
129 QString text;
130 if (expectError.empty()) {
131 ConfirmSend(&text, cancel ? QMessageBox::Cancel : QMessageBox::Yes);
132 } else {
133 ConfirmMessage(&text, 0ms);
134 }
135 action->trigger();
136 QVERIFY(text.indexOf(QString::fromStdString(expectError)) != -1);
137}
138
139void CompareBalance(WalletModel& walletModel, CAmount expected_balance, QLabel* balance_label_to_check)
140{
141 BitcoinUnit unit = walletModel.getOptionsModel()->getDisplayUnit();
142 QString balanceComparison = BitcoinUnits::formatWithUnit(unit, expected_balance, false, BitcoinUnits::SeparatorStyle::ALWAYS);
143 QCOMPARE(balance_label_to_check->text().trimmed(), balanceComparison);
144}
145
146// Verify the 'useAvailableBalance' functionality. With and without manually selected coins.
147// Case 1: No coin control selected coins.
148// 'useAvailableBalance' should fill the amount edit box with the total available balance
149// Case 2: With coin control selected coins.
150// 'useAvailableBalance' should fill the amount edit box with the sum of the selected coins values.
151void VerifyUseAvailableBalance(SendCoinsDialog& sendCoinsDialog, const WalletModel& walletModel)
152{
153 // Verify first entry amount and "useAvailableBalance" button
154 QVBoxLayout* entries = sendCoinsDialog.findChild<QVBoxLayout*>("entries");
155 QVERIFY(entries->count() == 1); // only one entry
156 SendCoinsEntry* send_entry = qobject_cast<SendCoinsEntry*>(entries->itemAt(0)->widget());
157 QVERIFY(send_entry->getValue().amount == 0);
158 // Now click "useAvailableBalance", check updated balance (the entire wallet balance should be set)
159 Q_EMIT send_entry->useAvailableBalance(send_entry);
160 QVERIFY(send_entry->getValue().amount == walletModel.getCachedBalance().balance);
161
162 // Now manually select two coins and click on "useAvailableBalance". Then check updated balance
163 // (only the sum of the selected coins should be set).
164 int COINS_TO_SELECT = 2;
165 auto coins = walletModel.wallet().listCoins();
166 CAmount sum_selected_coins = 0;
167 int selected = 0;
168 QVERIFY(coins.size() == 1); // context check, coins received only on one destination
169 for (const auto& [outpoint, tx_out] : coins.begin()->second) {
170 sendCoinsDialog.getCoinControl()->Select(outpoint);
171 sum_selected_coins += tx_out.txout.nValue;
172 if (++selected == COINS_TO_SELECT) break;
173 }
174 QVERIFY(selected == COINS_TO_SELECT);
175
176 // Now that we have 2 coins selected, "useAvailableBalance" should update the balance label only with
177 // the sum of them.
178 Q_EMIT send_entry->useAvailableBalance(send_entry);
179 QVERIFY(send_entry->getValue().amount == sum_selected_coins);
180}
181
182void SyncUpWallet(const std::shared_ptr<CWallet>& wallet, interfaces::Node& node)
183{
184 WalletRescanReserver reserver(*wallet);
185 reserver.reserve();
186 CWallet::ScanResult result = wallet->ScanForWalletTransactions(Params().GetConsensus().hashGenesisBlock, /*start_height=*/0, /*max_height=*/{}, reserver, /*fUpdate=*/true, /*save_progress=*/false);
187 QCOMPARE(result.status, CWallet::ScanResult::SUCCESS);
188 QCOMPARE(result.last_scanned_block, WITH_LOCK(node.context()->chainman->GetMutex(), return node.context()->chainman->ActiveChain().Tip()->GetBlockHash()));
189 QVERIFY(result.last_failed_block.IsNull());
190}
191
192std::shared_ptr<CWallet> SetupDescriptorsWallet(interfaces::Node& node, TestChain100Setup& test, bool watch_only = false)
193{
194 std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), "", CreateMockableWalletDatabase());
195 wallet->LoadWallet();
196 LOCK(wallet->cs_wallet);
197 wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
198 if (watch_only) {
200 } else {
201 wallet->SetupDescriptorScriptPubKeyMans();
202 }
203
204 // Add the coinbase key
205 FlatSigningProvider provider;
206 std::string error;
207 std::string key_str;
208 if (watch_only) {
209 key_str = HexStr(test.coinbaseKey.GetPubKey());
210 } else {
211 key_str = EncodeSecret(test.coinbaseKey);
212 }
213 auto descs = Parse("combo(" + key_str + ")", provider, error, /* require_checksum=*/ false);
214 assert(!descs.empty());
215 assert(descs.size() == 1);
216 auto& desc = descs.at(0);
217 WalletDescriptor w_desc(std::move(desc), 0, 0, 1, 1);
218 Assert(wallet->AddWalletDescriptor(w_desc, provider, "", false));
219 const PKHash dest{test.coinbaseKey.GetPubKey()};
220 wallet->SetAddressBook(dest, "", wallet::AddressPurpose::RECEIVE);
221 wallet->SetLastBlockProcessed(105, WITH_LOCK(node.context()->chainman->GetMutex(), return node.context()->chainman->ActiveChain().Tip()->GetBlockHash()));
222 SyncUpWallet(wallet, node);
223 wallet->SetBroadcastTransactions(true);
224 return wallet;
225}
226
227struct MiniGUI {
228public:
229 SendCoinsDialog sendCoinsDialog;
230 TransactionView transactionView;
231 OptionsModel optionsModel;
232 std::unique_ptr<ClientModel> clientModel;
233 std::unique_ptr<WalletModel> walletModel;
234
235 MiniGUI(interfaces::Node& node, const PlatformStyle* platformStyle) : sendCoinsDialog(platformStyle), transactionView(platformStyle), optionsModel(node) {
236 bilingual_str error;
237 QVERIFY(optionsModel.Init(error));
238 clientModel = std::make_unique<ClientModel>(node, &optionsModel);
239 }
240
241 void initModelForWallet(interfaces::Node& node, const std::shared_ptr<CWallet>& wallet, const PlatformStyle* platformStyle)
242 {
243 WalletContext& context = *node.walletLoader().context();
244 AddWallet(context, wallet);
245 walletModel = std::make_unique<WalletModel>(interfaces::MakeWallet(context, wallet), *clientModel, platformStyle);
246 RemoveWallet(context, wallet, /* load_on_start= */ std::nullopt);
247 sendCoinsDialog.setModel(walletModel.get());
248 transactionView.setModel(walletModel.get());
249 }
250
251};
252
254//
255// Test widgets can be debugged interactively calling show() on them and
256// manually running the event loop, e.g.:
257//
258// sendCoinsDialog.show();
259// QEventLoop().exec();
260//
261// This also requires overriding the default minimal Qt platform:
262//
263// QT_QPA_PLATFORM=xcb build/bin/test_bitcoin-qt # Linux
264// QT_QPA_PLATFORM=windows build/bin/test_bitcoin-qt # Windows
265// QT_QPA_PLATFORM=cocoa build/bin/test_bitcoin-qt # macOS
266void TestGUI(interfaces::Node& node, const std::shared_ptr<CWallet>& wallet)
267{
268 // Create widgets for sending coins and listing transactions.
269 std::unique_ptr<const PlatformStyle> platformStyle(PlatformStyle::instantiate("other"));
270 MiniGUI mini_gui(node, platformStyle.get());
271 mini_gui.initModelForWallet(node, wallet, platformStyle.get());
272 WalletModel& walletModel = *mini_gui.walletModel;
273 SendCoinsDialog& sendCoinsDialog = mini_gui.sendCoinsDialog;
274 TransactionView& transactionView = mini_gui.transactionView;
275
276 // Update walletModel cached balance which will trigger an update for the 'labelBalance' QLabel.
277 walletModel.pollBalanceChanged();
278 // Check balance in send dialog
279 CompareBalance(walletModel, walletModel.wallet().getBalance(), sendCoinsDialog.findChild<QLabel*>("labelBalance"));
280
281 // Check 'UseAvailableBalance' functionality
282 VerifyUseAvailableBalance(sendCoinsDialog, walletModel);
283
284 // Send two transactions, and verify they are added to transaction list.
285 TransactionTableModel* transactionTableModel = walletModel.getTransactionTableModel();
286 QCOMPARE(transactionTableModel->rowCount({}), 105);
287 Txid txid1 = SendCoins(*wallet.get(), sendCoinsDialog, PKHash(), 5 * COIN, /*rbf=*/false);
288 Txid txid2 = SendCoins(*wallet.get(), sendCoinsDialog, PKHash(), 10 * COIN, /*rbf=*/true);
289 // Transaction table model updates on a QueuedConnection, so process events to ensure it's updated.
290 qApp->processEvents();
291 QCOMPARE(transactionTableModel->rowCount({}), 107);
292 QVERIFY(FindTx(*transactionTableModel, txid1).isValid());
293 QVERIFY(FindTx(*transactionTableModel, txid2).isValid());
294
295 // Call bumpfee. Test canceled fullrbf bump, canceled bip-125-rbf bump, passing bump, and then failing bump.
296 BumpFee(transactionView, txid1, /*expectDisabled=*/false, /*expectError=*/{}, /*cancel=*/true);
297 BumpFee(transactionView, txid2, /*expectDisabled=*/false, /*expectError=*/{}, /*cancel=*/true);
298 BumpFee(transactionView, txid2, /*expectDisabled=*/false, /*expectError=*/{}, /*cancel=*/false);
299 BumpFee(transactionView, txid2, /*expectDisabled=*/true, /*expectError=*/"already bumped", /*cancel=*/false);
300
301 // Check current balance on OverviewPage
302 OverviewPage overviewPage(platformStyle.get());
303 overviewPage.setWalletModel(&walletModel);
304 walletModel.pollBalanceChanged(); // Manual balance polling update
305 CompareBalance(walletModel, walletModel.wallet().getBalance(), overviewPage.findChild<QLabel*>("labelBalance"));
306
307 // Check Request Payment button
308 ReceiveCoinsDialog receiveCoinsDialog(platformStyle.get());
309 receiveCoinsDialog.setModel(&walletModel);
310 RecentRequestsTableModel* requestTableModel = walletModel.getRecentRequestsTableModel();
311
312 // Label input
313 QLineEdit* labelInput = receiveCoinsDialog.findChild<QLineEdit*>("reqLabel");
314 labelInput->setText("TEST_LABEL_1");
315
316 // Amount input
317 BitcoinAmountField* amountInput = receiveCoinsDialog.findChild<BitcoinAmountField*>("reqAmount");
318 amountInput->setValue(1);
319
320 // Message input
321 QLineEdit* messageInput = receiveCoinsDialog.findChild<QLineEdit*>("reqMessage");
322 messageInput->setText("TEST_MESSAGE_1");
323 int initialRowCount = requestTableModel->rowCount({});
324 QPushButton* requestPaymentButton = receiveCoinsDialog.findChild<QPushButton*>("receiveButton");
325 requestPaymentButton->click();
326 QString address;
327 for (QWidget* widget : QApplication::topLevelWidgets()) {
328 if (widget->inherits("ReceiveRequestDialog")) {
329 ReceiveRequestDialog* receiveRequestDialog = qobject_cast<ReceiveRequestDialog*>(widget);
330 QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("payment_header")->text(), QString("Payment information"));
331 QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("uri_tag")->text(), QString("URI:"));
332 QString uri = receiveRequestDialog->QObject::findChild<QLabel*>("uri_content")->text();
333 QCOMPARE(uri.count("bitcoin:"), 2);
334 QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("address_tag")->text(), QString("Address:"));
335 QVERIFY(address.isEmpty());
336 address = receiveRequestDialog->QObject::findChild<QLabel*>("address_content")->text();
337 QVERIFY(!address.isEmpty());
338
339 QCOMPARE(uri.count("amount=0.00000001"), 2);
340 QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("amount_tag")->text(), QString("Amount:"));
341 QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("amount_content")->text(), QString::fromStdString("0.00000001 " + CURRENCY_UNIT));
342
343 QCOMPARE(uri.count("label=TEST_LABEL_1"), 2);
344 QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("label_tag")->text(), QString("Label:"));
345 QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("label_content")->text(), QString("TEST_LABEL_1"));
346
347 QCOMPARE(uri.count("message=TEST_MESSAGE_1"), 2);
348 QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("message_tag")->text(), QString("Message:"));
349 QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("message_content")->text(), QString("TEST_MESSAGE_1"));
350 }
351 }
352
353 // Clear button
354 QPushButton* clearButton = receiveCoinsDialog.findChild<QPushButton*>("clearButton");
355 clearButton->click();
356 QCOMPARE(labelInput->text(), QString(""));
357 QCOMPARE(amountInput->value(), CAmount(0));
358 QCOMPARE(messageInput->text(), QString(""));
359
360 // Check addition to history
361 int currentRowCount = requestTableModel->rowCount({});
362 QCOMPARE(currentRowCount, initialRowCount+1);
363
364 // Check addition to wallet
365 std::vector<std::string> requests = walletModel.wallet().getAddressReceiveRequests();
366 QCOMPARE(requests.size(), size_t{1});
367 RecentRequestEntry entry;
368 DataStream{MakeUCharSpan(requests[0])} >> entry;
369 QCOMPARE(entry.nVersion, int{1});
370 QCOMPARE(entry.id, int64_t{1});
371 QVERIFY(entry.date.isValid());
372 QCOMPARE(entry.recipient.address, address);
373 QCOMPARE(entry.recipient.label, QString{"TEST_LABEL_1"});
374 QCOMPARE(entry.recipient.amount, CAmount{1});
375 QCOMPARE(entry.recipient.message, QString{"TEST_MESSAGE_1"});
376 QCOMPARE(entry.recipient.sPaymentRequest, std::string{});
377 QCOMPARE(entry.recipient.authenticatedMerchant, QString{});
378
379 // Check Remove button
380 QTableView* table = receiveCoinsDialog.findChild<QTableView*>("recentRequestsView");
381 table->selectRow(currentRowCount-1);
382 QPushButton* removeRequestButton = receiveCoinsDialog.findChild<QPushButton*>("removeRequestButton");
383 removeRequestButton->click();
384 QCOMPARE(requestTableModel->rowCount({}), currentRowCount-1);
385
386 // Check removal from wallet
387 QCOMPARE(walletModel.wallet().getAddressReceiveRequests().size(), size_t{0});
388}
389
390void TestGUIWatchOnly(interfaces::Node& node, TestChain100Setup& test)
391{
392 const std::shared_ptr<CWallet>& wallet = SetupDescriptorsWallet(node, test, /*watch_only=*/true);
393
394 // Create widgets and init models
395 std::unique_ptr<const PlatformStyle> platformStyle(PlatformStyle::instantiate("other"));
396 MiniGUI mini_gui(node, platformStyle.get());
397 mini_gui.initModelForWallet(node, wallet, platformStyle.get());
398 WalletModel& walletModel = *mini_gui.walletModel;
399 SendCoinsDialog& sendCoinsDialog = mini_gui.sendCoinsDialog;
400
401 // Update walletModel cached balance which will trigger an update for the 'labelBalance' QLabel.
402 walletModel.pollBalanceChanged();
403 // Check balance in send dialog
404 CompareBalance(walletModel, walletModel.wallet().getBalances().balance,
405 sendCoinsDialog.findChild<QLabel*>("labelBalance"));
406
407 // Set change address
408 sendCoinsDialog.getCoinControl()->destChange = PKHash{test.coinbaseKey.GetPubKey()};
409
410 // Time to reject "save" PSBT dialog ('SendCoins' locks the main thread until the dialog receives the event).
411 QTimer timer;
412 timer.setInterval(500);
413 QObject::connect(&timer, &QTimer::timeout, [&](){
414 for (QWidget* widget : QApplication::topLevelWidgets()) {
415 if (widget->inherits("QMessageBox") && widget->objectName().compare("psbt_copied_message") == 0) {
416 QMessageBox* dialog = qobject_cast<QMessageBox*>(widget);
417 QAbstractButton* button = dialog->button(QMessageBox::Discard);
418 button->setEnabled(true);
419 button->click();
420 timer.stop();
421 break;
422 }
423 }
424 });
425 timer.start(500);
426
427 // Send tx and verify PSBT copied to the clipboard.
428 SendCoins(*wallet.get(), sendCoinsDialog, PKHash(), 5 * COIN, /*rbf=*/false, QMessageBox::Save);
429 const std::string& psbt_string = QApplication::clipboard()->text().toStdString();
430 QVERIFY(!psbt_string.empty());
431
432 // Decode psbt
433 std::optional<std::vector<unsigned char>> decoded_psbt = DecodeBase64(psbt_string);
434 QVERIFY(decoded_psbt);
436 std::string err;
437 QVERIFY(DecodeRawPSBT(psbt, MakeByteSpan(*decoded_psbt), err));
438}
439
440void TestGUI(interfaces::Node& node)
441{
442 // Set up wallet and chain with 105 blocks (5 mature blocks for spending).
444 for (int i = 0; i < 5; ++i) {
446 }
447 auto wallet_loader = interfaces::MakeWalletLoader(*test.m_node.chain, *Assert(test.m_node.args));
448 test.m_node.wallet_loader = wallet_loader.get();
449 node.setContext(&test.m_node);
450
451 // "Full" GUI tests, use descriptor wallet
452 const std::shared_ptr<CWallet>& desc_wallet = SetupDescriptorsWallet(node, test);
453 TestGUI(node, desc_wallet);
454
455 // Legacy watch-only wallet test
456 // Verify PSBT creation.
457 TestGUIWatchOnly(node, test);
458}
459
460} // namespace
461
463{
464#ifdef Q_OS_MACOS
465 if (QApplication::platformName() == "minimal") {
466 // Disable for mac on "minimal" platform to avoid crashes inside the Qt
467 // framework when it tries to look up unimplemented cocoa functions,
468 // and fails to handle returned nulls
469 // (https://bugreports.qt.io/browse/QTBUG-49686).
470 qWarning() << "Skipping WalletTests on mac build with 'minimal' platform set due to Qt bugs. To run AppTests, invoke "
471 "with 'QT_QPA_PLATFORM=cocoa test_bitcoin-qt' on mac, or else use a linux or windows build.";
472 return;
473 }
474#endif
475 TestGUI(m_node);
476}
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:106
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
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:147
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:43
bool Init(bilingual_str &error)
BitcoinUnit getDisplayUnit() const
Definition: optionsmodel.h:103
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
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:91
TransactionTableModel * getTransactionTableModel() const
interfaces::Wallet & wallet() const
Definition: walletmodel.h:139
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:84
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
Definition: wallet.h:301
Descriptor with some wallet metadata.
Definition: walletutil.h:85
RAII object to check and reserve a wallet rescan.
Definition: wallet.h:1059
static UniValue Parse(std::string_view raw)
Parse string to UniValue or throw runtime_error if string contains invalid JSON.
Definition: client.cpp:317
const std::string CURRENCY_UNIT
Definition: feerate.h:17
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:29
std::string EncodeSecret(const CKey &key)
Definition: key_io.cpp:231
std::string EncodeDestination(const CTxDestination &dest)
Definition: key_io.cpp:294
std::unique_ptr< WalletLoader > MakeWalletLoader(Chain &chain, ArgsManager &args)
Return implementation of ChainClient interface for a wallet loader.
Definition: dummywallet.cpp:60
std::unique_ptr< Wallet > MakeWallet(wallet::WalletContext &context, const std::shared_ptr< wallet::CWallet > &wallet)
Return implementation of Wallet interface.
Definition: interfaces.cpp:684
Definition: messages.h:20
std::unique_ptr< WalletDatabase > CreateMockableWalletDatabase(MockableData records)
Definition: util.cpp:186
bool AddWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet)
Definition: wallet.cpp:149
@ WALLET_FLAG_DESCRIPTORS
Indicate that this wallet supports DescriptorScriptPubKeyMan.
Definition: walletutil.h:74
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS
Definition: walletutil.h:51
bool RemoveWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
Definition: wallet.cpp:161
bool DecodeRawPSBT(PartiallySignedTransaction &psbt, std::span< const std::byte > tx_data, std::string &error)
Decode a raw (binary blob) PSBT into a PartiallySignedTransaction.
Definition: psbt.cpp:594
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
constexpr auto MakeUCharSpan(const V &v) -> decltype(UCharSpanCast(std::span{v}))
Like the std::span constructor, but for (const) unsigned char member types only.
Definition: span.h:111
node::NodeContext m_node
Definition: setup_common.h:66
A version of CTransaction with the PSBT format.
Definition: psbt.h:1119
Testing fixture that pre-creates a 100-block REGTEST-mode block chain.
Definition: setup_common.h:146
CBlock CreateAndProcessBlock(const std::vector< CMutableTransaction > &txns, const CScript &scriptPubKey, Chainstate *chainstate=nullptr)
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:74
interfaces::WalletLoader * wallet_loader
Definition: context.h:82
std::unique_ptr< interfaces::Chain > chain
Definition: context.h:76
WalletContext struct containing references to state shared between CWallet instances,...
Definition: context.h:36
#define LOCK(cs)
Definition: sync.h:257
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:302
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())