37 #include <QMessageBox> 43 QObject(parent), wallet(_wallet), optionsModel(_optionsModel), addressTableModel(0),
44 transactionTableModel(0),
46 recentRequestsTableModel(0),
47 cachedBalance(0), cachedUnconfirmedBalance(0), cachedImmatureBalance(0),
48 cachedEncryptionStatus(Unencrypted),
152 CAmount newWatchOnlyBalance = 0;
153 CAmount newWatchUnconfBalance = 0;
154 CAmount newWatchImmatureBalance = 0;
171 Q_EMIT
balanceChanged(newBalance, newUnconfirmedBalance, newImmatureBalance,
172 newWatchOnlyBalance, newWatchUnconfBalance, newWatchImmatureBalance);
183 bool isMine,
const QString &purpose,
int status)
203 bool fSubtractFeeFromAmount =
false;
204 QList<SendCoinsRecipient> recipients = transaction.
getRecipients();
205 std::vector<CRecipient> vecSend;
207 if(recipients.empty())
212 QSet<QString> setAddress;
218 if (rcp.fSubtractFeeFromAmount)
219 fSubtractFeeFromAmount =
true;
221 if (rcp.paymentRequest.IsInitialized())
224 const payments::PaymentDetails& details = rcp.paymentRequest.getDetails();
225 for (
int i = 0; i < details.outputs_size(); i++)
227 const payments::Output& out = details.outputs(i);
228 if (out.amount() <= 0)
continue;
229 subtotal += out.amount();
230 const unsigned char* scriptStr = (
const unsigned char*)out.script().data();
231 CScript scriptPubKey(scriptStr, scriptStr+out.script().size());
232 CAmount nAmount = out.amount();
234 vecSend.push_back(recipient);
252 setAddress.insert(rcp.address);
256 CRecipient recipient = {scriptPubKey, rcp.amount, rcp.fSubtractFeeFromAmount};
262 if(setAddress.size() != nAddresses)
280 int nChangePosRet = -1;
281 std::string strFailReason;
285 bool fCreated =
wallet->
CreateTransaction(vecSend, *newTx, *keyChange, nFeeRequired, nChangePosRet, strFailReason, coinControl);
287 if (fSubtractFeeFromAmount && fCreated)
292 if(!fSubtractFeeFromAmount && (total + nFeeRequired) > nBalance)
296 Q_EMIT
message(tr(
"Send Coins"), QString::fromStdString(strFailReason),
313 QByteArray transaction_array;
321 if (rcp.paymentRequest.IsInitialized())
329 std::string key(
"PaymentRequest");
331 rcp.paymentRequest.SerializeToString(&value);
332 newTx->
vOrderForm.push_back(make_pair(key, value));
334 else if (!rcp.message.isEmpty())
335 newTx->
vOrderForm.push_back(make_pair(
"Message", rcp.message.toStdString()));
345 transaction_array.append(&(ssTx[0]), ssTx.
size());
353 if (!rcp.paymentRequest.IsInitialized())
355 std::string strAddress = rcp.address.toStdString();
357 std::string strLabel = rcp.label.toStdString();
368 else if (mi->second.name != strLabel)
383 QByteArray transaction_array;
388 std::pair<int, std::string>
error;
395 transaction_array.append(&(ssTx[0]), ssTx.
size());
403 if (!rcp.paymentRequest.IsInitialized())
405 std::string strAddress = rcp.address.toStdString();
407 std::string strLabel = rcp.label.toStdString();
418 else if (mi->second.name != strLabel)
519 qDebug() <<
"NotifyKeyStoreStatusChanged";
520 QMetaObject::invokeMethod(walletmodel,
"updateStatus", Qt::QueuedConnection);
524 const CTxDestination &address,
const std::string &label,
bool isMine,
525 const std::string &purpose,
ChangeType status)
528 QString strLabel = QString::fromStdString(label);
529 QString strPurpose = QString::fromStdString(purpose);
531 qDebug() <<
"NotifyAddressBookChanged: " + strAddress +
" " + strLabel +
" isMine=" + QString::number(isMine) +
" purpose=" + strPurpose +
" status=" + QString::number(status);
532 QMetaObject::invokeMethod(walletmodel,
"updateAddressBook", Qt::QueuedConnection,
533 Q_ARG(QString, strAddress),
534 Q_ARG(QString, strLabel),
536 Q_ARG(QString, strPurpose),
545 QMetaObject::invokeMethod(walletmodel,
"updateTransaction", Qt::QueuedConnection);
548 static void ShowProgress(
WalletModel *walletmodel,
const std::string &title,
int nProgress)
551 QMetaObject::invokeMethod(walletmodel,
"showProgress", Qt::QueuedConnection,
552 Q_ARG(QString, QString::fromStdString(title)),
553 Q_ARG(
int, nProgress));
556 static void NotifyWatchonlyChanged(
WalletModel *walletmodel,
bool fHaveWatchonly)
558 QMetaObject::invokeMethod(walletmodel,
"updateWatchOnlyFlag", Qt::QueuedConnection,
559 Q_ARG(
bool, fHaveWatchonly));
568 wallet->
ShowProgress.connect(boost::bind(ShowProgress,
this, _1, _2));
575 wallet->
NotifyStatusChanged.disconnect(boost::bind(&NotifyKeyStoreStatusChanged,
this, _1));
578 wallet->
ShowProgress.disconnect(boost::bind(ShowProgress,
this, _1, _2));
608 wallet->setWalletLocked(
true);
621 return wallet->
GetPubKey(address, vchPubKeyOut);
631 return wallet->
GetKey(address, vchPrivKeyOut);
638 for (
const COutPoint& outpoint : vOutpoints)
640 auto it = wallet->
mapWallet.find(outpoint.hash);
641 if (it == wallet->
mapWallet.end())
continue;
642 int nDepth = it->second.GetDepthInMainChain();
643 if (nDepth < 0)
continue;
644 COutput out(&it->second, outpoint.n, nDepth,
true ,
true ,
true );
645 vOutputs.push_back(out);
658 for (
auto& group : wallet->
ListCoins()) {
659 auto& resultGroup = mapCoins[QString::fromStdString(
EncodeDestination(group.first))];
660 for (
auto& coin : group.second) {
661 resultGroup.emplace_back(std::move(coin));
670 std::map<QString, std::map<QString, std::vector<COutput> > > mapSortedByAssetName;
673 for (
auto& group : list) {
676 for (
auto& coin : group.second) {
677 auto out = coin.tx->tx->vout[coin.i];
678 std::string strAssetName;
686 QString assetName = QString::fromStdString(strAssetName);
687 auto& assetMap = mapCoins[assetName];
688 assetMap[address].emplace_back(coin);
727 std::stringstream ss;
729 std::string key =
"rr" + ss.str();
732 if (sRequest.empty())
bool abandonTransaction(uint256 hash) const
void loadReceiveRequests(std::vector< std::string > &vReceiveRequests)
bool isLockedCoin(uint256 hash, unsigned int n) const
RVN END.
void listCoins(std::map< QString, std::vector< COutput > > &mapCoins) const
Model for list of recently generated payment requests / raven: URIs.
TransactionTableModel * transactionTableModel
void getOutputs(const std::vector< COutPoint > &vOutpoints, std::vector< COutput > &vOutputs)
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
RecentRequestsTableModel * recentRequestsTableModel
CAmount GetImmatureBalance() const
void lockCoin(COutPoint &output)
CWalletTx * getTransaction() const
#define TRY_LOCK(cs, name)
static bool isWalletEnabled()
CAmount GetAvailableBalance(const CCoinControl *coinControl=nullptr) const
std::map< CTxDestination, CAddressBookData > mapAddressBook
std::vector< std::string > GetDestValues(const std::string &prefix) const
Get all destination values matching a prefix.
CCriticalSection cs_wallet
CAmount maxTxFee
Absolute maximum transaction fee (in satoshis) used by wallet and mempool (rejects high fee in sendra...
UnlockContext requestUnlock()
void unsubscribeFromCoreSignals()
bool bumpFee(uint256 hash)
int Height() const
Return the maximal height in the chain.
CCriticalSection cs_main
Global state.
CTxDestination DecodeDestination(const std::string &str)
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
bool backupWallet(const QString &filename)
SendCoinsReturn sendCoins(WalletModelTransaction &transaction)
isminetype IsMine(const CKeyStore &keystore, const CScript &scriptPubKey, SigVersion sigversion)
bool transactionCanBeAbandoned(uint256 hash) const
QList< SendCoinsRecipient > getRecipients() const
void assetsSent(CWallet *wallet, SendAssetsRecipient recipient, QByteArray transaction)
std::map< CTxDestination, std::vector< COutput > > ListAssets() const
Return list of available assets and locked assets grouped by non-change output address.
bool fSubtractFeeFromAmount
Double ended buffer combining vector and stream-like interfaces.
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
CAmount GetUnconfirmedWatchOnlyBalance() const
AddressTableModel * getAddressTableModel()
Keystore which keeps the private keys encrypted.
bool EncryptWallet(const SecureString &strWalletPassphrase)
AssetTableModel * assetTableModel
bool IsSpent(const uint256 &hash, unsigned int n) const
Outpoint is spent if any non-conflicted transaction spends it:
CAmount GetBalance() const
bool haveWatchOnly() const
void newPossibleKeyChange(CWallet *wallet)
bool GetPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const override
EncryptionStatus getEncryptionStatus() const
CAmount getBalance(const CCoinControl *coinControl=nullptr) const
void setTransactionFee(const CAmount &newFee)
void checkBalanceChanged()
UnlockContext(WalletModel *wallet, bool valid, bool relock)
int64_t CAmount
Amount in corbies (Can be negative)
boost::signals2::signal< void(CWallet *wallet, const uint256 &hashTx, ChangeType status)> NotifyTransactionChanged
Wallet transaction added, removed or updated.
CAmount getImmatureBalance() const
bool CreateTransaction(const std::vector< CRecipient > &vecSend, CWalletTx &wtxNew, CReserveKey &reservekey, CAmount &nFeeRet, int &nChangePosInOut, std::string &strFailReason, const CCoinControl &coin_control, bool sign=true)
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::string &purpose)
boost::signals2::signal< void(CCryptoKeyStore *wallet)> NotifyStatusChanged
Wallet status (encrypted, locked) changed.
void checkBalanceChanged()
bool getPubKey(const CKeyID &address, CPubKey &vchPubKeyOut) const
void push_back(const T &value)
unsigned int nTxConfirmTarget
bool transactionCanBeBumped(uint256 hash) const
bool IsValidDestinationString(const std::string &str, const CChainParams ¶ms)
Models assets portion of wallet as table of owned assets.
bool AbandonTransaction(const uint256 &hashTx)
void UnlockCoin(const COutPoint &output)
CAmount cachedImmatureBalance
ChangeType
General change type (added, updated, removed).
bool getPrivKey(const CKeyID &address, CKey &vchPrivKeyOut) const
bool changePassphrase(const SecureString &oldPass, const SecureString &newPass)
void reassignAmounts(int nChangePosRet)
int getDefaultConfirmTarget() const
CAmount getWatchUnconfirmedBalance() const
An encapsulated public key.
bool TransactionCanBeAbandoned(const uint256 &hashTx) const
Return whether transaction can be abandoned.
bool IsLockedCoin(uint256 hash, unsigned int n) const
std::string GetRejectReason() const
CAmount GetUnconfirmedBalance() const
SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const CCoinControl &coinControl)
CAmount GetImmatureWatchOnlyBalance() const
static bool verifyExpired(const payments::PaymentDetails &requestDetails)
bool EraseDestData(const CTxDestination &dest, const std::string &key)
Erases a destination data tuple in the store and on disk.
bool GetAssetInfoFromScript(const CScript &scriptPubKey, std::string &strName, CAmount &nAmount)
bool isSpent(const COutPoint &outpoint) const
bool GetKey(const CKeyID &address, CKey &keyOut) const override
OptionsModel * optionsModel
CAmount cachedWatchOnlyBalance
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Raven scriptPubKey for the given CTxDestination.
TransactionTableModel * getTransactionTableModel()
EncryptionStatus cachedEncryptionStatus
An outpoint - a combination of a transaction hash and an index n into its vout.
void CopyFrom(const UnlockContext &rhs)
UI model for the transaction table of a wallet.
bool SendAssetTransaction(CWallet *pwallet, CWalletTx &transaction, CReserveKey &reserveKey, std::pair< int, std::string > &error, std::string &txid)
Send any type of asset transaction to the network.
void LockCoin(const COutPoint &output)
Qt model of the address book in the core.
AssetTableModel * getAssetTableModel()
bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString())
A transaction with a bunch of additional info that only the owner cares about.
void encryptionStatusChanged(int status)
CAmount GetWatchOnlyBalance() const
bool validateAddress(const QString &address)
WalletModel(const PlatformStyle *platformStyle, CWallet *wallet, OptionsModel *optionsModel, QObject *parent=0)
void updateWatchOnlyFlag(bool fHaveWatchonly)
CReserveKey * getPossibleKeyChange()
CAmount cachedWatchUnconfBalance
bool fForceCheckBalanceChanged
CAmount cachedWatchImmatureBalance
std::map< CTxDestination, std::vector< COutput > > ListCoins() const
Return list of available coins and locked coins grouped by non-change output address.
std::string EncodeDestination(const CTxDestination &dest)
RecentRequestsTableModel * getRecentRequestsTableModel()
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.
bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
void listLockedCoins(std::vector< COutPoint > &vOutpts)
A key allocated from the key pool.
Interface from Qt to configuration data structure for Raven client.
Serialized script, used inside transaction inputs and outputs.
Interface to Raven wallet from Qt view code.
CAmount getWatchBalance() const
CAmount getUnconfirmedBalance() const
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.
CAmount cachedUnconfirmedBalance
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
std::unique_ptr< CConnman > g_connman
void notifyWatchonlyChanged(bool fHaveWatchonly)
Data model for a walletmodel transaction.
void coinsSent(CWallet *wallet, SendCoinsRecipient recipient, QByteArray transaction)
bool error(const char *fmt, const Args &... args)
std::map< uint256, CWalletTx > mapWallet
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
bool getDefaultWalletRbf() const
AddressTableModel * addressTableModel
CAmount getWatchImmatureBalance() const
void listAssets(std::map< QString, std::map< QString, std::vector< COutput > > > &mapCoins) const
RVN START.
SendCoinsReturn sendAssets(CWalletTx &tx, QList< SendAssetsRecipient > &recipients, CReserveKey &reservekey)
An encapsulated private key.
bool HaveWatchOnly(const CScript &dest) const override
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.
void ListLockedCoins(std::vector< COutPoint > &vOutpts) const
CWallet * getWallet() const
bool BackupWallet(const std::string &strDest)
void updateConfirmations()
bool saveReceiveRequest(const std::string &sAddress, const int64_t nId, const std::string &sRequest)
boost::signals2::signal< void(bool fHaveWatchOnly)> NotifyWatchonlyChanged
Watch-only address added.
void updateAddressBook(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
void updateEntry(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
void balanceChanged(const CAmount &balance, const CAmount &unconfirmedBalance, const CAmount &immatureBalance, const CAmount &watchOnlyBalance, const CAmount &watchUnconfBalance, const CAmount &watchImmatureBalance)
void pollBalanceChanged()
OptionsModel * getOptionsModel()
bool Unlock(const SecureString &strWalletPassphrase)
void subscribeToCoreSignals()
bool IsSpendable(const CTxDestination &dest) const
std::vector< std::pair< std::string, std::string > > vOrderForm
bool CommitTransaction(CWalletTx &wtxNew, CReserveKey &reservekey, CConnman *connman, CValidationState &state)
RVN END.