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