17 #include "validation.h" 35 #include <boost/foreach.hpp> 38 QObject(parent),
wallet(
wallet), optionsModel(optionsModel), addressTableModel(0),
39 transactionTableModel(0),
40 recentRequestsTableModel(0),
42 cachedUnconfirmedBalance(0),
43 cachedImmatureBalance(0),
44 cachedAnonymizedBalance(0),
45 cachedWatchOnlyBalance(0),
46 cachedWatchUnconfBalance(0),
47 cachedWatchImmatureBalance(0),
48 cachedEncryptionStatus(Unencrypted),
51 cachedPrivateSendRounds(0)
78 std::vector<COutput>
vCoins;
82 nBalance +=
out.tx->vout[
out.i].nValue;
87 return wallet->GetBalance();
93 return wallet->GetAnonymizedBalance();
98 return wallet->GetUnconfirmedBalance();
103 return wallet->GetImmatureBalance();
113 return wallet->GetWatchOnlyBalance();
118 return wallet->GetUnconfirmedWatchOnlyBalance();
123 return wallet->GetImmatureWatchOnlyBalance();
166 CAmount newWatchOnlyBalance = 0;
167 CAmount newWatchUnconfBalance = 0;
168 CAmount newWatchImmatureBalance = 0;
188 Q_EMIT
balanceChanged(newBalance, newUnconfirmedBalance, newImmatureBalance, newAnonymizedBalance,
189 newWatchOnlyBalance, newWatchUnconfBalance, newWatchImmatureBalance);
200 bool isMine,
const QString &purpose,
int status)
215 return addressParsed.
IsValid();
221 bool fSubtractFeeFromAmount =
false;
222 QList<SendCoinsRecipient> recipients = transaction.
getRecipients();
223 std::vector<CRecipient> vecSend;
225 if(recipients.empty())
235 QSet<QString> setAddress;
242 fSubtractFeeFromAmount =
true;
251 if (
out.amount() <= 0)
continue;
252 subtotal +=
out.amount();
253 const unsigned char* scriptStr = (
const unsigned char*)
out.script().data();
254 CScript scriptPubKey(scriptStr, scriptStr+
out.script().size());
257 vecSend.push_back(recipient);
275 setAddress.insert(rcp.
address);
280 vecSend.push_back(recipient);
285 if(setAddress.size() != nAddresses)
303 int nChangePosRet = -1;
304 std::string strFailReason;
315 bool fCreated =
wallet->CreateTransaction(vecSend, *newTx, *keyChange, nFeeRequired, nChangePosRet, strFailReason, coinControl,
true, recipients[0].inputType, recipients[0].fUseInstantSend);
317 if (fSubtractFeeFromAmount && fCreated)
320 if(recipients[0].fUseInstantSend) {
334 if(!fSubtractFeeFromAmount && (total + nFeeRequired) > nBalance)
338 Q_EMIT
message(tr(
"Send Coins"), QString::fromStdString(strFailReason),
355 QByteArray transaction_array;
360 QList<SendCoinsRecipient> recipients = transaction.
getRecipients();
372 std::string
key(
"PaymentRequest");
377 else if (!rcp.
message.isEmpty())
391 transaction_array.append(&(ssTx[0]), ssTx.
size());
401 std::string strAddress = rcp.
address.toStdString();
403 std::string strLabel = rcp.
label.toStdString();
407 std::map<CTxDestination, CAddressBookData>::iterator mi =
wallet->mapAddressBook.find(dest);
410 if (mi ==
wallet->mapAddressBook.end())
412 wallet->SetAddressBook(dest, strLabel,
"send");
414 else if (mi->second.name != strLabel)
416 wallet->SetAddressBook(dest, strLabel,
"");
453 else if(
wallet->IsLocked(
true))
457 else if (
wallet->IsLocked())
472 return wallet->EncryptWallet(passphrase);
486 return wallet->Lock(fMixing);
491 return wallet->Unlock(passPhrase, fMixing);
501 retval =
wallet->ChangeWalletPassphrase(oldPass, newPass);
514 qDebug() <<
"NotifyKeyStoreStatusChanged";
515 QMetaObject::invokeMethod(walletmodel,
"updateStatus", Qt::QueuedConnection);
519 const CTxDestination &address,
const std::string &label,
bool isMine,
520 const std::string &purpose,
ChangeType status)
522 QString strAddress = QString::fromStdString(
CBitcoinAddress(address).ToString());
523 QString strLabel = QString::fromStdString(label);
524 QString strPurpose = QString::fromStdString(purpose);
526 qDebug() <<
"NotifyAddressBookChanged: " + strAddress +
" " + strLabel +
" isMine=" + QString::number(isMine) +
" purpose=" + strPurpose +
" status=" + QString::number(status);
527 QMetaObject::invokeMethod(walletmodel,
"updateAddressBook", Qt::QueuedConnection,
528 Q_ARG(QString, strAddress),
529 Q_ARG(QString, strLabel),
531 Q_ARG(QString, strPurpose),
540 QMetaObject::invokeMethod(walletmodel,
"updateTransaction", Qt::QueuedConnection);
546 QMetaObject::invokeMethod(walletmodel,
"showProgress", Qt::QueuedConnection,
547 Q_ARG(QString, QString::fromStdString(title)),
548 Q_ARG(
int, nProgress));
553 QMetaObject::invokeMethod(walletmodel,
"updateWatchOnlyFlag", Qt::QueuedConnection,
554 Q_ARG(
bool, fHaveWatchonly));
583 bool was_locked = (encStatusOld ==
Locked);
587 bool fMixingToFullRequested = !fForMixingOnly && was_mixing;
589 if(was_locked || fMixingToFullRequested) {
599 bool fMixingToFullFailed = fMixingToFullRequested && !(encStatusNew ==
Unlocked);
601 bool fInvalid = (encStatusNew ==
Locked) || fMixingUnlockFailed || fMixingToFullFailed;
603 bool fKeepUnlocked = !was_locked || (fForMixingOnly && !fMixingUnlockFailed);
605 return UnlockContext(
this, !fInvalid, !fKeepUnlocked, was_mixing);
611 was_locked(was_locked),
612 was_mixing(was_mixing)
618 if(valid && (was_locked || was_mixing))
620 wallet->setWalletLocked(
true,
"", was_mixing);
634 return wallet->GetPubKey(address, vchPubKeyOut);
639 return wallet->HaveKey(address);
646 BOOST_FOREACH(
const COutPoint& outpoint, vOutpoints)
648 if (!
wallet->mapWallet.count(outpoint.
hash))
continue;
649 int nDepth =
wallet->mapWallet[outpoint.
hash].GetDepthInMainChain();
650 if (nDepth < 0)
continue;
652 vOutputs.push_back(
out);
665 std::vector<COutput>
vCoins;
669 std::vector<COutPoint> vLockedCoins;
670 wallet->ListLockedCoins(vLockedCoins);
673 BOOST_FOREACH(
const COutPoint& outpoint, vLockedCoins)
675 if (!
wallet->mapWallet.count(outpoint.
hash))
continue;
676 int nDepth =
wallet->mapWallet[outpoint.
hash].GetDepthInMainChain();
677 if (nDepth < 0)
continue;
689 if (!
wallet->mapWallet.count(cout.
tx->
vin[0].prevout.hash))
break;
703 return wallet->IsLockedCoin(hash,
n);
715 wallet->UnlockCoin(output);
721 wallet->ListLockedCoins(vOutpts);
728 BOOST_FOREACH(
const PAIRTYPE(std::string, std::string)& item2, item.second.
destdata)
729 if (item2.first.size() > 2 && item2.first.substr(0,2) ==
"rr")
730 vReceiveRequests.push_back(item2.second);
737 std::stringstream ss;
739 std::string
key =
"rr" + ss.str();
742 if (sRequest.empty())
745 return wallet->AddDestData(dest,
key, sRequest);
760 return wallet->AbandonTransaction(hash);
765 return wallet->IsHDEnabled();
void encryptionStatusChanged(int status)
CAmount cachedImmatureBalance
bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString(), bool fMixing=false)
CAmount cachedWatchOnlyBalance
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
CAmount cachedWatchImmatureBalance
void unsubscribeFromCoreSignals()
#define TRY_LOCK(cs, name)
void coinsSent(CWallet *wallet, SendCoinsRecipient recipient, QByteArray transaction)
void message(const QString &title, const QString &message, unsigned int style)
void updateConfirmations()
static const int SPORK_5_INSTANTSEND_MAX_VALUE
void newPossibleKeyChange(CWallet *wallet)
void reassignAmounts(int nChangePosRet)
static const CAmount COIN
static bool verifyExpired(const payments::PaymentDetails &requestDetails)
QList< SendCoinsRecipient > getRecipients()
EncryptionStatus cachedEncryptionStatus
const ::payments::Output & outputs(int index) const
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
bool IsInitialized() const
EncryptionStatus getEncryptionStatus() const
UnlockContext(WalletModel *wallet, bool valid, bool was_locked, bool was_mixing)
void requireUnlock(bool fForMixingOnly=false)
CAmount GetValueOut() const
void updateAddressBook(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
bool BackupWallet(const CWallet &wallet, const string &strDest)
bool haveWatchOnly() const
TransactionTableModel * getTransactionTableModel()
CAmount cachedUnconfirmedBalance
bool fSubtractFeeFromAmount
CAmount getWatchImmatureBalance() const
CAmount cachedWatchUnconfBalance
CAmount getAnonymizedBalance() const
void unlockCoin(COutPoint &output)
void updateWatchOnlyFlag(bool fHaveWatchonly)
bool SerializeToString(std::string *output) const
RecentRequestsTableModel * recentRequestsTableModel
RecentRequestsTableModel * getRecentRequestsTableModel()
void loadReceiveRequests(std::vector< std::string > &vReceiveRequests)
SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const CCoinControl *coinControl=NULL)
SendCoinsReturn sendCoins(WalletModelTransaction &transaction)
bool havePrivKey(const CKeyID &address) const
void notifyWatchonlyChanged(bool fHaveWatchonly)
bool setWalletEncrypted(bool encrypted, const SecureString &passphrase)
CAmount cachedAnonymizedBalance
void listLockedCoins(std::vector< COutPoint > &vOutpts)
std::vector< std::pair< std::string, std::string > > vOrderForm
OptionsModel * getOptionsModel()
bool getPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
CScript GetScriptForDestination(const CTxDestination &dest)
void setTransactionFee(const CAmount &newFee)
CAmount getWatchUnconfirmedBalance() const
void subscribeToCoreSignals()
void updateEntry(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
void balanceChanged(const CAmount &balance, const CAmount &unconfirmedBalance, const CAmount &immatureBalance, const CAmount &anonymizedBalance, const CAmount &watchOnlyBalance, const CAmount &watchUnconfBalance, const CAmount &watchImmatureBalance)
bool validateAddress(const QString &address)
static const int MODEL_UPDATE_DELAY
void checkBalanceChanged()
void CopyFrom(const UnlockContext &rhs)
bool isSpent(const COutPoint &outpoint) const
PaymentRequestPlus paymentRequest
bool isLockedCoin(uint256 hash, unsigned int n) const
static void NotifyAddressBookChanged(WalletModel *walletmodel, CWallet *wallet, const CTxDestination &address, const std::string &label, bool isMine, const std::string &purpose, ChangeType status)
CWalletTx * getTransaction()
CSporkManager sporkManager
TransactionTableModel * transactionTableModel
CPrivateSendClient privateSendClient
const std::vector< CTxIn > vin
static void NotifyTransactionChanged(WalletModel *walletmodel, CWallet *wallet, const uint256 &hash, ChangeType status)
const char * TXLOCKREQUEST
CTxDestination Get() const
static vector< COutput > vCoins
void lockCoin(COutPoint &output)
bool changePassphrase(const SecureString &oldPass, const SecureString &newPass)
bool saveReceiveRequest(const std::string &sAddress, const int64_t nId, const std::string &sRequest)
OptionsModel * optionsModel
static const int PROTOCOL_VERSION
AddressTableModel * addressTableModel
bool fForceCheckBalanceChanged
std::unique_ptr< CConnman > g_connman
const std::vector< CTxOut > vout
static void NotifyKeyStoreStatusChanged(WalletModel *walletmodel, CCryptoKeyStore *wallet)
CAmount getUnconfirmedBalance() const
static void NotifyWatchonlyChanged(WalletModel *walletmodel, bool fHaveWatchonly)
static const int WARN_MANY_INPUTS
bool backupWallet(const QString &filename)
void pollBalanceChanged()
bool abandonTransaction(uint256 hash) const
CAmount getBalance(const CCoinControl *coinControl=NULL) const
CAmount getWatchBalance() const
int64_t GetSporkValue(int nSporkID)
static void ShowProgress(WalletModel *walletmodel, const std::string &title, int nProgress)
int cachedPrivateSendRounds
bool transactionCanBeAbandoned(uint256 hash) const
CAmount getImmatureBalance() const
AddressTableModel * getAddressTableModel()
CReserveKey * getPossibleKeyChange()
int GetDepthInMainChain(const CBlockIndex *&pindexRet, bool enableIX=true) const
WalletModel(const PlatformStyle *platformStyle, CWallet *wallet, OptionsModel *optionsModel, QObject *parent=0)
UnlockContext requestUnlock(bool fForMixingOnly=false)
void getOutputs(const std::vector< COutPoint > &vOutpoints, std::vector< COutput > &vOutputs)
const payments::PaymentDetails & getDetails() const
void listCoins(std::map< QString, std::vector< COutput > > &mapCoins) const