Dogecoin Core  1.14.2
P2P Digital Currency
walletmodel.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2016 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 "walletmodel.h"
6 
7 #include "addresstablemodel.h"
8 #include "consensus/validation.h"
9 #include "guiconstants.h"
10 #include "guiutil.h"
11 #include "paymentserver.h"
13 #include "transactiontablemodel.h"
14 
15 #include "base58.h"
16 #include "keystore.h"
17 #include "validation.h"
18 #include "net.h" // for g_connman
19 #include "sync.h"
20 #include "ui_interface.h"
21 #include "util.h" // for GetBoolArg
22 #include "wallet/wallet.h"
23 #include "wallet/walletdb.h" // for BackupWallet
24 
25 #include <stdint.h>
26 
27 #include <QDebug>
28 #include <QSet>
29 #include <QTimer>
30 
31 #include <boost/bind/bind.hpp>
32 #include <boost/foreach.hpp>
33 
34 WalletModel::WalletModel(const PlatformStyle *platformStyle, CWallet *_wallet, OptionsModel *_optionsModel, QObject *parent) :
35  QObject(parent), wallet(_wallet), optionsModel(_optionsModel), addressTableModel(0),
36  transactionTableModel(0),
37  recentRequestsTableModel(0),
38  cachedBalance(0), cachedUnconfirmedBalance(0), cachedImmatureBalance(0),
39  cachedEncryptionStatus(Unencrypted),
40  cachedNumBlocks(0)
41 {
44 
46  transactionTableModel = new TransactionTableModel(platformStyle, wallet, this);
48 
49  // This timer will be fired repeatedly to update the balance
50  pollTimer = new QTimer(this);
51  connect(pollTimer, SIGNAL(timeout()), this, SLOT(pollBalanceChanged()));
52  pollTimer->start(MODEL_UPDATE_DELAY);
53 
55 }
56 
58 {
60 }
61 
62 CAmount WalletModel::getBalance(const CCoinControl *coinControl) const
63 {
64  if (coinControl)
65  {
66  CAmount nBalance = 0;
67  std::vector<COutput> vCoins;
68  wallet->AvailableCoins(vCoins, true, coinControl);
69  BOOST_FOREACH(const COutput& out, vCoins)
70  if(out.fSpendable)
71  nBalance += out.tx->tx->vout[out.i].nValue;
72 
73  return nBalance;
74  }
75 
76  return wallet->GetBalance();
77 }
78 
80 {
81  return wallet->GetUnconfirmedBalance();
82 }
83 
85 {
86  return wallet->GetImmatureBalance();
87 }
88 
90 {
91  return fHaveWatchOnly;
92 }
93 
95 {
96  return wallet->GetWatchOnlyBalance();
97 }
98 
100 {
102 }
103 
105 {
107 }
108 
110 {
111  EncryptionStatus newEncryptionStatus = getEncryptionStatus();
112 
113  if(cachedEncryptionStatus != newEncryptionStatus)
114  Q_EMIT encryptionStatusChanged(newEncryptionStatus);
115 }
116 
118 {
119  // Get required locks upfront. This avoids the GUI from getting stuck on
120  // periodical polls if the core is holding the locks for a longer time -
121  // for example, during a wallet rescan.
122  TRY_LOCK(cs_main, lockMain);
123  if(!lockMain)
124  return;
125  TRY_LOCK(wallet->cs_wallet, lockWallet);
126  if(!lockWallet)
127  return;
128 
130  {
132 
133  // Balance and number of transactions might have changed
135 
139  }
140 }
141 
143 {
144  CAmount newBalance = getBalance();
145  CAmount newUnconfirmedBalance = getUnconfirmedBalance();
146  CAmount newImmatureBalance = getImmatureBalance();
147  CAmount newWatchOnlyBalance = 0;
148  CAmount newWatchUnconfBalance = 0;
149  CAmount newWatchImmatureBalance = 0;
150  if (haveWatchOnly())
151  {
152  newWatchOnlyBalance = getWatchBalance();
153  newWatchUnconfBalance = getWatchUnconfirmedBalance();
154  newWatchImmatureBalance = getWatchImmatureBalance();
155  }
156 
157  if(cachedBalance != newBalance || cachedUnconfirmedBalance != newUnconfirmedBalance || cachedImmatureBalance != newImmatureBalance ||
158  cachedWatchOnlyBalance != newWatchOnlyBalance || cachedWatchUnconfBalance != newWatchUnconfBalance || cachedWatchImmatureBalance != newWatchImmatureBalance)
159  {
160  cachedBalance = newBalance;
161  cachedUnconfirmedBalance = newUnconfirmedBalance;
162  cachedImmatureBalance = newImmatureBalance;
163  cachedWatchOnlyBalance = newWatchOnlyBalance;
164  cachedWatchUnconfBalance = newWatchUnconfBalance;
165  cachedWatchImmatureBalance = newWatchImmatureBalance;
166  Q_EMIT balanceChanged(newBalance, newUnconfirmedBalance, newImmatureBalance,
167  newWatchOnlyBalance, newWatchUnconfBalance, newWatchImmatureBalance);
168  }
169 }
170 
172 {
173  // Balance and number of transactions might have changed
175 }
176 
177 void WalletModel::updateAddressBook(const QString &address, const QString &label,
178  bool isMine, const QString &purpose, int status)
179 {
181  addressTableModel->updateEntry(address, label, isMine, purpose, status);
182 }
183 
184 void WalletModel::updateWatchOnlyFlag(bool fHaveWatchonly)
185 {
186  fHaveWatchOnly = fHaveWatchonly;
187  Q_EMIT notifyWatchonlyChanged(fHaveWatchonly);
188 }
189 
190 bool WalletModel::validateAddress(const QString &address)
191 {
192  CBitcoinAddress addressParsed(address.toStdString());
193  return addressParsed.IsValid();
194 }
195 
197 {
198  CAmount total = 0;
199  bool fSubtractFeeFromAmount = false;
200  QList<SendCoinsRecipient> recipients = transaction.getRecipients();
201  std::vector<CRecipient> vecSend;
202 
203  if(recipients.empty())
204  {
205  return OK;
206  }
207 
208  QSet<QString> setAddress; // Used to detect duplicates
209  int nAddresses = 0;
210 
211  // Pre-check input data for validity
212  Q_FOREACH(const SendCoinsRecipient &rcp, recipients)
213  {
214  if (rcp.fSubtractFeeFromAmount)
215  fSubtractFeeFromAmount = true;
216 
217  if (rcp.paymentRequest.IsInitialized())
218  { // PaymentRequest...
219  CAmount subtotal = 0;
220  const payments::PaymentDetails& details = rcp.paymentRequest.getDetails();
221  for (int i = 0; i < details.outputs_size(); i++)
222  {
223  const payments::Output& out = details.outputs(i);
224  if (out.amount() <= 0) continue;
225  subtotal += out.amount();
226  const unsigned char* scriptStr = (const unsigned char*)out.script().data();
227  CScript scriptPubKey(scriptStr, scriptStr+out.script().size());
228  CAmount nAmount = out.amount();
229  CRecipient recipient = {scriptPubKey, nAmount, rcp.fSubtractFeeFromAmount};
230  vecSend.push_back(recipient);
231  }
232  if (subtotal <= 0)
233  {
234  return InvalidAmount;
235  }
236  total += subtotal;
237  }
238  else
239  { // User-entered bitcoin address / amount:
240  if(!validateAddress(rcp.address))
241  {
242  return InvalidAddress;
243  }
244  if(rcp.amount <= 0)
245  {
246  return InvalidAmount;
247  }
248  setAddress.insert(rcp.address);
249  ++nAddresses;
250 
251  CScript scriptPubKey = GetScriptForDestination(CBitcoinAddress(rcp.address.toStdString()).Get());
252  CRecipient recipient = {scriptPubKey, rcp.amount, rcp.fSubtractFeeFromAmount};
253  vecSend.push_back(recipient);
254 
255  total += rcp.amount;
256  }
257  }
258  if(setAddress.size() != nAddresses)
259  {
260  return DuplicateAddress;
261  }
262 
263  CAmount nBalance = getBalance(coinControl);
264 
265  if(total > nBalance)
266  {
267  return AmountExceedsBalance;
268  }
269 
270  {
272 
273  transaction.newPossibleKeyChange(wallet);
274 
275  CAmount nFeeRequired = 0;
276  int nChangePosRet = -1;
277  std::string strFailReason;
278 
279  CWalletTx *newTx = transaction.getTransaction();
280  CReserveKey *keyChange = transaction.getPossibleKeyChange();
281  bool fCreated = wallet->CreateTransaction(vecSend, *newTx, *keyChange, nFeeRequired, nChangePosRet, strFailReason, coinControl);
282  transaction.setTransactionFee(nFeeRequired);
283  if (fSubtractFeeFromAmount && fCreated)
284  transaction.reassignAmounts(nChangePosRet);
285 
286  if(!fCreated)
287  {
288  if(!fSubtractFeeFromAmount && (total + nFeeRequired) > nBalance)
289  {
291  }
292  Q_EMIT message(tr("Send Coins"), QString::fromStdString(strFailReason),
295  }
296 
297  // reject absurdly high fee. (This can never happen because the
298  // wallet caps the fee at maxTxFee. This merely serves as a
299  // belt-and-suspenders check)
300  if (nFeeRequired > maxTxFee)
301  return AbsurdFee;
302  }
303 
304  return SendCoinsReturn(OK);
305 }
306 
308 {
309  QByteArray transaction_array; /* store serialized transaction */
310 
311  {
313  CWalletTx *newTx = transaction.getTransaction();
314 
315  Q_FOREACH(const SendCoinsRecipient &rcp, transaction.getRecipients())
316  {
317  if (rcp.paymentRequest.IsInitialized())
318  {
319  // Make sure any payment requests involved are still valid.
321  return PaymentRequestExpired;
322  }
323 
324  // Store PaymentRequests in wtx.vOrderForm in wallet.
325  std::string key("PaymentRequest");
326  std::string value;
327  rcp.paymentRequest.SerializeToString(&value);
328  newTx->vOrderForm.push_back(make_pair(key, value));
329  }
330  else if (!rcp.message.isEmpty()) // Message from normal bitcoin:URI (bitcoin:123...?message=example)
331  newTx->vOrderForm.push_back(make_pair("Message", rcp.message.toStdString()));
332  }
333 
334  CReserveKey *keyChange = transaction.getPossibleKeyChange();
335  CValidationState state;
336  if(!wallet->CommitTransaction(*newTx, *keyChange, g_connman.get(), state))
337  return SendCoinsReturn(TransactionCommitFailed, QString::fromStdString(state.GetRejectReason()));
338 
339  CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
340  ssTx << *newTx->tx;
341  transaction_array.append(&(ssTx[0]), ssTx.size());
342  }
343 
344  // Add addresses / update labels that we've sent to to the address book,
345  // and emit coinsSent signal for each recipient
346  Q_FOREACH(const SendCoinsRecipient &rcp, transaction.getRecipients())
347  {
348  // Don't touch the address book when we have a payment request
349  if (!rcp.paymentRequest.IsInitialized())
350  {
351  std::string strAddress = rcp.address.toStdString();
352  CTxDestination dest = CBitcoinAddress(strAddress).Get();
353  std::string strLabel = rcp.label.toStdString();
354  {
356 
357  std::map<CTxDestination, CAddressBookData>::iterator mi = wallet->mapAddressBook.find(dest);
358 
359  // Check if we have a new address or an updated label
360  if (mi == wallet->mapAddressBook.end())
361  {
362  wallet->SetAddressBook(dest, strLabel, "send");
363  }
364  else if (mi->second.name != strLabel)
365  {
366  wallet->SetAddressBook(dest, strLabel, ""); // "" means don't change purpose
367  }
368  }
369  }
370  Q_EMIT coinsSent(wallet, rcp, transaction_array);
371  }
372  checkBalanceChanged(); // update balance immediately, otherwise there could be a short noticeable delay until pollBalanceChanged hits
373 
374  return SendCoinsReturn(OK);
375 }
376 
378 {
379  return optionsModel;
380 }
381 
383 {
384  return addressTableModel;
385 }
386 
388 {
389  return transactionTableModel;
390 }
391 
393 {
395 }
396 
398 {
399  if(!wallet->IsCrypted())
400  {
401  return Unencrypted;
402  }
403  else if(wallet->IsLocked())
404  {
405  return Locked;
406  }
407  else
408  {
409  return Unlocked;
410  }
411 }
412 
413 bool WalletModel::setWalletEncrypted(bool encrypted, const SecureString &passphrase)
414 {
415  if(encrypted)
416  {
417  // Encrypt
418  return wallet->EncryptWallet(passphrase);
419  }
420  else
421  {
422  // Decrypt -- TODO; not supported yet
423  return false;
424  }
425 }
426 
427 bool WalletModel::setWalletLocked(bool locked, const SecureString &passPhrase)
428 {
429  if(locked)
430  {
431  // Lock
432  return wallet->Lock();
433  }
434  else
435  {
436  // Unlock
437  return wallet->Unlock(passPhrase);
438  }
439 }
440 
441 bool WalletModel::changePassphrase(const SecureString &oldPass, const SecureString &newPass)
442 {
443  bool retval;
444  {
446  wallet->Lock(); // Make sure wallet is locked before attempting pass change
447  retval = wallet->ChangeWalletPassphrase(oldPass, newPass);
448  }
449  return retval;
450 }
451 
452 bool WalletModel::backupWallet(const QString &filename)
453 {
454  return wallet->BackupWallet(filename.toLocal8Bit().data());
455 }
456 
457 // Handlers for core signals
458 static void NotifyKeyStoreStatusChanged(WalletModel *walletmodel, CCryptoKeyStore *wallet)
459 {
460  qDebug() << "NotifyKeyStoreStatusChanged";
461  QMetaObject::invokeMethod(walletmodel, "updateStatus", Qt::QueuedConnection);
462 }
463 
464 static void NotifyAddressBookChanged(WalletModel *walletmodel, CWallet *wallet,
465  const CTxDestination &address, const std::string &label, bool isMine,
466  const std::string &purpose, ChangeType status)
467 {
468  QString strAddress = QString::fromStdString(CBitcoinAddress(address).ToString());
469  QString strLabel = QString::fromStdString(label);
470  QString strPurpose = QString::fromStdString(purpose);
471 
472  qDebug() << "NotifyAddressBookChanged: " + strAddress + " " + strLabel + " isMine=" + QString::number(isMine) + " purpose=" + strPurpose + " status=" + QString::number(status);
473  QMetaObject::invokeMethod(walletmodel, "updateAddressBook", Qt::QueuedConnection,
474  Q_ARG(QString, strAddress),
475  Q_ARG(QString, strLabel),
476  Q_ARG(bool, isMine),
477  Q_ARG(QString, strPurpose),
478  Q_ARG(int, status));
479 }
480 
481 static void NotifyTransactionChanged(WalletModel *walletmodel, CWallet *wallet, const uint256 &hash, ChangeType status)
482 {
483  Q_UNUSED(wallet);
484  Q_UNUSED(hash);
485  Q_UNUSED(status);
486  QMetaObject::invokeMethod(walletmodel, "updateTransaction", Qt::QueuedConnection);
487 }
488 
489 static void ShowProgress(WalletModel *walletmodel, const std::string &title, int nProgress)
490 {
491  // emits signal "showProgress"
492  QMetaObject::invokeMethod(walletmodel, "showProgress", Qt::QueuedConnection,
493  Q_ARG(QString, QString::fromStdString(title)),
494  Q_ARG(int, nProgress));
495 }
496 
497 static void NotifyWatchonlyChanged(WalletModel *walletmodel, bool fHaveWatchonly)
498 {
499  QMetaObject::invokeMethod(walletmodel, "updateWatchOnlyFlag", Qt::QueuedConnection,
500  Q_ARG(bool, fHaveWatchonly));
501 }
502 
504 {
505  // Connect signals to wallet
506  wallet->NotifyStatusChanged.connect(boost::bind(&NotifyKeyStoreStatusChanged, this,
507  boost::placeholders::_1));
508  wallet->NotifyAddressBookChanged.connect(boost::bind(NotifyAddressBookChanged, this,
509  boost::placeholders::_1,
510  boost::placeholders::_2,
511  boost::placeholders::_3,
512  boost::placeholders::_4,
513  boost::placeholders::_5,
514  boost::placeholders::_6));
515  wallet->NotifyTransactionChanged.connect(boost::bind(NotifyTransactionChanged, this,
516  boost::placeholders::_1,
517  boost::placeholders::_2,
518  boost::placeholders::_3));
519  wallet->ShowProgress.connect(boost::bind(ShowProgress, this, boost::placeholders::_1,
520  boost::placeholders::_2));
521  wallet->NotifyWatchonlyChanged.connect(boost::bind(NotifyWatchonlyChanged, this,
522  boost::placeholders::_1));
523 }
524 
526 {
527  // Disconnect signals from wallet
528  wallet->NotifyStatusChanged.disconnect(boost::bind(&NotifyKeyStoreStatusChanged, this,
529  boost::placeholders::_1));
530  wallet->NotifyAddressBookChanged.disconnect(boost::bind(NotifyAddressBookChanged, this,
531  boost::placeholders::_1,
532  boost::placeholders::_2,
533  boost::placeholders::_3,
534  boost::placeholders::_4,
535  boost::placeholders::_5,
536  boost::placeholders::_6));
537  wallet->NotifyTransactionChanged.disconnect(boost::bind(NotifyTransactionChanged, this,
538  boost::placeholders::_1,
539  boost::placeholders::_2,
540  boost::placeholders::_3));
541  wallet->ShowProgress.disconnect(boost::bind(ShowProgress, this,
542  boost::placeholders::_1,
543  boost::placeholders::_2));
544  wallet->NotifyWatchonlyChanged.disconnect(boost::bind(NotifyWatchonlyChanged, this,
545  boost::placeholders::_1));
546 }
547 
548 // WalletModel::UnlockContext implementation
550 {
551  bool was_locked = getEncryptionStatus() == Locked;
552  if(was_locked)
553  {
554  // Request UI to unlock wallet
555  Q_EMIT requireUnlock();
556  }
557  // If wallet is still locked, unlock was failed or cancelled, mark context as invalid
558  bool valid = getEncryptionStatus() != Locked;
559 
560  return UnlockContext(this, valid, was_locked);
561 }
562 
563 WalletModel::UnlockContext::UnlockContext(WalletModel *_wallet, bool _valid, bool _relock):
564  wallet(_wallet),
565  valid(_valid),
566  relock(_relock)
567 {
568 }
569 
571 {
572  if(valid && relock)
573  {
574  wallet->setWalletLocked(true);
575  }
576 }
577 
579 {
580  // Transfer context; old object no longer relocks wallet
581  *this = rhs;
582  rhs.relock = false;
583 }
584 
585 bool WalletModel::getPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const
586 {
587  return wallet->GetPubKey(address, vchPubKeyOut);
588 }
589 
590 bool WalletModel::havePrivKey(const CKeyID &address) const
591 {
592  return wallet->HaveKey(address);
593 }
594 
595 bool WalletModel::getPrivKey(const CKeyID &address, CKey& vchPrivKeyOut) const
596 {
597  return wallet->GetKey(address, vchPrivKeyOut);
598 }
599 
600 // returns a list of COutputs from COutPoints
601 void WalletModel::getOutputs(const std::vector<COutPoint>& vOutpoints, std::vector<COutput>& vOutputs)
602 {
604  BOOST_FOREACH(const COutPoint& outpoint, vOutpoints)
605  {
606  if (!wallet->mapWallet.count(outpoint.hash)) continue;
607  int nDepth = wallet->mapWallet[outpoint.hash].GetDepthInMainChain();
608  if (nDepth < 0) continue;
609  COutput out(&wallet->mapWallet[outpoint.hash], outpoint.n, nDepth, true, true);
610  vOutputs.push_back(out);
611  }
612 }
613 
614 bool WalletModel::isSpent(const COutPoint& outpoint) const
615 {
617  return wallet->IsSpent(outpoint.hash, outpoint.n);
618 }
619 
620 // AvailableCoins + LockedCoins grouped by wallet address (put change in one group with wallet address)
621 void WalletModel::listCoins(std::map<QString, std::vector<COutput> >& mapCoins) const
622 {
623  std::vector<COutput> vCoins;
624  wallet->AvailableCoins(vCoins);
625 
626  LOCK2(cs_main, wallet->cs_wallet); // ListLockedCoins, mapWallet
627  std::vector<COutPoint> vLockedCoins;
628  wallet->ListLockedCoins(vLockedCoins);
629 
630  // add locked coins
631  BOOST_FOREACH(const COutPoint& outpoint, vLockedCoins)
632  {
633  if (!wallet->mapWallet.count(outpoint.hash)) continue;
634  int nDepth = wallet->mapWallet[outpoint.hash].GetDepthInMainChain();
635  if (nDepth < 0) continue;
636  COutput out(&wallet->mapWallet[outpoint.hash], outpoint.n, nDepth, true, true);
637  if (outpoint.n < out.tx->tx->vout.size() && wallet->IsMine(out.tx->tx->vout[outpoint.n]) == ISMINE_SPENDABLE)
638  vCoins.push_back(out);
639  }
640 
641  BOOST_FOREACH(const COutput& out, vCoins)
642  {
643  COutput cout = out;
644 
645  while (wallet->IsChange(cout.tx->tx->vout[cout.i]) && cout.tx->tx->vin.size() > 0 && wallet->IsMine(cout.tx->tx->vin[0]))
646  {
647  if (!wallet->mapWallet.count(cout.tx->tx->vin[0].prevout.hash)) break;
648  cout = COutput(&wallet->mapWallet[cout.tx->tx->vin[0].prevout.hash], cout.tx->tx->vin[0].prevout.n, 0, true, true);
649  }
650 
651  CTxDestination address;
652  if(!out.fSpendable || !ExtractDestination(cout.tx->tx->vout[cout.i].scriptPubKey, address))
653  continue;
654  mapCoins[QString::fromStdString(CBitcoinAddress(address).ToString())].push_back(out);
655  }
656 }
657 
658 bool WalletModel::isLockedCoin(uint256 hash, unsigned int n) const
659 {
661  return wallet->IsLockedCoin(hash, n);
662 }
663 
665 {
667  wallet->LockCoin(output);
668 }
669 
671 {
673  wallet->UnlockCoin(output);
674 }
675 
676 void WalletModel::listLockedCoins(std::vector<COutPoint>& vOutpts)
677 {
679  wallet->ListLockedCoins(vOutpts);
680 }
681 
682 void WalletModel::loadReceiveRequests(std::vector<std::string>& vReceiveRequests)
683 {
685  BOOST_FOREACH(const PAIRTYPE(CTxDestination, CAddressBookData)& item, wallet->mapAddressBook)
686  BOOST_FOREACH(const PAIRTYPE(std::string, std::string)& item2, item.second.destdata)
687  if (item2.first.size() > 2 && item2.first.substr(0,2) == "rr") // receive request
688  vReceiveRequests.push_back(item2.second);
689 }
690 
691 bool WalletModel::saveReceiveRequest(const std::string &sAddress, const int64_t nId, const std::string &sRequest)
692 {
693  CTxDestination dest = CBitcoinAddress(sAddress).Get();
694 
695  std::stringstream ss;
696  ss << nId;
697  std::string key = "rr" + ss.str(); // "rr" prefix = "receive request" in destdata
698 
700  if (sRequest.empty())
701  return wallet->EraseDestData(dest, key);
702  else
703  return wallet->AddDestData(dest, key, sRequest);
704 }
705 
707 {
709  const CWalletTx *wtx = wallet->GetWalletTx(hash);
710  if (!wtx || wtx->isAbandoned() || wtx->GetDepthInMainChain() > 0 || wtx->InMempool())
711  return false;
712  return true;
713 }
714 
716 {
718  return wallet->AbandonTransaction(hash);
719 }
720 
722 {
723  return !GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET);
724 }
725 
727 {
728  return wallet->IsHDEnabled();
729 }
730 
732 {
733  return nTxConfirmTarget;
734 }
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:15
Qt model of the address book in the core.
void updateEntry(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
Address book data.
Definition: wallet.h:123
StringMap destdata
Definition: wallet.h:134
virtual bool HaveWatchOnly(const CScript &dest) const
Definition: keystore.cpp:105
base58-encoded Bitcoin addresses.
Definition: base58.h:104
CTxDestination Get() const
Definition: base58.cpp:260
bool IsValid() const
Definition: base58.cpp:247
int Height() const
Return the maximal height in the chain.
Definition: chain.h:474
Coin Control Features.
Definition: coincontrol.h:12
Keystore which keeps the private keys encrypted.
Definition: crypter.h:116
bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
Definition: crypter.cpp:261
boost::signals2::signal< void(CCryptoKeyStore *wallet)> NotifyStatusChanged
Wallet status (encrypted, locked) changed.
Definition: crypter.h:195
bool IsLocked() const
Definition: crypter.h:147
bool HaveKey(const CKeyID &address) const
Check whether a key corresponding to a given address is present in the store.
Definition: crypter.h:163
bool IsCrypted() const
Definition: crypter.h:142
bool GetKey(const CKeyID &address, CKey &keyOut) const
Definition: crypter.cpp:243
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:147
size_type size() const
Definition: streams.h:237
An encapsulated private key.
Definition: key.h:36
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:30
int GetDepthInMainChain(const CBlockIndex *&pindexRet) const
Return depth of transaction in blockchain: <0 : conflicts with a transaction this deep in the blockch...
Definition: auxpow.cpp:45
bool isAbandoned() const
Definition: auxpow.h:110
CTransactionRef tx
Definition: auxpow.h:37
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:20
uint32_t n
Definition: transaction.h:23
uint256 hash
Definition: transaction.h:22
bool fSpendable
Definition: wallet.h:364
const CWalletTx * tx
Definition: wallet.h:361
int i
Definition: wallet.h:362
An encapsulated public key.
Definition: pubkey.h:40
A key allocated from the key pool.
Definition: wallet.h:928
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:377
Capture information about block/transaction validation.
Definition: validation.h:22
std::string GetRejectReason() const
Definition: validation.h:84
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,...
Definition: wallet.h:493
std::map< uint256, CWalletTx > mapWallet
Definition: wallet.h:614
std::map< CTxDestination, CAddressBookData > mapAddressBook
Definition: wallet.h:624
CCriticalSection cs_wallet
Definition: wallet.h:559
boost::signals2::signal< void(bool fHaveWatchOnly)> NotifyWatchonlyChanged
Watch-only address added.
Definition: wallet.h:881
bool BackupWallet(const std::string &strDest)
Definition: wallet.cpp:3920
boost::signals2::signal< void(CWallet *wallet, const CTxDestination &address, const std::string &label, bool isMine, const std::string &purpose, ChangeType status)> NotifyAddressBookChanged
Address book entry changed.
Definition: wallet.h:868
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
Definition: wallet.h:878
bool EraseDestData(const CTxDestination &dest, const std::string &key)
Erases a destination data tuple in the store and on disk.
Definition: wallet.cpp:3547
bool AddDestData(const CTxDestination &dest, const std::string &key, const std::string &value)
Adds a destination data tuple to the store, and saves it to disk.
Definition: wallet.cpp:3536
boost::signals2::signal< void(CWallet *wallet, const uint256 &hashTx, ChangeType status)> NotifyTransactionChanged
Wallet transaction added, removed or updated.
Definition: wallet.h:875
A transaction with a bunch of additional info that only the owner cares about.
Definition: wallet.h:177
std::vector< std::pair< std::string, std::string > > vOrderForm
Definition: wallet.h:183
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:23
const payments::PaymentDetails & getDetails() const
bool SerializeToString(std::string *output) const
static bool verifyExpired(const payments::PaymentDetails &requestDetails)
Model for list of recently generated payment requests / bitcoin: URIs.
PaymentRequestPlus paymentRequest
Definition: walletmodel.h:56
bool fSubtractFeeFromAmount
Definition: walletmodel.h:60
UI model for the transaction table of a wallet.
UnlockContext(WalletModel *wallet, bool valid, bool relock)
void CopyFrom(const UnlockContext &rhs)
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:99
CAmount cachedWatchUnconfBalance
Definition: walletmodel.h:234
CAmount cachedImmatureBalance
Definition: walletmodel.h:232
OptionsModel * optionsModel
Definition: walletmodel.h:223
bool validateAddress(const QString &address)
AddressTableModel * addressTableModel
Definition: walletmodel.h:225
void unlockCoin(COutPoint &output)
void loadReceiveRequests(std::vector< std::string > &vReceiveRequests)
EncryptionStatus cachedEncryptionStatus
Definition: walletmodel.h:236
bool hdEnabled() const
CAmount cachedBalance
Definition: walletmodel.h:230
WalletModel(const PlatformStyle *platformStyle, CWallet *wallet, OptionsModel *optionsModel, QObject *parent=0)
Definition: walletmodel.cpp:34
void listLockedCoins(std::vector< COutPoint > &vOutpts)
bool transactionCanBeAbandoned(uint256 hash) const
bool getPrivKey(const CKeyID &address, CKey &vchPrivKeyOut) const
bool setWalletEncrypted(bool encrypted, const SecureString &passphrase)
CAmount getBalance(const CCoinControl *coinControl=NULL) const
Definition: walletmodel.cpp:62
void encryptionStatusChanged(int status)
CAmount getUnconfirmedBalance() const
Definition: walletmodel.cpp:79
void pollBalanceChanged()
void getOutputs(const std::vector< COutPoint > &vOutpoints, std::vector< COutput > &vOutputs)
SendCoinsReturn sendCoins(WalletModelTransaction &transaction)
void balanceChanged(const CAmount &balance, const CAmount &unconfirmedBalance, const CAmount &immatureBalance, const CAmount &watchOnlyBalance, const CAmount &watchUnconfBalance, const CAmount &watchImmatureBalance)
RecentRequestsTableModel * recentRequestsTableModel
Definition: walletmodel.h:227
TransactionTableModel * transactionTableModel
Definition: walletmodel.h:226
void notifyWatchonlyChanged(bool fHaveWatchonly)
bool changePassphrase(const SecureString &oldPass, const SecureString &newPass)
CAmount getWatchUnconfirmedBalance() const
Definition: walletmodel.cpp:99
bool havePrivKey(const CKeyID &address) const
CAmount cachedWatchImmatureBalance
Definition: walletmodel.h:235
bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString())
CAmount getWatchBalance() const
Definition: walletmodel.cpp:94
void message(const QString &title, const QString &message, unsigned int style)
CAmount cachedWatchOnlyBalance
Definition: walletmodel.h:233
bool saveReceiveRequest(const std::string &sAddress, const int64_t nId, const std::string &sRequest)
void updateStatus()
AddressTableModel * getAddressTableModel()
SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const CCoinControl *coinControl=NULL)
CAmount cachedUnconfirmedBalance
Definition: walletmodel.h:231
OptionsModel * getOptionsModel()
void lockCoin(COutPoint &output)
CAmount getWatchImmatureBalance() const
bool abandonTransaction(uint256 hash) const
bool backupWallet(const QString &filename)
EncryptionStatus getEncryptionStatus() const
RecentRequestsTableModel * getRecentRequestsTableModel()
bool fForceCheckBalanceChanged
Definition: walletmodel.h:219
bool haveWatchOnly() const
Definition: walletmodel.cpp:89
CWallet * wallet
Definition: walletmodel.h:217
bool getPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
bool isLockedCoin(uint256 hash, unsigned int n) const
CAmount getImmatureBalance() const
Definition: walletmodel.cpp:84
QTimer * pollTimer
Definition: walletmodel.h:239
void unsubscribeFromCoreSignals()
bool isSpent(const COutPoint &outpoint) const
void requireUnlock()
void updateTransaction()
void coinsSent(CWallet *wallet, SendCoinsRecipient recipient, QByteArray transaction)
void updateAddressBook(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
bool fHaveWatchOnly
Definition: walletmodel.h:218
void checkBalanceChanged()
void updateWatchOnlyFlag(bool fHaveWatchonly)
void listCoins(std::map< QString, std::vector< COutput > > &mapCoins) const
UnlockContext requestUnlock()
int cachedNumBlocks
Definition: walletmodel.h:237
static bool isWalletEnabled()
@ AmountWithFeeExceedsBalance
Definition: walletmodel.h:112
@ TransactionCreationFailed
Definition: walletmodel.h:114
@ AmountExceedsBalance
Definition: walletmodel.h:111
@ TransactionCommitFailed
Definition: walletmodel.h:115
@ PaymentRequestExpired
Definition: walletmodel.h:117
int getDefaultConfirmTarget() const
void subscribeToCoreSignals()
TransactionTableModel * getTransactionTableModel()
Data model for a walletmodel transaction.
void setTransactionFee(const CAmount &newFee)
void reassignAmounts(int nChangePosRet)
QList< SendCoinsRecipient > getRecipients()
void newPossibleKeyChange(CWallet *wallet)
256-bit opaque blob.
Definition: uint256.h:123
void UnlockCoin(const COutPoint &output)
Definition: wallet.cpp:3418
bool CreateTransaction(const std::vector< CRecipient > &vecSend, CWalletTx &wtxNew, CReserveKey &reservekey, CAmount &nFeeRet, int &nChangePosInOut, std::string &strFailReason, const CCoinControl *coinControl=NULL, bool sign=true)
Create a new transaction paying the recipients with a set of coins selected by SelectCoins(); Also cr...
Definition: wallet.cpp:2405
CAmount GetImmatureWatchOnlyBalance() const
Definition: wallet.cpp:2007
bool CommitTransaction(CWalletTx &wtxNew, CReserveKey &reservekey, CConnman *connman, CValidationState &state)
Call after CreateTransaction unless you want to abort.
Definition: wallet.cpp:2780
void ListLockedCoins(std::vector< COutPoint > &vOutpts)
Definition: wallet.cpp:3438
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::string &purpose)
Definition: wallet.cpp:2959
bool IsLockedCoin(uint256 hash, unsigned int n) const
Definition: wallet.cpp:3430
CAmount GetImmatureBalance() const
Definition: wallet.cpp:1962
CAmount GetUnconfirmedBalance() const
Definition: wallet.cpp:1947
CAmount GetWatchOnlyBalance() const
Definition: wallet.cpp:1976
CAmount GetBalance() const
Definition: wallet.cpp:1931
void AvailableCoins(std::vector< COutput > &vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl=NULL, const CAmount &nMinimumAmount=1, const CAmount &nMaximumAmount=MAX_MONEY, const CAmount &nMinimumSumAmount=MAX_MONEY, const uint64_t &nMaximumCount=0, const int &nMinDepth=0, const int &nMaxDepth=9999999) const
populate vCoins with vector of available COutputs.
Definition: wallet.cpp:2021
CAmount GetUnconfirmedWatchOnlyBalance() const
Definition: wallet.cpp:1992
void LockCoin(const COutPoint &output)
Definition: wallet.cpp:3412
bool Unlock(const SecureString &strWalletPassphrase)
Definition: wallet.cpp:295
bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
Definition: wallet.cpp:315
isminetype IsMine(const CTxIn &txin) const
Definition: wallet.cpp:1201
bool IsSpent(const uint256 &hash, unsigned int n) const
Outpoint is spent if any non-conflicted transaction spends it:
Definition: wallet.cpp:541
bool AbandonTransaction(const uint256 &hashTx)
Definition: wallet.cpp:1067
bool EncryptWallet(const SecureString &strWalletPassphrase)
Definition: wallet.cpp:581
bool IsHDEnabled()
Definition: wallet.cpp:1402
bool IsChange(const CTxOut &txout) const
Definition: wallet.cpp:1246
const CWalletTx * GetWalletTx(const uint256 &hash) const
Definition: wallet.cpp:80
bool InMempool() const
Definition: wallet.cpp:1824
std::unique_ptr< CConnman > g_connman
Definition: init.cpp:75
@ ISMINE_SPENDABLE
Definition: ismine.h:25
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: secure.h:56
@ SER_NETWORK
Definition: serialize.h:146
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Definition: standard.cpp:182
CScript GetScriptForDestination(const CTxDestination &dest)
Definition: standard.cpp:280
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:71
#define LOCK2(cs1, cs2)
Definition: sync.h:178
#define LOCK(cs)
Definition: sync.h:177
#define TRY_LOCK(cs, name)
Definition: sync.h:179
ChangeType
General change type (added, updated, removed).
Definition: ui_interface.h:22
bool GetBoolArg(const std::string &strArg, bool fDefault)
Return boolean argument or default value.
Definition: util.cpp:411
#define PAIRTYPE(t1, t2)
This is needed because the foreach macro can't get over the comma in pair<t1, t2>
CCriticalSection cs_main
Global state.
Definition: validation.cpp:61
CAmount maxTxFee
Absolute maximum transaction fee (in satoshis) used by wallet and mempool (rejects high fee in sendra...
Definition: validation.cpp:87
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
Definition: validation.cpp:64
unsigned int nTxConfirmTarget
Definition: wallet.cpp:41