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