31 #include <boost/bind/bind.hpp>
32 #include <boost/foreach.hpp>
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),
67 std::vector<COutput> vCoins;
69 BOOST_FOREACH(
const COutput& out, vCoins)
71 nBalance += out.
tx->
tx->vout[out.
i].nValue;
147 CAmount newWatchOnlyBalance = 0;
148 CAmount newWatchUnconfBalance = 0;
149 CAmount newWatchImmatureBalance = 0;
166 Q_EMIT
balanceChanged(newBalance, newUnconfirmedBalance, newImmatureBalance,
167 newWatchOnlyBalance, newWatchUnconfBalance, newWatchImmatureBalance);
178 bool isMine,
const QString &purpose,
int status)
193 return addressParsed.
IsValid();
199 bool fSubtractFeeFromAmount =
false;
200 QList<SendCoinsRecipient> recipients = transaction.
getRecipients();
201 std::vector<CRecipient> vecSend;
203 if(recipients.empty())
208 QSet<QString> setAddress;
215 fSubtractFeeFromAmount =
true;
221 for (
int i = 0; i < details.outputs_size(); i++)
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();
230 vecSend.push_back(recipient);
248 setAddress.insert(rcp.
address);
253 vecSend.push_back(recipient);
258 if(setAddress.size() != nAddresses)
276 int nChangePosRet = -1;
277 std::string strFailReason;
281 bool fCreated =
wallet->
CreateTransaction(vecSend, *newTx, *keyChange, nFeeRequired, nChangePosRet, strFailReason, coinControl);
283 if (fSubtractFeeFromAmount && fCreated)
288 if(!fSubtractFeeFromAmount && (total + nFeeRequired) > nBalance)
292 Q_EMIT
message(tr(
"Send Coins"), QString::fromStdString(strFailReason),
309 QByteArray transaction_array;
325 std::string key(
"PaymentRequest");
328 newTx->
vOrderForm.push_back(make_pair(key, value));
330 else if (!rcp.
message.isEmpty())
341 transaction_array.append(&(ssTx[0]), ssTx.
size());
351 std::string strAddress = rcp.
address.toStdString();
353 std::string strLabel = rcp.
label.toStdString();
364 else if (mi->second.name != strLabel)
460 qDebug() <<
"NotifyKeyStoreStatusChanged";
461 QMetaObject::invokeMethod(walletmodel,
"updateStatus", Qt::QueuedConnection);
465 const CTxDestination &address,
const std::string &label,
bool isMine,
466 const std::string &purpose,
ChangeType status)
468 QString strAddress = QString::fromStdString(
CBitcoinAddress(address).ToString());
469 QString strLabel = QString::fromStdString(label);
470 QString strPurpose = QString::fromStdString(purpose);
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),
477 Q_ARG(QString, strPurpose),
486 QMetaObject::invokeMethod(walletmodel,
"updateTransaction", Qt::QueuedConnection);
489 static void ShowProgress(
WalletModel *walletmodel,
const std::string &title,
int nProgress)
492 QMetaObject::invokeMethod(walletmodel,
"showProgress", Qt::QueuedConnection,
493 Q_ARG(QString, QString::fromStdString(title)),
494 Q_ARG(
int, nProgress));
497 static void NotifyWatchonlyChanged(
WalletModel *walletmodel,
bool fHaveWatchonly)
499 QMetaObject::invokeMethod(walletmodel,
"updateWatchOnlyFlag", Qt::QueuedConnection,
500 Q_ARG(
bool, fHaveWatchonly));
507 boost::placeholders::_1));
509 boost::placeholders::_1,
510 boost::placeholders::_2,
511 boost::placeholders::_3,
512 boost::placeholders::_4,
513 boost::placeholders::_5,
514 boost::placeholders::_6));
516 boost::placeholders::_1,
517 boost::placeholders::_2,
518 boost::placeholders::_3));
520 boost::placeholders::_2));
522 boost::placeholders::_1));
529 boost::placeholders::_1));
531 boost::placeholders::_1,
532 boost::placeholders::_2,
533 boost::placeholders::_3,
534 boost::placeholders::_4,
535 boost::placeholders::_5,
536 boost::placeholders::_6));
538 boost::placeholders::_1,
539 boost::placeholders::_2,
540 boost::placeholders::_3));
542 boost::placeholders::_1,
543 boost::placeholders::_2));
545 boost::placeholders::_1));
574 wallet->setWalletLocked(
true);
604 BOOST_FOREACH(
const COutPoint& outpoint, vOutpoints)
608 if (nDepth < 0)
continue;
610 vOutputs.push_back(out);
623 std::vector<COutput> vCoins;
627 std::vector<COutPoint> vLockedCoins;
631 BOOST_FOREACH(
const COutPoint& outpoint, vLockedCoins)
635 if (nDepth < 0)
continue;
638 vCoins.push_back(out);
641 BOOST_FOREACH(
const COutput& out, vCoins)
654 mapCoins[QString::fromStdString(
CBitcoinAddress(address).ToString())].push_back(out);
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")
688 vReceiveRequests.push_back(item2.second);
695 std::stringstream ss;
697 std::string key =
"rr" + ss.str();
700 if (sRequest.empty())
723 return !
GetBoolArg(
"-disablewallet", DEFAULT_DISABLE_WALLET);
int64_t CAmount
Amount in satoshis (Can be negative)
Qt model of the address book in the core.
void updateEntry(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
virtual bool HaveWatchOnly(const CScript &dest) const
base58-encoded Bitcoin addresses.
CTxDestination Get() const
int Height() const
Return the maximal height in the chain.
Keystore which keeps the private keys encrypted.
bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
boost::signals2::signal< void(CCryptoKeyStore *wallet)> NotifyStatusChanged
Wallet status (encrypted, locked) changed.
bool HaveKey(const CKeyID &address) const
Check whether a key corresponding to a given address is present in the store.
bool GetKey(const CKeyID &address, CKey &keyOut) const
Double ended buffer combining vector and stream-like interfaces.
An encapsulated private key.
A reference to a CKey: the Hash160 of its serialized public key.
int GetDepthInMainChain(const CBlockIndex *&pindexRet) const
Return depth of transaction in blockchain: <0 : conflicts with a transaction this deep in the blockch...
An outpoint - a combination of a transaction hash and an index n into its vout.
An encapsulated public key.
A key allocated from the key pool.
Serialized script, used inside transaction inputs and outputs.
Capture information about block/transaction validation.
std::string GetRejectReason() const
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,...
std::map< uint256, CWalletTx > mapWallet
std::map< CTxDestination, CAddressBookData > mapAddressBook
CCriticalSection cs_wallet
boost::signals2::signal< void(bool fHaveWatchOnly)> NotifyWatchonlyChanged
Watch-only address added.
bool BackupWallet(const std::string &strDest)
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.
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
bool EraseDestData(const CTxDestination &dest, const std::string &key)
Erases a destination data tuple in the store and on disk.
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.
boost::signals2::signal< void(CWallet *wallet, const uint256 &hashTx, ChangeType status)> NotifyTransactionChanged
Wallet transaction added, removed or updated.
A transaction with a bunch of additional info that only the owner cares about.
std::vector< std::pair< std::string, std::string > > vOrderForm
Interface from Qt to configuration data structure for Bitcoin client.
bool IsInitialized() const
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
bool fSubtractFeeFromAmount
UI model for the transaction table of a wallet.
void updateConfirmations()
UnlockContext(WalletModel *wallet, bool valid, bool relock)
void CopyFrom(const UnlockContext &rhs)
Interface to Bitcoin wallet from Qt view code.
CAmount cachedWatchUnconfBalance
CAmount cachedImmatureBalance
OptionsModel * optionsModel
bool validateAddress(const QString &address)
AddressTableModel * addressTableModel
void unlockCoin(COutPoint &output)
void loadReceiveRequests(std::vector< std::string > &vReceiveRequests)
EncryptionStatus cachedEncryptionStatus
WalletModel(const PlatformStyle *platformStyle, CWallet *wallet, OptionsModel *optionsModel, QObject *parent=0)
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
void encryptionStatusChanged(int status)
CAmount getUnconfirmedBalance() const
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
TransactionTableModel * transactionTableModel
void notifyWatchonlyChanged(bool fHaveWatchonly)
bool changePassphrase(const SecureString &oldPass, const SecureString &newPass)
CAmount getWatchUnconfirmedBalance() const
bool havePrivKey(const CKeyID &address) const
CAmount cachedWatchImmatureBalance
bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString())
CAmount getWatchBalance() const
void message(const QString &title, const QString &message, unsigned int style)
CAmount cachedWatchOnlyBalance
bool saveReceiveRequest(const std::string &sAddress, const int64_t nId, const std::string &sRequest)
AddressTableModel * getAddressTableModel()
SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const CCoinControl *coinControl=NULL)
CAmount cachedUnconfirmedBalance
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
bool haveWatchOnly() const
bool getPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
bool isLockedCoin(uint256 hash, unsigned int n) const
CAmount getImmatureBalance() const
void unsubscribeFromCoreSignals()
bool isSpent(const COutPoint &outpoint) const
void coinsSent(CWallet *wallet, SendCoinsRecipient recipient, QByteArray transaction)
void updateAddressBook(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
void checkBalanceChanged()
void updateWatchOnlyFlag(bool fHaveWatchonly)
void listCoins(std::map< QString, std::vector< COutput > > &mapCoins) const
UnlockContext requestUnlock()
static bool isWalletEnabled()
@ AmountWithFeeExceedsBalance
@ TransactionCreationFailed
@ TransactionCommitFailed
int getDefaultConfirmTarget() const
void subscribeToCoreSignals()
TransactionTableModel * getTransactionTableModel()
Data model for a walletmodel transaction.
void setTransactionFee(const CAmount &newFee)
CWalletTx * getTransaction()
void reassignAmounts(int nChangePosRet)
QList< SendCoinsRecipient > getRecipients()
CReserveKey * getPossibleKeyChange()
void newPossibleKeyChange(CWallet *wallet)
void UnlockCoin(const COutPoint &output)
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...
CAmount GetImmatureWatchOnlyBalance() const
bool CommitTransaction(CWalletTx &wtxNew, CReserveKey &reservekey, CConnman *connman, CValidationState &state)
Call after CreateTransaction unless you want to abort.
void ListLockedCoins(std::vector< COutPoint > &vOutpts)
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::string &purpose)
bool IsLockedCoin(uint256 hash, unsigned int n) const
CAmount GetImmatureBalance() const
CAmount GetUnconfirmedBalance() const
CAmount GetWatchOnlyBalance() const
CAmount GetBalance() const
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.
CAmount GetUnconfirmedWatchOnlyBalance() const
void LockCoin(const COutPoint &output)
bool Unlock(const SecureString &strWalletPassphrase)
bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
isminetype IsMine(const CTxIn &txin) const
bool IsSpent(const uint256 &hash, unsigned int n) const
Outpoint is spent if any non-conflicted transaction spends it:
bool AbandonTransaction(const uint256 &hashTx)
bool EncryptWallet(const SecureString &strWalletPassphrase)
bool IsChange(const CTxOut &txout) const
const CWalletTx * GetWalletTx(const uint256 &hash) const
std::unique_ptr< CConnman > g_connman
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
CScript GetScriptForDestination(const CTxDestination &dest)
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
#define TRY_LOCK(cs, name)
ChangeType
General change type (added, updated, removed).
bool GetBoolArg(const std::string &strArg, bool fDefault)
Return boolean argument or default value.
#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.
CAmount maxTxFee
Absolute maximum transaction fee (in satoshis) used by wallet and mempool (rejects high fee in sendra...
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
unsigned int nTxConfirmTarget