Anoncoin  0.9.4
P2P Digital Currency
walletmodel.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2014 The Bitcoin developers
2 // Copyright (c) 2013-2014 The Anoncoin Core developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include "walletmodel.h"
7 
8 #include "addresstablemodel.h"
9 #include "guiconstants.h"
11 #include "transactiontablemodel.h"
12 
13 #include "base58.h"
14 #include "db.h"
15 #include "keystore.h"
16 #include "main.h"
17 #include "sync.h"
18 #include "ui_interface.h"
19 #include "wallet.h"
20 #include "walletdb.h" // for BackupWallet
21 
22 #include <stdint.h>
23 
24 #include <QDebug>
25 #include <QSet>
26 #include <QTimer>
27 
28 WalletModel::WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *parent) :
29  QObject(parent), wallet(wallet), optionsModel(optionsModel), addressTableModel(0),
30  transactionTableModel(0),
31  recentRequestsTableModel(0),
32  cachedBalance(0), cachedUnconfirmedBalance(0), cachedImmatureBalance(0),
33  cachedEncryptionStatus(Unencrypted),
34  cachedNumBlocks(0)
35 {
37  fHaveWatchOnly = wallet->HaveWatchOnly();
39 
40  addressTableModel = new AddressTableModel(wallet, this);
41  transactionTableModel = new TransactionTableModel(wallet, this);
43 
44  // This timer will be fired repeatedly to update the balance
45  pollTimer = new QTimer(this);
46  connect(pollTimer, SIGNAL(timeout()), this, SLOT(pollBalanceChanged()));
47  pollTimer->start(MODEL_UPDATE_DELAY);
48 
50 }
51 
53 {
55 }
56 
57 qint64 WalletModel::getBalance(const CCoinControl *coinControl) const
58 {
59  if (coinControl)
60  {
61  qint64 nBalance = 0;
62  std::vector<COutput> vCoins;
63  wallet->AvailableCoins(vCoins, true, coinControl);
64  BOOST_FOREACH(const COutput& out, vCoins)
65  if(out.fSpendable)
66  nBalance += out.tx->vout[out.i].nValue;
67 
68  return nBalance;
69  }
70 
71  return wallet->GetBalance();
72 }
73 
75 {
76  return wallet->GetUnconfirmedBalance();
77 }
78 
80 {
81  return wallet->GetImmatureBalance();
82 }
83 
85 {
86  return fHaveWatchOnly;
87 }
88 
90 {
91  return wallet->GetWatchOnlyBalance();
92 }
93 
95 {
97 }
98 
100 {
102 }
103 
105 {
106  EncryptionStatus newEncryptionStatus = getEncryptionStatus();
107 
108  if(cachedEncryptionStatus != newEncryptionStatus)
109  emit encryptionStatusChanged(newEncryptionStatus);
110 }
111 
113 {
114  // Get required locks upfront. This avoids the GUI from getting stuck on
115  // periodical polls if the core is holding the locks for a longer time -
116  // for example, during a wallet rescan.
117  TRY_LOCK(cs_main, lockMain);
118  if(!lockMain)
119  return;
120  TRY_LOCK(wallet->cs_wallet, lockWallet);
121  if(!lockWallet)
122  return;
123 
125  {
127 
128  // Balance and number of transactions might have changed
130 
134  }
135 }
136 
138 {
139  qint64 newBalance = getBalance();
140  qint64 newUnconfirmedBalance = getUnconfirmedBalance();
141  qint64 newImmatureBalance = getImmatureBalance();
142  qint64 newWatchOnlyBalance = 0;
143  qint64 newWatchUnconfBalance = 0;
144  qint64 newWatchImmatureBalance = 0;
145  if (haveWatchOnly())
146  {
147  newWatchOnlyBalance = getWatchBalance();
148  newWatchUnconfBalance = getWatchUnconfirmedBalance();
149  newWatchImmatureBalance = getWatchImmatureBalance();
150  }
151 
152  if(cachedBalance != newBalance || cachedUnconfirmedBalance != newUnconfirmedBalance || cachedImmatureBalance != newImmatureBalance ||
153  cachedWatchOnlyBalance != newWatchOnlyBalance || cachedWatchUnconfBalance != newWatchUnconfBalance || cachedWatchImmatureBalance != newWatchImmatureBalance)
154  {
155  cachedBalance = newBalance;
156  cachedUnconfirmedBalance = newUnconfirmedBalance;
157  cachedImmatureBalance = newImmatureBalance;
158  cachedWatchOnlyBalance = newWatchOnlyBalance;
159  cachedWatchUnconfBalance = newWatchUnconfBalance;
160  cachedWatchImmatureBalance = newWatchImmatureBalance;
161  emit balanceChanged(newBalance, newUnconfirmedBalance, newImmatureBalance,
162  newWatchOnlyBalance, newWatchUnconfBalance, newWatchImmatureBalance);
163  }
164 }
165 
166 void WalletModel::updateTransaction(const QString &hash, int status)
167 {
170 
171  // Balance and number of transactions might have changed
173 }
174 
175 void WalletModel::updateAddressBook(const QString &address, const QString &label,
176  bool isMine, const QString &purpose, int status)
177 {
179  addressTableModel->updateEntry(address, label, isMine, purpose, status);
180 }
181 
182 void WalletModel::updateWatchOnlyFlag(bool fHaveWatchonly)
183 {
184  fHaveWatchOnly = fHaveWatchonly;
185  emit notifyWatchonlyChanged(fHaveWatchonly);
186 }
187 
188 bool WalletModel::validateAddress(const QString &address)
189 {
190  CAnoncoinAddress addressParsed(address.toStdString());
191  return addressParsed.IsValid();
192 }
193 
195 {
196  qint64 total = 0;
197  QList<SendCoinsRecipient> recipients = transaction.getRecipients();
198  std::vector<std::pair<CScript, int64_t> > vecSend;
199 
200  if(recipients.empty())
201  {
202  return OK;
203  }
204 
205  QSet<QString> setAddress; // Used to detect duplicates
206  int nAddresses = 0;
207 
208  // Pre-check input data for validity
209  foreach(const SendCoinsRecipient &rcp, recipients)
210  {
211  if (rcp.paymentRequest.IsInitialized())
212  { // PaymentRequest...
213  int64_t subtotal = 0;
214  const payments::PaymentDetails& details = rcp.paymentRequest.getDetails();
215  for (int i = 0; i < details.outputs_size(); i++)
216  {
217  const payments::Output& out = details.outputs(i);
218  if (out.amount() <= 0) continue;
219  subtotal += out.amount();
220  const unsigned char* scriptStr = (const unsigned char*)out.script().data();
221  CScript scriptPubKey(scriptStr, scriptStr+out.script().size());
222  vecSend.push_back(std::pair<CScript, int64_t>(scriptPubKey, out.amount()));
223  }
224  if (subtotal <= 0)
225  {
226  return InvalidAmount;
227  }
228  total += subtotal;
229  }
230  else
231  { // User-entered anoncoin address / amount:
232  if(!validateAddress(rcp.address))
233  {
234  return InvalidAddress;
235  }
236  if(rcp.amount <= 0)
237  {
238  return InvalidAmount;
239  }
240  setAddress.insert(rcp.address);
241  ++nAddresses;
242 
243  CScript scriptPubKey;
244  scriptPubKey.SetDestination(CAnoncoinAddress(rcp.address.toStdString()).Get());
245  vecSend.push_back(std::pair<CScript, int64_t>(scriptPubKey, rcp.amount));
246 
247  total += rcp.amount;
248  }
249  }
250  if(setAddress.size() != nAddresses)
251  {
252  return DuplicateAddress;
253  }
254 
255  qint64 nBalance = getBalance(coinControl);
256 
257  if(total > nBalance)
258  {
259  return AmountExceedsBalance;
260  }
261 
262  if((total + nTransactionFee) > nBalance)
263  {
264  transaction.setTransactionFee(nTransactionFee);
266  }
267 
268  {
270 
271  transaction.newPossibleKeyChange(wallet);
272  int64_t nFeeRequired = 0;
273  std::string strFailReason;
274 
275  CWalletTx *newTx = transaction.getTransaction();
276  CReserveKey *keyChange = transaction.getPossibleKeyChange();
277  bool fCreated = wallet->CreateTransaction(vecSend, *newTx, *keyChange, nFeeRequired, strFailReason, coinControl);
278  transaction.setTransactionFee(nFeeRequired);
279 
280  if(!fCreated)
281  {
282  if((total + nFeeRequired) > nBalance)
283  {
285  }
286  emit message(tr("Send Coins"), QString::fromStdString(strFailReason),
289  }
290  }
291 
292  return SendCoinsReturn(OK);
293 }
294 
296 {
297  QByteArray transaction_array; /* store serialized transaction */
298 
299  {
301  CWalletTx *newTx = transaction.getTransaction();
302 
303  // Store PaymentRequests in wtx.vOrderForm in wallet.
304  foreach(const SendCoinsRecipient &rcp, transaction.getRecipients())
305  {
306  if (rcp.paymentRequest.IsInitialized())
307  {
308  std::string key("PaymentRequest");
309  std::string value;
310  rcp.paymentRequest.SerializeToString(&value);
311  newTx->vOrderForm.push_back(make_pair(key, value));
312  }
313  else if (!rcp.message.isEmpty()) // Message from normal anoncoin:URI (anoncoin:123...?message=example)
314  newTx->vOrderForm.push_back(make_pair("Message", rcp.message.toStdString()));
315  }
316 
317  CReserveKey *keyChange = transaction.getPossibleKeyChange();
318  if(!wallet->CommitTransaction(*newTx, *keyChange))
320 
321  CTransaction* t = (CTransaction*)newTx;
322  CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
323  ssTx << *t;
324  transaction_array.append(&(ssTx[0]), ssTx.size());
325  }
326 
327  // Add addresses / update labels that we've sent to to the address book,
328  // and emit coinsSent signal for each recipient
329  foreach(const SendCoinsRecipient &rcp, transaction.getRecipients())
330  {
331  // Don't touch the address book when we have a payment request
332  if (!rcp.paymentRequest.IsInitialized())
333  {
334  std::string strAddress = rcp.address.toStdString();
335  CTxDestination dest = CAnoncoinAddress(strAddress).Get();
336  std::string strLabel = rcp.label.toStdString();
337  {
339 
340  std::map<CTxDestination, CAddressBookData>::iterator mi = wallet->mapAddressBook.find(dest);
341 
342  // Check if we have a new address or an updated label
343  if (mi == wallet->mapAddressBook.end())
344  {
345  wallet->SetAddressBook(dest, strLabel, "send");
346  }
347  else if (mi->second.name != strLabel)
348  {
349  wallet->SetAddressBook(dest, strLabel, ""); // "" means don't change purpose
350  }
351  }
352  }
353  emit coinsSent(wallet, rcp, transaction_array);
354  }
355  checkBalanceChanged(); // update balance immediately, otherwise there could be a short noticeable delay until pollBalanceChanged hits
356 
357  return SendCoinsReturn(OK);
358 }
359 
361 {
362  return optionsModel;
363 }
364 
366 {
367  return addressTableModel;
368 }
369 
371 {
372  return transactionTableModel;
373 }
374 
376 {
378 }
379 
381 {
382  if(!wallet->IsCrypted())
383  {
384  return Unencrypted;
385  }
386  else if(wallet->IsLocked())
387  {
388  return Locked;
389  }
390  else
391  {
392  return Unlocked;
393  }
394 }
395 
396 bool WalletModel::setWalletEncrypted(bool encrypted, const SecureString &passphrase)
397 {
398  if(encrypted)
399  {
400  // Encrypt
401  return wallet->EncryptWallet(passphrase);
402  }
403  else
404  {
405  // Decrypt -- TODO; not supported yet
406  return false;
407  }
408 }
409 
410 bool WalletModel::setWalletLocked(bool locked, const SecureString &passPhrase)
411 {
412  if(locked)
413  {
414  // Lock
415  return wallet->Lock();
416  }
417  else
418  {
419  // Unlock
420  return wallet->Unlock(passPhrase);
421  }
422 }
423 
424 bool WalletModel::changePassphrase(const SecureString &oldPass, const SecureString &newPass)
425 {
426  bool retval;
427  {
429  wallet->Lock(); // Make sure wallet is locked before attempting pass change
430  retval = wallet->ChangeWalletPassphrase(oldPass, newPass);
431  }
432  return retval;
433 }
434 
435 bool WalletModel::backupWallet(const QString &filename)
436 {
437  return BackupWallet(*wallet, filename.toLocal8Bit().data());
438 }
439 
440 // Handlers for core signals
441 static void NotifyKeyStoreStatusChanged(WalletModel *walletmodel, CCryptoKeyStore *wallet)
442 {
443  qDebug() << "NotifyKeyStoreStatusChanged";
444  QMetaObject::invokeMethod(walletmodel, "updateStatus", Qt::QueuedConnection);
445 }
446 
447 static void NotifyAddressBookChanged(WalletModel *walletmodel, CWallet *wallet,
448  const CTxDestination &address, const std::string &label, bool isMine,
449  const std::string &purpose, ChangeType status)
450 {
451  QString strAddress = QString::fromStdString(CAnoncoinAddress(address).ToString());
452  QString strLabel = QString::fromStdString(label);
453  QString strPurpose = QString::fromStdString(purpose);
454 
455  qDebug() << "NotifyAddressBookChanged : " + strAddress + " " + strLabel + " isMine=" + QString::number(isMine) + " purpose=" + strPurpose + " status=" + QString::number(status);
456  QMetaObject::invokeMethod(walletmodel, "updateAddressBook", Qt::QueuedConnection,
457  Q_ARG(QString, strAddress),
458  Q_ARG(QString, strLabel),
459  Q_ARG(bool, isMine),
460  Q_ARG(QString, strPurpose),
461  Q_ARG(int, status));
462 }
463 
464 // queue notifications to show a non freezing progress dialog e.g. for rescan
465 static bool fQueueNotifications = false;
466 static std::vector<std::pair<uint256, ChangeType> > vQueueNotifications;
467 static void NotifyTransactionChanged(WalletModel *walletmodel, CWallet *wallet, const uint256 &hash, ChangeType status)
468 {
469  if (fQueueNotifications)
470  {
471  vQueueNotifications.push_back(make_pair(hash, status));
472  return;
473  }
474 
475  QString strHash = QString::fromStdString(hash.GetHex());
476 
477  qDebug() << "NotifyTransactionChanged : " + strHash + " status= " + QString::number(status);
478  QMetaObject::invokeMethod(walletmodel, "updateTransaction", Qt::QueuedConnection,
479  Q_ARG(QString, strHash),
480  Q_ARG(int, status));
481 }
482 
483 static void ShowProgress(WalletModel *walletmodel, const std::string &title, int nProgress)
484 {
485  if (nProgress == 0)
486  fQueueNotifications = true;
487 
488  if (nProgress == 100)
489  {
490  fQueueNotifications = false;
491  if (vQueueNotifications.size() > 10) // prevent balloon spam, show maximum 10 balloons
492  QMetaObject::invokeMethod(walletmodel, "setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(bool, true));
493  for (unsigned int i = 0; i < vQueueNotifications.size(); ++i)
494  {
495  if (vQueueNotifications.size() - i <= 10)
496  QMetaObject::invokeMethod(walletmodel, "setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(bool, false));
497 
498  NotifyTransactionChanged(walletmodel, NULL, vQueueNotifications[i].first, vQueueNotifications[i].second);
499  }
500  std::vector<std::pair<uint256, ChangeType> >().swap(vQueueNotifications); // clear
501  }
502 
503  // emits signal "showProgress"
504  QMetaObject::invokeMethod(walletmodel, "showProgress", Qt::QueuedConnection,
505  Q_ARG(QString, QString::fromStdString(title)),
506  Q_ARG(int, nProgress));
507 }
508 
509 static void NotifyWatchonlyChanged(WalletModel *walletmodel, bool fHaveWatchonly)
510 {
511  QMetaObject::invokeMethod(walletmodel, "updateWatchOnlyFlag", Qt::QueuedConnection,
512  Q_ARG(bool, fHaveWatchonly));
513 }
514 
516 {
517  // Connect signals to wallet
518  wallet->NotifyStatusChanged.connect(boost::bind(&NotifyKeyStoreStatusChanged, this, _1));
519  wallet->NotifyAddressBookChanged.connect(boost::bind(NotifyAddressBookChanged, this, _1, _2, _3, _4, _5, _6));
520  wallet->NotifyTransactionChanged.connect(boost::bind(NotifyTransactionChanged, this, _1, _2, _3));
521  wallet->ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2));
522  wallet->NotifyWatchonlyChanged.connect(boost::bind(NotifyWatchonlyChanged, this, _1));
523 }
524 
526 {
527  // Disconnect signals from wallet
528  wallet->NotifyStatusChanged.disconnect(boost::bind(&NotifyKeyStoreStatusChanged, this, _1));
529  wallet->NotifyAddressBookChanged.disconnect(boost::bind(NotifyAddressBookChanged, this, _1, _2, _3, _4, _5, _6));
530  wallet->NotifyTransactionChanged.disconnect(boost::bind(NotifyTransactionChanged, this, _1, _2, _3));
531  wallet->ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2));
532  wallet->NotifyWatchonlyChanged.disconnect(boost::bind(NotifyWatchonlyChanged, this, _1));
533 }
534 
535 // WalletModel::UnlockContext implementation
537 {
538  bool was_locked = getEncryptionStatus() == Locked;
539  if(was_locked)
540  {
541  // Request UI to unlock wallet
542  emit requireUnlock();
543  }
544  // If wallet is still locked, unlock was failed or cancelled, mark context as invalid
545  bool valid = getEncryptionStatus() != Locked;
546 
547  return UnlockContext(this, valid, was_locked);
548 }
549 
550 WalletModel::UnlockContext::UnlockContext(WalletModel *wallet, bool valid, bool relock):
551  wallet(wallet),
552  valid(valid),
553  relock(relock)
554 {
555 }
556 
558 {
559  if(valid && relock)
560  {
561  wallet->setWalletLocked(true);
562  }
563 }
564 
566 {
567  // Transfer context; old object no longer relocks wallet
568  *this = rhs;
569  rhs.relock = false;
570 }
571 
572 bool WalletModel::getPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const
573 {
574  return wallet->GetPubKey(address, vchPubKeyOut);
575 }
576 
577 // returns a list of COutputs from COutPoints
578 void WalletModel::getOutputs(const std::vector<COutPoint>& vOutpoints, std::vector<COutput>& vOutputs)
579 {
580  LOCK2(cs_main, wallet->cs_wallet);
581  BOOST_FOREACH(const COutPoint& outpoint, vOutpoints)
582  {
583  if (!wallet->mapWallet.count(outpoint.hash)) continue;
584  int nDepth = wallet->mapWallet[outpoint.hash].GetDepthInMainChain();
585  if (nDepth < 0) continue;
586  COutput out(&wallet->mapWallet[outpoint.hash], outpoint.n, nDepth, true);
587  vOutputs.push_back(out);
588  }
589 }
590 
591 bool WalletModel::isSpent(const COutPoint& outpoint) const
592 {
593  LOCK2(cs_main, wallet->cs_wallet);
594  return wallet->IsSpent(outpoint.hash, outpoint.n);
595 }
596 
597 // AvailableCoins + LockedCoins grouped by wallet address (put change in one group with wallet address)
598 void WalletModel::listCoins(std::map<QString, std::vector<COutput> >& mapCoins) const
599 {
600  std::vector<COutput> vCoins;
601  wallet->AvailableCoins(vCoins);
602 
603  LOCK2(cs_main, wallet->cs_wallet); // ListLockedCoins, mapWallet
604  std::vector<COutPoint> vLockedCoins;
605  wallet->ListLockedCoins(vLockedCoins);
606 
607  // add locked coins
608  BOOST_FOREACH(const COutPoint& outpoint, vLockedCoins)
609  {
610  if (!wallet->mapWallet.count(outpoint.hash)) continue;
611  int nDepth = wallet->mapWallet[outpoint.hash].GetDepthInMainChain();
612  if (nDepth < 0) continue;
613  COutput out(&wallet->mapWallet[outpoint.hash], outpoint.n, nDepth, true);
614  if (outpoint.n < out.tx->vout.size() && wallet->IsMine(out.tx->vout[outpoint.n]) == ISMINE_SPENDABLE)
615  vCoins.push_back(out);
616  }
617 
618  BOOST_FOREACH(const COutput& out, vCoins)
619  {
620  COutput cout = out;
621 
622  while (wallet->IsChange(cout.tx->vout[cout.i]) && cout.tx->vin.size() > 0 && wallet->IsMine(cout.tx->vin[0]))
623  {
624  if (!wallet->mapWallet.count(cout.tx->vin[0].prevout.hash)) break;
625  cout = COutput(&wallet->mapWallet[cout.tx->vin[0].prevout.hash], cout.tx->vin[0].prevout.n, 0, true);
626  }
627 
628  CTxDestination address;
629  if(!out.fSpendable || !ExtractDestination(cout.tx->vout[cout.i].scriptPubKey, address))
630  continue;
631  mapCoins[CAnoncoinAddress(address).ToString().c_str()].push_back(out);
632  }
633 }
634 
635 bool WalletModel::isLockedCoin(uint256 hash, unsigned int n) const
636 {
637  LOCK2(cs_main, wallet->cs_wallet);
638  return wallet->IsLockedCoin(hash, n);
639 }
640 
642 {
643  LOCK2(cs_main, wallet->cs_wallet);
644  wallet->LockCoin(output);
645 }
646 
648 {
649  LOCK2(cs_main, wallet->cs_wallet);
650  wallet->UnlockCoin(output);
651 }
652 
653 void WalletModel::listLockedCoins(std::vector<COutPoint>& vOutpts)
654 {
655  LOCK2(cs_main, wallet->cs_wallet);
656  wallet->ListLockedCoins(vOutpts);
657 }
658 
659 void WalletModel::loadReceiveRequests(std::vector<std::string>& vReceiveRequests)
660 {
661  LOCK(wallet->cs_wallet);
662  BOOST_FOREACH(const PAIRTYPE(CTxDestination, CAddressBookData)& item, wallet->mapAddressBook)
663  BOOST_FOREACH(const PAIRTYPE(std::string, std::string)& item2, item.second.destdata)
664  if (item2.first.size() > 2 && item2.first.substr(0,2) == "rr") // receive request
665  vReceiveRequests.push_back(item2.second);
666 }
667 
668 bool WalletModel::saveReceiveRequest(const std::string &sAddress, const int64_t nId, const std::string &sRequest)
669 {
670  CTxDestination dest = CAnoncoinAddress(sAddress).Get();
671 
672  std::stringstream ss;
673  ss << nId;
674  std::string key = "rr" + ss.str(); // "rr" prefix = "receive request" in destdata
675 
676  LOCK(wallet->cs_wallet);
677  if (sRequest.empty())
678  return wallet->EraseDestData(dest, key);
679  else
680  return wallet->AddDestData(dest, key, sRequest);
681 }
void loadReceiveRequests(std::vector< std::string > &vReceiveRequests)
Model for list of recently generated payment requests / anoncoin: URIs.
TransactionTableModel * transactionTableModel
Definition: walletmodel.h:210
bool IsCrypted() const
Definition: crypter.h:138
void getOutputs(const std::vector< COutPoint > &vOutpoints, std::vector< COutput > &vOutputs)
int i
Definition: wallet.h:828
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::string &purpose)
Definition: wallet.cpp:1638
RecentRequestsTableModel * recentRequestsTableModel
Definition: walletmodel.h:211
PaymentRequestPlus paymentRequest
Definition: walletmodel.h:56
isminetype IsMine(const CTxIn &txin) const
Definition: wallet.cpp:691
bool IsInitialized() const
int64_t GetImmatureBalance() const
Definition: wallet.cpp:1050
void lockCoin(COutPoint &output)
qint64 getImmatureBalance() const
Definition: walletmodel.cpp:79
#define TRY_LOCK(cs, name)
Definition: sync.h:159
qint64 cachedImmatureBalance
Definition: walletmodel.h:216
int64_t GetUnconfirmedWatchOnlyBalance() const
Definition: wallet.cpp:1080
void ListLockedCoins(std::vector< COutPoint > &vOutpts)
Definition: wallet.cpp:2087
std::map< CTxDestination, CAddressBookData > mapAddressBook
Definition: wallet.h:174
#define PAIRTYPE(t1, t2)
Definition: util.h:49
CCriticalSection cs_wallet
Main wallet lock.
Definition: wallet.h:133
qint64 cachedUnconfirmedBalance
Definition: walletmodel.h:215
UnlockContext requestUnlock()
void unsubscribeFromCoreSignals()
bool isLockedCoin(uint256 hash, unsigned int n) const
CTxDestination Get() const
Definition: base58.cpp:223
bool SerializeToString(string *output) const
qint64 getWatchUnconfirmedBalance() const
Definition: walletmodel.cpp:94
CCriticalSection cs_main
Definition: main.cpp:38
bool backupWallet(const QString &filename)
SendCoinsReturn sendCoins(WalletModelTransaction &transaction)
bool IsLocked() const
Definition: crypter.h:143
Double ended buffer combining vector and stream-like interfaces.
Definition: serialize.h:848
virtual bool HaveWatchOnly(const CScript &dest) const
Definition: keystore.cpp:77
void updateTransaction(const QString &hash, int status)
bool fProcessingQueuedTransactions
Definition: walletmodel.h:201
unsigned int n
Definition: core.h:28
bool BackupWallet(const CWallet &wallet, const string &strDest)
Definition: walletdb.cpp:851
AddressTableModel * getAddressTableModel()
Keystore which keeps the private keys encrypted.
Definition: crypter.h:114
bool fSpendable
Definition: wallet.h:830
bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
Definition: crypter.cpp:236
CChain chainActive
The currently-connected chain of blocks.
Definition: main.cpp:43
bool IsValid() const
Definition: base58.cpp:216
Coin Control Features.
Definition: coincontrol.h:12
const ::std::string & script() const
void updateStatus()
void newPossibleKeyChange(CWallet *wallet)
void setTransactionFee(qint64 newFee)
UnlockContext(WalletModel *wallet, bool valid, bool relock)
void SetDestination(const CTxDestination &address)
Definition: script.cpp:1945
int64_t GetWatchOnlyBalance() const
Definition: wallet.cpp:1064
QList< SendCoinsRecipient > getRecipients()
boost::signals2::signal< void(CWallet *wallet, const uint256 &hashTx, ChangeType status)> NotifyTransactionChanged
Wallet transaction added, removed or updated.
Definition: wallet.h:405
int64_t GetBalance() const
Definition: wallet.cpp:1019
bool CreateTransaction(const std::vector< std::pair< CScript, int64_t > > &vecSend, CWalletTx &wtxNew, CReserveKey &reservekey, int64_t &nFeeRet, std::string &strFailReason, const CCoinControl *coinControl=NULL)
WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *parent=0)
Definition: walletmodel.cpp:28
boost::signals2::signal< void(CCryptoKeyStore *wallet)> NotifyStatusChanged
Definition: crypter.h:190
void checkBalanceChanged()
#define LOCK2(cs1, cs2)
Definition: sync.h:158
void balanceChanged(qint64 balance, qint64 unconfirmedBalance, qint64 immatureBalance, qint64 watchOnlyBalance, qint64 watchUnconfBalance, qint64 watchImmatureBalance)
int Height() const
Return the maximal height in the chain.
Definition: main.h:1055
bool IsSpent(const uint256 &hash, unsigned int n) const
Definition: wallet.cpp:357
CWallet * wallet
Definition: walletmodel.h:200
qint64 getWatchImmatureBalance() const
Definition: walletmodel.cpp:99
void LockCoin(COutPoint &output)
Definition: wallet.cpp:2061
bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
Definition: wallet.cpp:205
int64_t nTransactionFee
Definition: wallet.cpp:20
ChangeType
General change type (added, updated, removed).
Definition: ui_interface.h:26
bool isSpent(const COutPoint &outpoint) const
#define LOCK(cs)
Definition: sync.h:157
bool changePassphrase(const SecureString &oldPass, const SecureString &newPass)
std::vector< CTxOut > vout
Definition: core.h:187
size_type size() const
Definition: serialize.h:937
void UnlockCoin(COutPoint &output)
Definition: wallet.cpp:2067
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
Definition: allocators.h:254
qint64 getUnconfirmedBalance() const
Definition: walletmodel.cpp:74
const ::payments::Output & outputs(int index) const
An encapsulated public key.
Definition: key.h:43
std::vector< CTxIn > vin
Definition: core.h:186
bool getPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
base58-encoded Anoncoin addresses.
Definition: base58.h:102
bool EraseDestData(const CTxDestination &dest, const std::string &key)
Erases a destination data tuple in the store and on disk.
Definition: wallet.cpp:2160
bool CommitTransaction(CWalletTx &wtxNew, CReserveKey &reservekey)
Definition: wallet.cpp:1491
std::string ToString() const
Definition: base58.cpp:175
OptionsModel * optionsModel
Definition: walletmodel.h:207
const payments::PaymentDetails & getDetails() const
TransactionTableModel * getTransactionTableModel()
void AvailableCoins(std::vector< COutput > &vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl=NULL) const
Definition: wallet.cpp:1110
EncryptionStatus cachedEncryptionStatus
Definition: walletmodel.h:220
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: core.h:24
void CopyFrom(const UnlockContext &rhs)
std::string GetHex() const
Definition: uint256.h:298
UI model for the transaction table of a wallet.
inline::google::protobuf::uint64 amount() const
Qt model of the address book in the core.
bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString())
A transaction with a bunch of additional info that only the owner cares about.
Definition: wallet.h:464
void encryptionStatusChanged(int status)
QTimer * pollTimer
Definition: walletmodel.h:223
EncryptionStatus getEncryptionStatus() const
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
Definition: keystore.h:17
bool validateAddress(const QString &address)
void updateWatchOnlyFlag(bool fHaveWatchonly)
qint64 cachedWatchOnlyBalance
Definition: walletmodel.h:217
256-bit unsigned integer
Definition: uint256.h:532
int cachedNumBlocks
Definition: walletmodel.h:221
bool fForceCheckBalanceChanged
Definition: walletmodel.h:203
int64_t GetImmatureWatchOnlyBalance() const
Definition: wallet.cpp:1095
int64_t GetUnconfirmedBalance() const
Definition: wallet.cpp:1035
qint64 cachedWatchUnconfBalance
Definition: walletmodel.h:218
RecentRequestsTableModel * getRecentRequestsTableModel()
bool EncryptWallet(const SecureString &strWalletPassphrase)
Definition: wallet.cpp:394
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:399
void listLockedCoins(std::vector< COutPoint > &vOutpts)
A key allocated from the key pool.
Definition: wallet.h:415
Interface from Qt to configuration data structure for Anoncoin client.
Definition: optionsmodel.h:27
Address book data.
Definition: wallet.h:83
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:413
StringMap destdata
Definition: wallet.h:95
Interface to Anoncoin wallet from Qt view code.
Definition: walletmodel.h:97
bool setWalletEncrypted(bool encrypted, const SecureString &passphrase)
void unlockCoin(COutPoint &output)
void message(const QString &title, const QString &message, unsigned int style)
A reference to a CKey: the Hash160 of its serialized public key.
Definition: key.h:27
qint64 getBalance(const CCoinControl *coinControl=NULL) const
Definition: walletmodel.cpp:57
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Definition: script.cpp:1513
const CWalletTx * tx
Definition: wallet.h:827
bool Unlock(const SecureString &strWalletPassphrase)
Definition: wallet.cpp:185
void updateTransaction(const QString &hash, int status)
bool IsChange(const CTxOut &txout) const
Definition: wallet.cpp:722
bool haveWatchOnly() const
Definition: walletmodel.cpp:84
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:101
void notifyWatchonlyChanged(bool fHaveWatchonly)
Data model for a walletmodel transaction.
void coinsSent(CWallet *wallet, SendCoinsRecipient recipient, QByteArray transaction)
SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const CCoinControl *coinControl=NULL)
std::map< uint256, CWalletTx > mapWallet
Definition: wallet.h:169
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
Definition: wallet.h:408
qint64 cachedWatchImmatureBalance
Definition: walletmodel.h:219
AddressTableModel * addressTableModel
Definition: walletmodel.h:209
qint64 cachedBalance
Definition: walletmodel.h:214
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: core.h:179
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:2149
bool fHaveWatchOnly
Definition: walletmodel.h:202
void listCoins(std::map< QString, std::vector< COutput > > &mapCoins) const
qint64 getWatchBalance() const
Definition: walletmodel.cpp:89
bool saveReceiveRequest(const std::string &sAddress, const int64_t nId, const std::string &sRequest)
bool IsLockedCoin(uint256 hash, unsigned int n) const
Definition: wallet.cpp:2079
boost::signals2::signal< void(bool fHaveWatchOnly)> NotifyWatchonlyChanged
Watch-only address added.
Definition: wallet.h:411
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 pollBalanceChanged()
OptionsModel * getOptionsModel()
void subscribeToCoreSignals()
std::vector< std::pair< std::string, std::string > > vOrderForm
Definition: wallet.h:471
uint256 hash
Definition: core.h:27