Merge #11247: qt: Use IsMine to validate custom change address
[bitcoinplatinum.git] / src / qt / walletmodel.cpp
bloba3f243a25f05e92386c3919d76d32245d78abc96
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.
5 #include "walletmodel.h"
7 #include "addresstablemodel.h"
8 #include "consensus/validation.h"
9 #include "guiconstants.h"
10 #include "guiutil.h"
11 #include "optionsmodel.h"
12 #include "paymentserver.h"
13 #include "recentrequeststablemodel.h"
14 #include "sendcoinsdialog.h"
15 #include "transactiontablemodel.h"
17 #include "base58.h"
18 #include "chain.h"
19 #include "keystore.h"
20 #include "validation.h"
21 #include "net.h" // for g_connman
22 #include "policy/fees.h"
23 #include "policy/rbf.h"
24 #include "sync.h"
25 #include "ui_interface.h"
26 #include "util.h" // for GetBoolArg
27 #include "wallet/coincontrol.h"
28 #include "wallet/feebumper.h"
29 #include "wallet/wallet.h"
30 #include "wallet/walletdb.h" // for BackupWallet
32 #include <stdint.h>
34 #include <QDebug>
35 #include <QMessageBox>
36 #include <QSet>
37 #include <QTimer>
40 WalletModel::WalletModel(const PlatformStyle *platformStyle, CWallet *_wallet, OptionsModel *_optionsModel, QObject *parent) :
41 QObject(parent), wallet(_wallet), optionsModel(_optionsModel), addressTableModel(0),
42 transactionTableModel(0),
43 recentRequestsTableModel(0),
44 cachedBalance(0), cachedUnconfirmedBalance(0), cachedImmatureBalance(0),
45 cachedEncryptionStatus(Unencrypted),
46 cachedNumBlocks(0)
48 fHaveWatchOnly = wallet->HaveWatchOnly();
49 fForceCheckBalanceChanged = false;
51 addressTableModel = new AddressTableModel(wallet, this);
52 transactionTableModel = new TransactionTableModel(platformStyle, wallet, this);
53 recentRequestsTableModel = new RecentRequestsTableModel(wallet, this);
55 // This timer will be fired repeatedly to update the balance
56 pollTimer = new QTimer(this);
57 connect(pollTimer, SIGNAL(timeout()), this, SLOT(pollBalanceChanged()));
58 pollTimer->start(MODEL_UPDATE_DELAY);
60 subscribeToCoreSignals();
63 WalletModel::~WalletModel()
65 unsubscribeFromCoreSignals();
68 CAmount WalletModel::getBalance(const CCoinControl *coinControl) const
70 if (coinControl)
72 return wallet->GetAvailableBalance(coinControl);
75 return wallet->GetBalance();
78 CAmount WalletModel::getUnconfirmedBalance() const
80 return wallet->GetUnconfirmedBalance();
83 CAmount WalletModel::getImmatureBalance() const
85 return wallet->GetImmatureBalance();
88 bool WalletModel::haveWatchOnly() const
90 return fHaveWatchOnly;
93 CAmount WalletModel::getWatchBalance() const
95 return wallet->GetWatchOnlyBalance();
98 CAmount WalletModel::getWatchUnconfirmedBalance() const
100 return wallet->GetUnconfirmedWatchOnlyBalance();
103 CAmount WalletModel::getWatchImmatureBalance() const
105 return wallet->GetImmatureWatchOnlyBalance();
108 void WalletModel::updateStatus()
110 EncryptionStatus newEncryptionStatus = getEncryptionStatus();
112 if(cachedEncryptionStatus != newEncryptionStatus)
113 Q_EMIT encryptionStatusChanged(newEncryptionStatus);
116 void WalletModel::pollBalanceChanged()
118 // Get required locks upfront. This avoids the GUI from getting stuck on
119 // periodical polls if the core is holding the locks for a longer time -
120 // for example, during a wallet rescan.
121 TRY_LOCK(cs_main, lockMain);
122 if(!lockMain)
123 return;
124 TRY_LOCK(wallet->cs_wallet, lockWallet);
125 if(!lockWallet)
126 return;
128 if(fForceCheckBalanceChanged || chainActive.Height() != cachedNumBlocks)
130 fForceCheckBalanceChanged = false;
132 // Balance and number of transactions might have changed
133 cachedNumBlocks = chainActive.Height();
135 checkBalanceChanged();
136 if(transactionTableModel)
137 transactionTableModel->updateConfirmations();
141 void WalletModel::checkBalanceChanged()
143 CAmount newBalance = getBalance();
144 CAmount newUnconfirmedBalance = getUnconfirmedBalance();
145 CAmount newImmatureBalance = getImmatureBalance();
146 CAmount newWatchOnlyBalance = 0;
147 CAmount newWatchUnconfBalance = 0;
148 CAmount newWatchImmatureBalance = 0;
149 if (haveWatchOnly())
151 newWatchOnlyBalance = getWatchBalance();
152 newWatchUnconfBalance = getWatchUnconfirmedBalance();
153 newWatchImmatureBalance = getWatchImmatureBalance();
156 if(cachedBalance != newBalance || cachedUnconfirmedBalance != newUnconfirmedBalance || cachedImmatureBalance != newImmatureBalance ||
157 cachedWatchOnlyBalance != newWatchOnlyBalance || cachedWatchUnconfBalance != newWatchUnconfBalance || cachedWatchImmatureBalance != newWatchImmatureBalance)
159 cachedBalance = newBalance;
160 cachedUnconfirmedBalance = newUnconfirmedBalance;
161 cachedImmatureBalance = newImmatureBalance;
162 cachedWatchOnlyBalance = newWatchOnlyBalance;
163 cachedWatchUnconfBalance = newWatchUnconfBalance;
164 cachedWatchImmatureBalance = newWatchImmatureBalance;
165 Q_EMIT balanceChanged(newBalance, newUnconfirmedBalance, newImmatureBalance,
166 newWatchOnlyBalance, newWatchUnconfBalance, newWatchImmatureBalance);
170 void WalletModel::updateTransaction()
172 // Balance and number of transactions might have changed
173 fForceCheckBalanceChanged = true;
176 void WalletModel::updateAddressBook(const QString &address, const QString &label,
177 bool isMine, const QString &purpose, int status)
179 if(addressTableModel)
180 addressTableModel->updateEntry(address, label, isMine, purpose, status);
183 void WalletModel::updateWatchOnlyFlag(bool fHaveWatchonly)
185 fHaveWatchOnly = fHaveWatchonly;
186 Q_EMIT notifyWatchonlyChanged(fHaveWatchonly);
189 bool WalletModel::validateAddress(const QString &address)
191 CBitcoinAddress addressParsed(address.toStdString());
192 return addressParsed.IsValid();
195 WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransaction &transaction, const CCoinControl& coinControl)
197 CAmount total = 0;
198 bool fSubtractFeeFromAmount = false;
199 QList<SendCoinsRecipient> recipients = transaction.getRecipients();
200 std::vector<CRecipient> vecSend;
202 if(recipients.empty())
204 return OK;
207 QSet<QString> setAddress; // Used to detect duplicates
208 int nAddresses = 0;
210 // Pre-check input data for validity
211 for (const SendCoinsRecipient &rcp : recipients)
213 if (rcp.fSubtractFeeFromAmount)
214 fSubtractFeeFromAmount = true;
216 if (rcp.paymentRequest.IsInitialized())
217 { // PaymentRequest...
218 CAmount subtotal = 0;
219 const payments::PaymentDetails& details = rcp.paymentRequest.getDetails();
220 for (int i = 0; i < details.outputs_size(); i++)
222 const payments::Output& out = details.outputs(i);
223 if (out.amount() <= 0) continue;
224 subtotal += out.amount();
225 const unsigned char* scriptStr = (const unsigned char*)out.script().data();
226 CScript scriptPubKey(scriptStr, scriptStr+out.script().size());
227 CAmount nAmount = out.amount();
228 CRecipient recipient = {scriptPubKey, nAmount, rcp.fSubtractFeeFromAmount};
229 vecSend.push_back(recipient);
231 if (subtotal <= 0)
233 return InvalidAmount;
235 total += subtotal;
237 else
238 { // User-entered bitcoin address / amount:
239 if(!validateAddress(rcp.address))
241 return InvalidAddress;
243 if(rcp.amount <= 0)
245 return InvalidAmount;
247 setAddress.insert(rcp.address);
248 ++nAddresses;
250 CScript scriptPubKey = GetScriptForDestination(CBitcoinAddress(rcp.address.toStdString()).Get());
251 CRecipient recipient = {scriptPubKey, rcp.amount, rcp.fSubtractFeeFromAmount};
252 vecSend.push_back(recipient);
254 total += rcp.amount;
257 if(setAddress.size() != nAddresses)
259 return DuplicateAddress;
262 CAmount nBalance = getBalance(&coinControl);
264 if(total > nBalance)
266 return AmountExceedsBalance;
270 LOCK2(cs_main, wallet->cs_wallet);
272 transaction.newPossibleKeyChange(wallet);
274 CAmount nFeeRequired = 0;
275 int nChangePosRet = -1;
276 std::string strFailReason;
278 CWalletTx *newTx = transaction.getTransaction();
279 CReserveKey *keyChange = transaction.getPossibleKeyChange();
280 bool fCreated = wallet->CreateTransaction(vecSend, *newTx, *keyChange, nFeeRequired, nChangePosRet, strFailReason, coinControl);
281 transaction.setTransactionFee(nFeeRequired);
282 if (fSubtractFeeFromAmount && fCreated)
283 transaction.reassignAmounts(nChangePosRet);
285 if(!fCreated)
287 if(!fSubtractFeeFromAmount && (total + nFeeRequired) > nBalance)
289 return SendCoinsReturn(AmountWithFeeExceedsBalance);
291 Q_EMIT message(tr("Send Coins"), QString::fromStdString(strFailReason),
292 CClientUIInterface::MSG_ERROR);
293 return TransactionCreationFailed;
296 // reject absurdly high fee. (This can never happen because the
297 // wallet caps the fee at maxTxFee. This merely serves as a
298 // belt-and-suspenders check)
299 if (nFeeRequired > maxTxFee)
300 return AbsurdFee;
303 return SendCoinsReturn(OK);
306 WalletModel::SendCoinsReturn WalletModel::sendCoins(WalletModelTransaction &transaction)
308 QByteArray transaction_array; /* store serialized transaction */
311 LOCK2(cs_main, wallet->cs_wallet);
312 CWalletTx *newTx = transaction.getTransaction();
314 for (const SendCoinsRecipient &rcp : transaction.getRecipients())
316 if (rcp.paymentRequest.IsInitialized())
318 // Make sure any payment requests involved are still valid.
319 if (PaymentServer::verifyExpired(rcp.paymentRequest.getDetails())) {
320 return PaymentRequestExpired;
323 // Store PaymentRequests in wtx.vOrderForm in wallet.
324 std::string key("PaymentRequest");
325 std::string value;
326 rcp.paymentRequest.SerializeToString(&value);
327 newTx->vOrderForm.push_back(make_pair(key, value));
329 else if (!rcp.message.isEmpty()) // Message from normal bitcoin:URI (bitcoin:123...?message=example)
330 newTx->vOrderForm.push_back(make_pair("Message", rcp.message.toStdString()));
333 CReserveKey *keyChange = transaction.getPossibleKeyChange();
334 CValidationState state;
335 if(!wallet->CommitTransaction(*newTx, *keyChange, g_connman.get(), state))
336 return SendCoinsReturn(TransactionCommitFailed, QString::fromStdString(state.GetRejectReason()));
338 CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
339 ssTx << *newTx->tx;
340 transaction_array.append(&(ssTx[0]), ssTx.size());
343 // Add addresses / update labels that we've sent to the address book,
344 // and emit coinsSent signal for each recipient
345 for (const SendCoinsRecipient &rcp : transaction.getRecipients())
347 // Don't touch the address book when we have a payment request
348 if (!rcp.paymentRequest.IsInitialized())
350 std::string strAddress = rcp.address.toStdString();
351 CTxDestination dest = CBitcoinAddress(strAddress).Get();
352 std::string strLabel = rcp.label.toStdString();
354 LOCK(wallet->cs_wallet);
356 std::map<CTxDestination, CAddressBookData>::iterator mi = wallet->mapAddressBook.find(dest);
358 // Check if we have a new address or an updated label
359 if (mi == wallet->mapAddressBook.end())
361 wallet->SetAddressBook(dest, strLabel, "send");
363 else if (mi->second.name != strLabel)
365 wallet->SetAddressBook(dest, strLabel, ""); // "" means don't change purpose
369 Q_EMIT coinsSent(wallet, rcp, transaction_array);
371 checkBalanceChanged(); // update balance immediately, otherwise there could be a short noticeable delay until pollBalanceChanged hits
373 return SendCoinsReturn(OK);
376 OptionsModel *WalletModel::getOptionsModel()
378 return optionsModel;
381 AddressTableModel *WalletModel::getAddressTableModel()
383 return addressTableModel;
386 TransactionTableModel *WalletModel::getTransactionTableModel()
388 return transactionTableModel;
391 RecentRequestsTableModel *WalletModel::getRecentRequestsTableModel()
393 return recentRequestsTableModel;
396 WalletModel::EncryptionStatus WalletModel::getEncryptionStatus() const
398 if(!wallet->IsCrypted())
400 return Unencrypted;
402 else if(wallet->IsLocked())
404 return Locked;
406 else
408 return Unlocked;
412 bool WalletModel::setWalletEncrypted(bool encrypted, const SecureString &passphrase)
414 if(encrypted)
416 // Encrypt
417 return wallet->EncryptWallet(passphrase);
419 else
421 // Decrypt -- TODO; not supported yet
422 return false;
426 bool WalletModel::setWalletLocked(bool locked, const SecureString &passPhrase)
428 if(locked)
430 // Lock
431 return wallet->Lock();
433 else
435 // Unlock
436 return wallet->Unlock(passPhrase);
440 bool WalletModel::changePassphrase(const SecureString &oldPass, const SecureString &newPass)
442 bool retval;
444 LOCK(wallet->cs_wallet);
445 wallet->Lock(); // Make sure wallet is locked before attempting pass change
446 retval = wallet->ChangeWalletPassphrase(oldPass, newPass);
448 return retval;
451 bool WalletModel::backupWallet(const QString &filename)
453 return wallet->BackupWallet(filename.toLocal8Bit().data());
456 // Handlers for core signals
457 static void NotifyKeyStoreStatusChanged(WalletModel *walletmodel, CCryptoKeyStore *wallet)
459 qDebug() << "NotifyKeyStoreStatusChanged";
460 QMetaObject::invokeMethod(walletmodel, "updateStatus", Qt::QueuedConnection);
463 static void NotifyAddressBookChanged(WalletModel *walletmodel, CWallet *wallet,
464 const CTxDestination &address, const std::string &label, bool isMine,
465 const std::string &purpose, ChangeType status)
467 QString strAddress = QString::fromStdString(CBitcoinAddress(address).ToString());
468 QString strLabel = QString::fromStdString(label);
469 QString strPurpose = QString::fromStdString(purpose);
471 qDebug() << "NotifyAddressBookChanged: " + strAddress + " " + strLabel + " isMine=" + QString::number(isMine) + " purpose=" + strPurpose + " status=" + QString::number(status);
472 QMetaObject::invokeMethod(walletmodel, "updateAddressBook", Qt::QueuedConnection,
473 Q_ARG(QString, strAddress),
474 Q_ARG(QString, strLabel),
475 Q_ARG(bool, isMine),
476 Q_ARG(QString, strPurpose),
477 Q_ARG(int, status));
480 static void NotifyTransactionChanged(WalletModel *walletmodel, CWallet *wallet, const uint256 &hash, ChangeType status)
482 Q_UNUSED(wallet);
483 Q_UNUSED(hash);
484 Q_UNUSED(status);
485 QMetaObject::invokeMethod(walletmodel, "updateTransaction", Qt::QueuedConnection);
488 static void ShowProgress(WalletModel *walletmodel, const std::string &title, int nProgress)
490 // emits signal "showProgress"
491 QMetaObject::invokeMethod(walletmodel, "showProgress", Qt::QueuedConnection,
492 Q_ARG(QString, QString::fromStdString(title)),
493 Q_ARG(int, nProgress));
496 static void NotifyWatchonlyChanged(WalletModel *walletmodel, bool fHaveWatchonly)
498 QMetaObject::invokeMethod(walletmodel, "updateWatchOnlyFlag", Qt::QueuedConnection,
499 Q_ARG(bool, fHaveWatchonly));
502 void WalletModel::subscribeToCoreSignals()
504 // Connect signals to wallet
505 wallet->NotifyStatusChanged.connect(boost::bind(&NotifyKeyStoreStatusChanged, this, _1));
506 wallet->NotifyAddressBookChanged.connect(boost::bind(NotifyAddressBookChanged, this, _1, _2, _3, _4, _5, _6));
507 wallet->NotifyTransactionChanged.connect(boost::bind(NotifyTransactionChanged, this, _1, _2, _3));
508 wallet->ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2));
509 wallet->NotifyWatchonlyChanged.connect(boost::bind(NotifyWatchonlyChanged, this, _1));
512 void WalletModel::unsubscribeFromCoreSignals()
514 // Disconnect signals from wallet
515 wallet->NotifyStatusChanged.disconnect(boost::bind(&NotifyKeyStoreStatusChanged, this, _1));
516 wallet->NotifyAddressBookChanged.disconnect(boost::bind(NotifyAddressBookChanged, this, _1, _2, _3, _4, _5, _6));
517 wallet->NotifyTransactionChanged.disconnect(boost::bind(NotifyTransactionChanged, this, _1, _2, _3));
518 wallet->ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2));
519 wallet->NotifyWatchonlyChanged.disconnect(boost::bind(NotifyWatchonlyChanged, this, _1));
522 // WalletModel::UnlockContext implementation
523 WalletModel::UnlockContext WalletModel::requestUnlock()
525 bool was_locked = getEncryptionStatus() == Locked;
526 if(was_locked)
528 // Request UI to unlock wallet
529 Q_EMIT requireUnlock();
531 // If wallet is still locked, unlock was failed or cancelled, mark context as invalid
532 bool valid = getEncryptionStatus() != Locked;
534 return UnlockContext(this, valid, was_locked);
537 WalletModel::UnlockContext::UnlockContext(WalletModel *_wallet, bool _valid, bool _relock):
538 wallet(_wallet),
539 valid(_valid),
540 relock(_relock)
544 WalletModel::UnlockContext::~UnlockContext()
546 if(valid && relock)
548 wallet->setWalletLocked(true);
552 void WalletModel::UnlockContext::CopyFrom(const UnlockContext& rhs)
554 // Transfer context; old object no longer relocks wallet
555 *this = rhs;
556 rhs.relock = false;
559 bool WalletModel::getPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const
561 return wallet->GetPubKey(address, vchPubKeyOut);
564 bool WalletModel::IsSpendable(const CTxDestination& dest) const
566 return IsMine(*wallet, dest) & ISMINE_SPENDABLE;
569 bool WalletModel::getPrivKey(const CKeyID &address, CKey& vchPrivKeyOut) const
571 return wallet->GetKey(address, vchPrivKeyOut);
574 // returns a list of COutputs from COutPoints
575 void WalletModel::getOutputs(const std::vector<COutPoint>& vOutpoints, std::vector<COutput>& vOutputs)
577 LOCK2(cs_main, wallet->cs_wallet);
578 for (const COutPoint& outpoint : vOutpoints)
580 auto it = wallet->mapWallet.find(outpoint.hash);
581 if (it == wallet->mapWallet.end()) continue;
582 int nDepth = it->second.GetDepthInMainChain();
583 if (nDepth < 0) continue;
584 COutput out(&it->second, outpoint.n, nDepth, true /* spendable */, true /* solvable */, true /* safe */);
585 vOutputs.push_back(out);
589 bool WalletModel::isSpent(const COutPoint& outpoint) const
591 LOCK2(cs_main, wallet->cs_wallet);
592 return wallet->IsSpent(outpoint.hash, outpoint.n);
595 // AvailableCoins + LockedCoins grouped by wallet address (put change in one group with wallet address)
596 void WalletModel::listCoins(std::map<QString, std::vector<COutput> >& mapCoins) const
598 for (auto& group : wallet->ListCoins()) {
599 auto& resultGroup = mapCoins[QString::fromStdString(CBitcoinAddress(group.first).ToString())];
600 for (auto& coin : group.second) {
601 resultGroup.emplace_back(std::move(coin));
606 bool WalletModel::isLockedCoin(uint256 hash, unsigned int n) const
608 LOCK2(cs_main, wallet->cs_wallet);
609 return wallet->IsLockedCoin(hash, n);
612 void WalletModel::lockCoin(COutPoint& output)
614 LOCK2(cs_main, wallet->cs_wallet);
615 wallet->LockCoin(output);
618 void WalletModel::unlockCoin(COutPoint& output)
620 LOCK2(cs_main, wallet->cs_wallet);
621 wallet->UnlockCoin(output);
624 void WalletModel::listLockedCoins(std::vector<COutPoint>& vOutpts)
626 LOCK2(cs_main, wallet->cs_wallet);
627 wallet->ListLockedCoins(vOutpts);
630 void WalletModel::loadReceiveRequests(std::vector<std::string>& vReceiveRequests)
632 vReceiveRequests = wallet->GetDestValues("rr"); // receive request
635 bool WalletModel::saveReceiveRequest(const std::string &sAddress, const int64_t nId, const std::string &sRequest)
637 CTxDestination dest = CBitcoinAddress(sAddress).Get();
639 std::stringstream ss;
640 ss << nId;
641 std::string key = "rr" + ss.str(); // "rr" prefix = "receive request" in destdata
643 LOCK(wallet->cs_wallet);
644 if (sRequest.empty())
645 return wallet->EraseDestData(dest, key);
646 else
647 return wallet->AddDestData(dest, key, sRequest);
650 bool WalletModel::transactionCanBeAbandoned(uint256 hash) const
652 return wallet->TransactionCanBeAbandoned(hash);
655 bool WalletModel::abandonTransaction(uint256 hash) const
657 LOCK2(cs_main, wallet->cs_wallet);
658 return wallet->AbandonTransaction(hash);
661 bool WalletModel::transactionCanBeBumped(uint256 hash) const
663 LOCK2(cs_main, wallet->cs_wallet);
664 const CWalletTx *wtx = wallet->GetWalletTx(hash);
665 return wtx && SignalsOptInRBF(*wtx) && !wtx->mapValue.count("replaced_by_txid");
668 bool WalletModel::bumpFee(uint256 hash)
670 std::unique_ptr<CFeeBumper> feeBump;
672 CCoinControl coin_control;
673 coin_control.signalRbf = true;
674 LOCK2(cs_main, wallet->cs_wallet);
675 feeBump.reset(new CFeeBumper(wallet, hash, coin_control, 0));
677 if (feeBump->getResult() != BumpFeeResult::OK)
679 QMessageBox::critical(0, tr("Fee bump error"), tr("Increasing transaction fee failed") + "<br />(" +
680 (feeBump->getErrors().size() ? QString::fromStdString(feeBump->getErrors()[0]) : "") +")");
681 return false;
684 // allow a user based fee verification
685 QString questionString = tr("Do you want to increase the fee?");
686 questionString.append("<br />");
687 CAmount oldFee = feeBump->getOldFee();
688 CAmount newFee = feeBump->getNewFee();
689 questionString.append("<table style=\"text-align: left;\">");
690 questionString.append("<tr><td>");
691 questionString.append(tr("Current fee:"));
692 questionString.append("</td><td>");
693 questionString.append(BitcoinUnits::formatHtmlWithUnit(getOptionsModel()->getDisplayUnit(), oldFee));
694 questionString.append("</td></tr><tr><td>");
695 questionString.append(tr("Increase:"));
696 questionString.append("</td><td>");
697 questionString.append(BitcoinUnits::formatHtmlWithUnit(getOptionsModel()->getDisplayUnit(), newFee - oldFee));
698 questionString.append("</td></tr><tr><td>");
699 questionString.append(tr("New fee:"));
700 questionString.append("</td><td>");
701 questionString.append(BitcoinUnits::formatHtmlWithUnit(getOptionsModel()->getDisplayUnit(), newFee));
702 questionString.append("</td></tr></table>");
703 SendConfirmationDialog confirmationDialog(tr("Confirm fee bump"), questionString);
704 confirmationDialog.exec();
705 QMessageBox::StandardButton retval = (QMessageBox::StandardButton)confirmationDialog.result();
707 // cancel sign&broadcast if users doesn't want to bump the fee
708 if (retval != QMessageBox::Yes) {
709 return false;
712 WalletModel::UnlockContext ctx(requestUnlock());
713 if(!ctx.isValid())
715 return false;
718 // sign bumped transaction
719 bool res = false;
721 LOCK2(cs_main, wallet->cs_wallet);
722 res = feeBump->signTransaction(wallet);
724 if (!res) {
725 QMessageBox::critical(0, tr("Fee bump error"), tr("Can't sign transaction."));
726 return false;
728 // commit the bumped transaction
730 LOCK2(cs_main, wallet->cs_wallet);
731 res = feeBump->commit(wallet);
733 if(!res) {
734 QMessageBox::critical(0, tr("Fee bump error"), tr("Could not commit transaction") + "<br />(" +
735 QString::fromStdString(feeBump->getErrors()[0])+")");
736 return false;
738 return true;
741 bool WalletModel::isWalletEnabled()
743 return !gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET);
746 bool WalletModel::hdEnabled() const
748 return wallet->IsHDEnabled();
751 int WalletModel::getDefaultConfirmTarget() const
753 return nTxConfirmTarget;
756 bool WalletModel::getDefaultWalletRbf() const
758 return fWalletRbf;