Bitcoin Core  24.99.0
P2P Digital Currency
walletmodel.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-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 
5 #if defined(HAVE_CONFIG_H)
7 #endif
8 
9 #include <qt/walletmodel.h>
10 
11 #include <qt/addresstablemodel.h>
12 #include <qt/clientmodel.h>
13 #include <qt/guiconstants.h>
14 #include <qt/guiutil.h>
15 #include <qt/optionsmodel.h>
16 #include <qt/paymentserver.h>
18 #include <qt/sendcoinsdialog.h>
20 
21 #include <interfaces/handler.h>
22 #include <interfaces/node.h>
23 #include <key_io.h>
24 #include <node/interface_ui.h>
25 #include <psbt.h>
26 #include <util/system.h> // for GetBoolArg
27 #include <util/translation.h>
28 #include <wallet/coincontrol.h>
29 #include <wallet/wallet.h> // for CRecipient
30 
31 #include <stdint.h>
32 #include <functional>
33 
34 #include <QDebug>
35 #include <QMessageBox>
36 #include <QSet>
37 #include <QTimer>
38 
40 using wallet::CRecipient;
42 
43 WalletModel::WalletModel(std::unique_ptr<interfaces::Wallet> wallet, ClientModel& client_model, const PlatformStyle *platformStyle, QObject *parent) :
44  QObject(parent),
45  m_wallet(std::move(wallet)),
46  m_client_model(&client_model),
47  m_node(client_model.node()),
48  optionsModel(client_model.getOptionsModel()),
49  timer(new QTimer(this))
50 {
51  fHaveWatchOnly = m_wallet->haveWatchOnly();
53  transactionTableModel = new TransactionTableModel(platformStyle, this);
55 
57 }
58 
60 {
62 }
63 
65 {
66  // Update the cached balance right away, so every view can make use of it,
67  // so them don't need to waste resources recalculating it.
69 
70  // This timer will be fired repeatedly to update the balance
71  // Since the QTimer::timeout is a private signal, it cannot be used
72  // in the GUIUtil::ExceptionSafeConnect directly.
73  connect(timer, &QTimer::timeout, this, &WalletModel::timerTimeout);
75  timer->start(MODEL_UPDATE_DELAY);
76 }
77 
79 {
80  m_client_model = client_model;
81  if (!m_client_model) timer->stop();
82 }
83 
85 {
86  EncryptionStatus newEncryptionStatus = getEncryptionStatus();
87 
88  if(cachedEncryptionStatus != newEncryptionStatus) {
89  Q_EMIT encryptionStatusChanged();
90  }
91 }
92 
94 {
95  // Avoid recomputing wallet balances unless a TransactionChanged or
96  // BlockTip notification was received.
98 
99  // Try to get balances and return early if locks can't be acquired. This
100  // avoids the GUI from getting stuck on periodical polls if the core is
101  // holding the locks for a longer time - for example, during a wallet
102  // rescan.
103  interfaces::WalletBalances new_balances;
104  uint256 block_hash;
105  if (!m_wallet->tryGetBalances(new_balances, block_hash)) {
106  return;
107  }
108 
111 
112  // Balance and number of transactions might have changed
113  m_cached_last_update_tip = block_hash;
114 
115  checkBalanceChanged(new_balances);
118  }
119 }
120 
122 {
123  if (new_balances.balanceChanged(m_cached_balances)) {
124  m_cached_balances = new_balances;
125  Q_EMIT balanceChanged(new_balances);
126  }
127 }
128 
130 {
131  return m_cached_balances;
132 }
133 
135 {
136  // Balance and number of transactions might have changed
138 }
139 
140 void WalletModel::updateAddressBook(const QString &address, const QString &label,
141  bool isMine, const QString &purpose, int status)
142 {
144  addressTableModel->updateEntry(address, label, isMine, purpose, status);
145 }
146 
147 void WalletModel::updateWatchOnlyFlag(bool fHaveWatchonly)
148 {
149  fHaveWatchOnly = fHaveWatchonly;
150  Q_EMIT notifyWatchonlyChanged(fHaveWatchonly);
151 }
152 
153 bool WalletModel::validateAddress(const QString& address) const
154 {
155  return IsValidDestinationString(address.toStdString());
156 }
157 
159 {
160  CAmount total = 0;
161  bool fSubtractFeeFromAmount = false;
162  QList<SendCoinsRecipient> recipients = transaction.getRecipients();
163  std::vector<CRecipient> vecSend;
164 
165  if(recipients.empty())
166  {
167  return OK;
168  }
169 
170  QSet<QString> setAddress; // Used to detect duplicates
171  int nAddresses = 0;
172 
173  // Pre-check input data for validity
174  for (const SendCoinsRecipient &rcp : recipients)
175  {
176  if (rcp.fSubtractFeeFromAmount)
177  fSubtractFeeFromAmount = true;
178  { // User-entered bitcoin address / amount:
179  if(!validateAddress(rcp.address))
180  {
181  return InvalidAddress;
182  }
183  if(rcp.amount <= 0)
184  {
185  return InvalidAmount;
186  }
187  setAddress.insert(rcp.address);
188  ++nAddresses;
189 
190  CScript scriptPubKey = GetScriptForDestination(DecodeDestination(rcp.address.toStdString()));
191  CRecipient recipient = {scriptPubKey, rcp.amount, rcp.fSubtractFeeFromAmount};
192  vecSend.push_back(recipient);
193 
194  total += rcp.amount;
195  }
196  }
197  if(setAddress.size() != nAddresses)
198  {
199  return DuplicateAddress;
200  }
201 
202  // If no coin was manually selected, use the cached balance
203  // Future: can merge this call with 'createTransaction'.
204  CAmount nBalance = getAvailableBalance(&coinControl);
205 
206  if(total > nBalance)
207  {
208  return AmountExceedsBalance;
209  }
210 
211  try {
212  CAmount nFeeRequired = 0;
213  int nChangePosRet = -1;
214 
215  auto& newTx = transaction.getWtx();
216  const auto& res = m_wallet->createTransaction(vecSend, coinControl, /*sign=*/!wallet().privateKeysDisabled(), nChangePosRet, nFeeRequired);
217  newTx = res ? *res : nullptr;
218  transaction.setTransactionFee(nFeeRequired);
219  if (fSubtractFeeFromAmount && newTx)
220  transaction.reassignAmounts(nChangePosRet);
221 
222  if(!newTx)
223  {
224  if(!fSubtractFeeFromAmount && (total + nFeeRequired) > nBalance)
225  {
227  }
228  Q_EMIT message(tr("Send Coins"), QString::fromStdString(util::ErrorString(res).translated),
231  }
232 
233  // Reject absurdly high fee. (This can never happen because the
234  // wallet never creates transactions with fee greater than
235  // m_default_max_tx_fee. This merely a belt-and-suspenders check).
236  if (nFeeRequired > m_wallet->getDefaultMaxTxFee()) {
237  return AbsurdFee;
238  }
239  } catch (const std::runtime_error& err) {
240  // Something unexpected happened, instruct user to report this bug.
241  Q_EMIT message(tr("Send Coins"), QString::fromStdString(err.what()),
244  }
245 
246  return SendCoinsReturn(OK);
247 }
248 
250 {
251  QByteArray transaction_array; /* store serialized transaction */
252 
253  {
254  std::vector<std::pair<std::string, std::string>> vOrderForm;
255  for (const SendCoinsRecipient &rcp : transaction.getRecipients())
256  {
257  if (!rcp.message.isEmpty()) // Message from normal bitcoin:URI (bitcoin:123...?message=example)
258  vOrderForm.emplace_back("Message", rcp.message.toStdString());
259  }
260 
261  auto& newTx = transaction.getWtx();
262  wallet().commitTransaction(newTx, /*value_map=*/{}, std::move(vOrderForm));
263 
265  ssTx << *newTx;
266  transaction_array.append((const char*)ssTx.data(), ssTx.size());
267  }
268 
269  // Add addresses / update labels that we've sent to the address book,
270  // and emit coinsSent signal for each recipient
271  for (const SendCoinsRecipient &rcp : transaction.getRecipients())
272  {
273  {
274  std::string strAddress = rcp.address.toStdString();
275  CTxDestination dest = DecodeDestination(strAddress);
276  std::string strLabel = rcp.label.toStdString();
277  {
278  // Check if we have a new address or an updated label
279  std::string name;
280  if (!m_wallet->getAddress(
281  dest, &name, /* is_mine= */ nullptr, /* purpose= */ nullptr))
282  {
283  m_wallet->setAddressBook(dest, strLabel, "send");
284  }
285  else if (name != strLabel)
286  {
287  m_wallet->setAddressBook(dest, strLabel, ""); // "" means don't change purpose
288  }
289  }
290  }
291  Q_EMIT coinsSent(this, rcp, transaction_array);
292  }
293 
294  checkBalanceChanged(m_wallet->getBalances()); // update balance immediately, otherwise there could be a short noticeable delay until pollBalanceChanged hits
295 }
296 
298 {
299  return optionsModel;
300 }
301 
303 {
304  return addressTableModel;
305 }
306 
308 {
309  return transactionTableModel;
310 }
311 
313 {
315 }
316 
318 {
319  if(!m_wallet->isCrypted())
320  {
321  // A previous bug allowed for watchonly wallets to be encrypted (encryption keys set, but nothing is actually encrypted).
322  // To avoid misrepresenting the encryption status of such wallets, we only return NoKeys for watchonly wallets that are unencrypted.
323  if (m_wallet->privateKeysDisabled()) {
324  return NoKeys;
325  }
326  return Unencrypted;
327  }
328  else if(m_wallet->isLocked())
329  {
330  return Locked;
331  }
332  else
333  {
334  return Unlocked;
335  }
336 }
337 
339 {
340  return m_wallet->encryptWallet(passphrase);
341 }
342 
343 bool WalletModel::setWalletLocked(bool locked, const SecureString &passPhrase)
344 {
345  if(locked)
346  {
347  // Lock
348  return m_wallet->lock();
349  }
350  else
351  {
352  // Unlock
353  return m_wallet->unlock(passPhrase);
354  }
355 }
356 
357 bool WalletModel::changePassphrase(const SecureString &oldPass, const SecureString &newPass)
358 {
359  m_wallet->lock(); // Make sure wallet is locked before attempting pass change
360  return m_wallet->changeWalletPassphrase(oldPass, newPass);
361 }
362 
363 // Handlers for core signals
364 static void NotifyUnload(WalletModel* walletModel)
365 {
366  qDebug() << "NotifyUnload";
367  bool invoked = QMetaObject::invokeMethod(walletModel, "unload");
368  assert(invoked);
369 }
370 
371 static void NotifyKeyStoreStatusChanged(WalletModel *walletmodel)
372 {
373  qDebug() << "NotifyKeyStoreStatusChanged";
374  bool invoked = QMetaObject::invokeMethod(walletmodel, "updateStatus", Qt::QueuedConnection);
375  assert(invoked);
376 }
377 
378 static void NotifyAddressBookChanged(WalletModel *walletmodel,
379  const CTxDestination &address, const std::string &label, bool isMine,
380  const std::string &purpose, ChangeType status)
381 {
382  QString strAddress = QString::fromStdString(EncodeDestination(address));
383  QString strLabel = QString::fromStdString(label);
384  QString strPurpose = QString::fromStdString(purpose);
385 
386  qDebug() << "NotifyAddressBookChanged: " + strAddress + " " + strLabel + " isMine=" + QString::number(isMine) + " purpose=" + strPurpose + " status=" + QString::number(status);
387  bool invoked = QMetaObject::invokeMethod(walletmodel, "updateAddressBook",
388  Q_ARG(QString, strAddress),
389  Q_ARG(QString, strLabel),
390  Q_ARG(bool, isMine),
391  Q_ARG(QString, strPurpose),
392  Q_ARG(int, status));
393  assert(invoked);
394 }
395 
396 static void NotifyTransactionChanged(WalletModel *walletmodel, const uint256 &hash, ChangeType status)
397 {
398  Q_UNUSED(hash);
399  Q_UNUSED(status);
400  bool invoked = QMetaObject::invokeMethod(walletmodel, "updateTransaction", Qt::QueuedConnection);
401  assert(invoked);
402 }
403 
404 static void ShowProgress(WalletModel *walletmodel, const std::string &title, int nProgress)
405 {
406  // emits signal "showProgress"
407  bool invoked = QMetaObject::invokeMethod(walletmodel, "showProgress", Qt::QueuedConnection,
408  Q_ARG(QString, QString::fromStdString(title)),
409  Q_ARG(int, nProgress));
410  assert(invoked);
411 }
412 
413 static void NotifyWatchonlyChanged(WalletModel *walletmodel, bool fHaveWatchonly)
414 {
415  bool invoked = QMetaObject::invokeMethod(walletmodel, "updateWatchOnlyFlag", Qt::QueuedConnection,
416  Q_ARG(bool, fHaveWatchonly));
417  assert(invoked);
418 }
419 
420 static void NotifyCanGetAddressesChanged(WalletModel* walletmodel)
421 {
422  bool invoked = QMetaObject::invokeMethod(walletmodel, "canGetAddressesChanged");
423  assert(invoked);
424 }
425 
427 {
428  // Connect signals to wallet
429  m_handler_unload = m_wallet->handleUnload(std::bind(&NotifyUnload, this));
430  m_handler_status_changed = m_wallet->handleStatusChanged(std::bind(&NotifyKeyStoreStatusChanged, this));
431  m_handler_address_book_changed = m_wallet->handleAddressBookChanged(std::bind(NotifyAddressBookChanged, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5));
432  m_handler_transaction_changed = m_wallet->handleTransactionChanged(std::bind(NotifyTransactionChanged, this, std::placeholders::_1, std::placeholders::_2));
433  m_handler_show_progress = m_wallet->handleShowProgress(std::bind(ShowProgress, this, std::placeholders::_1, std::placeholders::_2));
434  m_handler_watch_only_changed = m_wallet->handleWatchOnlyChanged(std::bind(NotifyWatchonlyChanged, this, std::placeholders::_1));
435  m_handler_can_get_addrs_changed = m_wallet->handleCanGetAddressesChanged(std::bind(NotifyCanGetAddressesChanged, this));
436 }
437 
439 {
440  // Disconnect signals from wallet
441  m_handler_unload->disconnect();
442  m_handler_status_changed->disconnect();
443  m_handler_address_book_changed->disconnect();
444  m_handler_transaction_changed->disconnect();
445  m_handler_show_progress->disconnect();
446  m_handler_watch_only_changed->disconnect();
447  m_handler_can_get_addrs_changed->disconnect();
448 }
449 
450 // WalletModel::UnlockContext implementation
452 {
453  bool was_locked = getEncryptionStatus() == Locked;
454  if(was_locked)
455  {
456  // Request UI to unlock wallet
457  Q_EMIT requireUnlock();
458  }
459  // If wallet is still locked, unlock was failed or cancelled, mark context as invalid
460  bool valid = getEncryptionStatus() != Locked;
461 
462  return UnlockContext(this, valid, was_locked);
463 }
464 
465 WalletModel::UnlockContext::UnlockContext(WalletModel *_wallet, bool _valid, bool _relock):
466  wallet(_wallet),
467  valid(_valid),
468  relock(_relock)
469 {
470 }
471 
473 {
474  if(valid && relock)
475  {
476  wallet->setWalletLocked(true);
477  }
478 }
479 
480 bool WalletModel::bumpFee(uint256 hash, uint256& new_hash)
481 {
482  CCoinControl coin_control;
483  coin_control.m_signal_bip125_rbf = true;
484  std::vector<bilingual_str> errors;
485  CAmount old_fee;
486  CAmount new_fee;
488  if (!m_wallet->createBumpTransaction(hash, coin_control, errors, old_fee, new_fee, mtx)) {
489  QMessageBox::critical(nullptr, tr("Fee bump error"), tr("Increasing transaction fee failed") + "<br />(" +
490  (errors.size() ? QString::fromStdString(errors[0].translated) : "") +")");
491  return false;
492  }
493 
494  // allow a user based fee verification
495  /*: Asks a user if they would like to manually increase the fee of a transaction that has already been created. */
496  QString questionString = tr("Do you want to increase the fee?");
497  questionString.append("<br />");
498  questionString.append("<table style=\"text-align: left;\">");
499  questionString.append("<tr><td>");
500  questionString.append(tr("Current fee:"));
501  questionString.append("</td><td>");
502  questionString.append(BitcoinUnits::formatHtmlWithUnit(getOptionsModel()->getDisplayUnit(), old_fee));
503  questionString.append("</td></tr><tr><td>");
504  questionString.append(tr("Increase:"));
505  questionString.append("</td><td>");
506  questionString.append(BitcoinUnits::formatHtmlWithUnit(getOptionsModel()->getDisplayUnit(), new_fee - old_fee));
507  questionString.append("</td></tr><tr><td>");
508  questionString.append(tr("New fee:"));
509  questionString.append("</td><td>");
510  questionString.append(BitcoinUnits::formatHtmlWithUnit(getOptionsModel()->getDisplayUnit(), new_fee));
511  questionString.append("</td></tr></table>");
512 
513  // Display warning in the "Confirm fee bump" window if the "Coin Control Features" option is enabled
514  if (getOptionsModel()->getCoinControlFeatures()) {
515  questionString.append("<br><br>");
516  questionString.append(tr("Warning: This may pay the additional fee by reducing change outputs or adding inputs, when necessary. It may add a new change output if one does not already exist. These changes may potentially leak privacy."));
517  }
518 
519  const bool enable_send{!wallet().privateKeysDisabled() || wallet().hasExternalSigner()};
520  const bool always_show_unsigned{getOptionsModel()->getEnablePSBTControls()};
521  auto confirmationDialog = new SendConfirmationDialog(tr("Confirm fee bump"), questionString, "", "", SEND_CONFIRM_DELAY, enable_send, always_show_unsigned, nullptr);
522  confirmationDialog->setAttribute(Qt::WA_DeleteOnClose);
523  // TODO: Replace QDialog::exec() with safer QDialog::show().
524  const auto retval = static_cast<QMessageBox::StandardButton>(confirmationDialog->exec());
525 
526  // cancel sign&broadcast if user doesn't want to bump the fee
527  if (retval != QMessageBox::Yes && retval != QMessageBox::Save) {
528  return false;
529  }
530 
532  if(!ctx.isValid())
533  {
534  return false;
535  }
536 
537  // Short-circuit if we are returning a bumped transaction PSBT to clipboard
538  if (retval == QMessageBox::Save) {
539  // "Create Unsigned" clicked
540  PartiallySignedTransaction psbtx(mtx);
541  bool complete = false;
542  const TransactionError err = wallet().fillPSBT(SIGHASH_ALL, /*sign=*/false, /*bip32derivs=*/true, nullptr, psbtx, complete);
543  if (err != TransactionError::OK || complete) {
544  QMessageBox::critical(nullptr, tr("Fee bump error"), tr("Can't draft transaction."));
545  return false;
546  }
547  // Serialize the PSBT
549  ssTx << psbtx;
550  GUIUtil::setClipboard(EncodeBase64(ssTx.str()).c_str());
551  Q_EMIT message(tr("PSBT copied"), "Copied to clipboard", CClientUIInterface::MSG_INFORMATION);
552  return true;
553  }
554 
555  assert(!m_wallet->privateKeysDisabled() || wallet().hasExternalSigner());
556 
557  // sign bumped transaction
558  if (!m_wallet->signBumpTransaction(mtx)) {
559  QMessageBox::critical(nullptr, tr("Fee bump error"), tr("Can't sign transaction."));
560  return false;
561  }
562  // commit the bumped transaction
563  if(!m_wallet->commitBumpTransaction(hash, std::move(mtx), errors, new_hash)) {
564  QMessageBox::critical(nullptr, tr("Fee bump error"), tr("Could not commit transaction") + "<br />(" +
565  QString::fromStdString(errors[0].translated)+")");
566  return false;
567  }
568  return true;
569 }
570 
571 bool WalletModel::displayAddress(std::string sAddress) const
572 {
573  CTxDestination dest = DecodeDestination(sAddress);
574  bool res = false;
575  try {
576  res = m_wallet->displayAddress(dest);
577  } catch (const std::runtime_error& e) {
578  QMessageBox::critical(nullptr, tr("Can't display address"), e.what());
579  }
580  return res;
581 }
582 
584 {
585  return !gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET);
586 }
587 
589 {
590  return QString::fromStdString(m_wallet->getWalletName());
591 }
592 
594 {
595  const QString name = getWalletName();
596  return name.isEmpty() ? "["+tr("default wallet")+"]" : name;
597 }
598 
600 {
601  return m_node.walletLoader().getWallets().size() > 1;
602 }
603 
604 void WalletModel::refresh(bool pk_hash_only)
605 {
606  addressTableModel = new AddressTableModel(this, pk_hash_only);
607 }
608 
610 {
612 }
613 
615 {
616  return control && control->HasSelected() ? wallet().getAvailableBalance(*control) : getCachedBalance().balance;
617 }
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
node::NodeContext m_node
Definition: bitcoin-gui.cpp:37
Qt model of the address book in the core.
void updateEntry(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: system.cpp:615
static QString formatHtmlWithUnit(Unit unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD)
Format as HTML string (with unit)
@ MSG_INFORMATION
Predefined combinations for certain default usage cases.
Definition: interface_ui.h:65
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:411
Model for Bitcoin network client.
Definition: clientmodel.h:54
uint256 getBestBlockHash() EXCLUSIVE_LOCKS_REQUIRED(!m_cached_tip_mutex)
size_type size() const
Definition: streams.h:220
value_type * data()
Definition: streams.h:227
std::string str() const
Definition: streams.h:207
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:41
bool getEnablePSBTControls() const
Definition: optionsmodel.h:99
Model for list of recently generated payment requests / bitcoin: URIs.
UI model for the transaction table of a wallet.
UnlockContext(WalletModel *wallet, bool valid, bool relock)
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:53
OptionsModel * optionsModel
Definition: walletmodel.h:180
AddressTableModel * addressTableModel
Definition: walletmodel.h:182
RecentRequestsTableModel * getRecentRequestsTableModel() const
EncryptionStatus cachedEncryptionStatus
Definition: walletmodel.h:188
void refresh(bool pk_hash_only=false)
uint256 m_cached_last_update_tip
Definition: walletmodel.h:192
ClientModel * m_client_model
Definition: walletmodel.h:172
std::unique_ptr< interfaces::Handler > m_handler_watch_only_changed
Definition: walletmodel.h:170
interfaces::Node & m_node
Definition: walletmodel.h:173
std::unique_ptr< interfaces::Handler > m_handler_transaction_changed
Definition: walletmodel.h:168
void startPollBalance()
Definition: walletmodel.cpp:64
void pollBalanceChanged()
Definition: walletmodel.cpp:93
AddressTableModel * getAddressTableModel() const
RecentRequestsTableModel * recentRequestsTableModel
Definition: walletmodel.h:184
SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const wallet::CCoinControl &coinControl)
bool displayAddress(std::string sAddress) const
TransactionTableModel * transactionTableModel
Definition: walletmodel.h:183
bool setWalletEncrypted(const SecureString &passphrase)
void notifyWatchonlyChanged(bool fHaveWatchonly)
bool changePassphrase(const SecureString &oldPass, const SecureString &newPass)
bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString())
void message(const QString &title, const QString &message, unsigned int style)
bool validateAddress(const QString &address) const
void sendCoins(WalletModelTransaction &transaction)
void setClientModel(ClientModel *client_model)
Definition: walletmodel.cpp:78
void updateStatus()
Definition: walletmodel.cpp:84
CAmount getAvailableBalance(const wallet::CCoinControl *control)
bool isMultiwallet() const
void timerTimeout()
std::unique_ptr< interfaces::Handler > m_handler_can_get_addrs_changed
Definition: walletmodel.h:171
std::unique_ptr< interfaces::Handler > m_handler_unload
Definition: walletmodel.h:165
interfaces::Wallet & wallet() const
Definition: walletmodel.h:143
EncryptionStatus getEncryptionStatus() const
TransactionTableModel * getTransactionTableModel() const
std::unique_ptr< interfaces::Handler > m_handler_status_changed
Definition: walletmodel.h:166
interfaces::WalletBalances m_cached_balances
Definition: walletmodel.h:187
bool fForceCheckBalanceChanged
Definition: walletmodel.h:176
void coinsSent(WalletModel *wallet, SendCoinsRecipient recipient, QByteArray transaction)
QString getDisplayName() const
OptionsModel * getOptionsModel() const
bool bumpFee(uint256 hash, uint256 &new_hash)
void checkBalanceChanged(const interfaces::WalletBalances &new_balances)
void unsubscribeFromCoreSignals()
void requireUnlock()
void updateTransaction()
void updateAddressBook(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
uint256 getLastBlockProcessed() const
QTimer * timer
Definition: walletmodel.h:189
bool fHaveWatchOnly
Definition: walletmodel.h:175
WalletModel(std::unique_ptr< interfaces::Wallet > wallet, ClientModel &client_model, const PlatformStyle *platformStyle, QObject *parent=nullptr)
Definition: walletmodel.cpp:43
void updateWatchOnlyFlag(bool fHaveWatchonly)
std::unique_ptr< interfaces::Handler > m_handler_address_book_changed
Definition: walletmodel.h:167
void encryptionStatusChanged()
std::unique_ptr< interfaces::Wallet > m_wallet
Definition: walletmodel.h:164
UnlockContext requestUnlock()
void balanceChanged(const interfaces::WalletBalances &balances)
static bool isWalletEnabled()
interfaces::WalletBalances getCachedBalance() const
QString getWalletName() const
std::unique_ptr< interfaces::Handler > m_handler_show_progress
Definition: walletmodel.h:169
@ AmountWithFeeExceedsBalance
Definition: walletmodel.h:66
@ TransactionCreationFailed
Definition: walletmodel.h:68
@ AmountExceedsBalance
Definition: walletmodel.h:65
@ DuplicateAddress
Definition: walletmodel.h:67
void subscribeToCoreSignals()
Data model for a walletmodel transaction.
void setTransactionFee(const CAmount &newFee)
void reassignAmounts(int nChangePosRet)
QList< SendCoinsRecipient > getRecipients() const
virtual WalletLoader & walletLoader()=0
Get wallet loader.
virtual TransactionError fillPSBT(int sighash_type, bool sign, bool bip32derivs, size_t *n_signed, PartiallySignedTransaction &psbtx, bool &complete)=0
Fill PSBT.
virtual CAmount getAvailableBalance(const wallet::CCoinControl &coin_control)=0
Get available balance.
virtual bool hasExternalSigner()=0
virtual void commitTransaction(CTransactionRef tx, WalletValueMap value_map, WalletOrderForm order_form)=0
Commit transaction.
virtual bool privateKeysDisabled()=0
virtual std::vector< std::unique_ptr< Wallet > > getWallets()=0
Return interfaces for accessing wallets (if any).
void push_back(const T &value)
Definition: prevector.h:431
256-bit opaque blob.
Definition: uint256.h:105
Coin Control Features.
Definition: coincontrol.h:30
std::optional< bool > m_signal_bip125_rbf
Override the wallet's m_signal_rbf if set.
Definition: coincontrol.h:50
bool HasSelected() const
Definition: coincontrol.h:66
TransactionError
Definition: error.h:22
static constexpr auto MODEL_UPDATE_DELAY
Definition: guiconstants.h:14
@ SIGHASH_ALL
Definition: interpreter.h:28
bool IsValidDestinationString(const std::string &str, const CChainParams &params)
Definition: key_io.cpp:292
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg, std::vector< int > *error_locations)
Definition: key_io.cpp:281
std::string EncodeDestination(const CTxDestination &dest)
Definition: key_io.cpp:276
auto ExceptionSafeConnect(Sender sender, Signal signal, Receiver receiver, Slot method, Qt::ConnectionType type=Qt::AutoConnection)
A drop-in replacement of QObject::connect function (see: https://doc.qt.io/qt-5/qobject....
Definition: guiutil.h:391
void setClipboard(const QString &str)
Definition: guiutil.cpp:653
Definition: init.h:25
bilingual_str ErrorString(const Result< T > &result)
Definition: result.h:78
Definition: node.h:39
static const bool DEFAULT_DISABLE_WALLET
Definition: wallet.h:108
const char * name
Definition: rest.cpp:46
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: secure.h:60
#define SEND_CONFIRM_DELAY
@ SER_NETWORK
Definition: serialize.h:131
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
Definition: standard.cpp:334
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:149
A mutable version of CTransaction.
Definition: transaction.h:380
A version of CTransaction with the PSBT format.
Definition: psbt.h:947
Collection of wallet balances.
Definition: wallet.h:366
bool balanceChanged(const WalletBalances &prev) const
Definition: wallet.h:375
ChangeType
General change type (added, updated, removed).
Definition: ui_change_type.h:9
std::string EncodeBase64(Span< const unsigned char > input)
ArgsManager gArgs
Definition: system.cpp:73
assert(!tx.IsCoinBase())
static const int PROTOCOL_VERSION
network protocol versioning
Definition: version.h:12
std::shared_ptr< CWallet > m_wallet
Definition: interfaces.cpp:522
static void NotifyUnload(WalletModel *walletModel)
static void NotifyWatchonlyChanged(WalletModel *walletmodel, bool fHaveWatchonly)
static void NotifyCanGetAddressesChanged(WalletModel *walletmodel)
static void NotifyAddressBookChanged(WalletModel *walletmodel, const CTxDestination &address, const std::string &label, bool isMine, const std::string &purpose, ChangeType status)
static void ShowProgress(WalletModel *walletmodel, const std::string &title, int nProgress)
static void NotifyKeyStoreStatusChanged(WalletModel *walletmodel)
static void NotifyTransactionChanged(WalletModel *walletmodel, const uint256 &hash, ChangeType status)