5 #if defined(HAVE_CONFIG_H)
34 #include <QMessageBox>
42 m_client_model(&client_model),
43 m_node(client_model.node()),
44 optionsModel(client_model.getOptionsModel()),
45 addressTableModel(nullptr),
46 transactionTableModel(nullptr),
47 recentRequestsTableModel(nullptr),
48 cachedEncryptionStatus(Unencrypted),
49 timer(new QTimer(this))
98 if (!
m_wallet->tryGetBalances(new_balances, block_hash)) {
129 bool isMine,
const QString &purpose,
int status)
149 bool fSubtractFeeFromAmount =
false;
150 QList<SendCoinsRecipient> recipients = transaction.
getRecipients();
151 std::vector<CRecipient> vecSend;
153 if(recipients.empty())
158 QSet<QString> setAddress;
164 if (rcp.fSubtractFeeFromAmount)
165 fSubtractFeeFromAmount =
true;
175 setAddress.insert(rcp.address);
179 CRecipient recipient = {scriptPubKey, rcp.amount, rcp.fSubtractFeeFromAmount};
180 vecSend.push_back(recipient);
185 if(setAddress.size() != nAddresses)
199 int nChangePosRet = -1;
202 auto& newTx = transaction.
getWtx();
203 newTx =
m_wallet->createTransaction(vecSend, coinControl, !
wallet().privateKeysDisabled() , nChangePosRet, nFeeRequired, error);
205 if (fSubtractFeeFromAmount && newTx)
210 if(!fSubtractFeeFromAmount && (total + nFeeRequired) > nBalance)
222 if (nFeeRequired >
m_wallet->getDefaultMaxTxFee()) {
232 QByteArray transaction_array;
235 std::vector<std::pair<std::string, std::string>> vOrderForm;
238 if (!rcp.message.isEmpty())
239 vOrderForm.emplace_back(
"Message", rcp.message.toStdString());
242 auto& newTx = transaction.
getWtx();
247 transaction_array.append(&(ssTx[0]), ssTx.
size());
255 std::string strAddress = rcp.address.toStdString();
257 std::string strLabel = rcp.label.toStdString();
262 dest, &name,
nullptr,
nullptr))
264 m_wallet->setAddressBook(dest, strLabel,
"send");
266 else if (name != strLabel)
268 m_wallet->setAddressBook(dest, strLabel,
"");
272 Q_EMIT
coinsSent(
this, rcp, transaction_array);
319 return m_wallet->encryptWallet(passphrase);
334 return m_wallet->unlock(passPhrase);
341 return m_wallet->changeWalletPassphrase(oldPass, newPass);
347 qDebug() <<
"NotifyUnload";
348 bool invoked = QMetaObject::invokeMethod(walletModel,
"unload");
354 qDebug() <<
"NotifyKeyStoreStatusChanged";
355 bool invoked = QMetaObject::invokeMethod(walletmodel,
"updateStatus", Qt::QueuedConnection);
360 const CTxDestination &address,
const std::string &label,
bool isMine,
361 const std::string &purpose,
ChangeType status)
364 QString strLabel = QString::fromStdString(label);
365 QString strPurpose = QString::fromStdString(purpose);
367 qDebug() <<
"NotifyAddressBookChanged: " + strAddress +
" " + strLabel +
" isMine=" + QString::number(isMine) +
" purpose=" + strPurpose +
" status=" + QString::number(status);
368 bool invoked = QMetaObject::invokeMethod(walletmodel,
"updateAddressBook", Qt::QueuedConnection,
369 Q_ARG(QString, strAddress),
370 Q_ARG(QString, strLabel),
372 Q_ARG(QString, strPurpose),
381 bool invoked = QMetaObject::invokeMethod(walletmodel,
"updateTransaction", Qt::QueuedConnection);
388 bool invoked = QMetaObject::invokeMethod(walletmodel,
"showProgress", Qt::QueuedConnection,
389 Q_ARG(QString, QString::fromStdString(title)),
390 Q_ARG(
int, nProgress));
396 bool invoked = QMetaObject::invokeMethod(walletmodel,
"updateWatchOnlyFlag", Qt::QueuedConnection,
397 Q_ARG(
bool, fHaveWatchonly));
403 bool invoked = QMetaObject::invokeMethod(walletmodel,
"canGetAddressesChanged");
457 wallet->setWalletLocked(
true);
470 vReceiveRequests =
m_wallet->getDestValues(
"rr");
477 std::stringstream ss;
479 std::string key =
"rr" + ss.str();
481 if (sRequest.empty())
482 return m_wallet->eraseDestData(dest, key);
484 return m_wallet->addDestData(dest, key, sRequest);
491 std::vector<bilingual_str> errors;
495 if (!
m_wallet->createBumpTransaction(hash, coin_control, errors, old_fee, new_fee, mtx)) {
496 QMessageBox::critical(
nullptr, tr(
"Fee bump error"), tr(
"Increasing transaction fee failed") +
"<br />(" +
497 (errors.size() ? QString::fromStdString(errors[0].translated) :
"") +
")");
501 const bool create_psbt =
m_wallet->privateKeysDisabled();
504 QString questionString = create_psbt ? tr(
"Do you want to draft a transaction with fee increase?") : tr(
"Do you want to increase the fee?");
505 questionString.append(
"<br />");
506 questionString.append(
"<table style=\"text-align: left;\">");
507 questionString.append(
"<tr><td>");
508 questionString.append(tr(
"Current fee:"));
509 questionString.append(
"</td><td>");
511 questionString.append(
"</td></tr><tr><td>");
512 questionString.append(tr(
"Increase:"));
513 questionString.append(
"</td><td>");
515 questionString.append(
"</td></tr><tr><td>");
516 questionString.append(tr(
"New fee:"));
517 questionString.append(
"</td><td>");
519 questionString.append(
"</td></tr></table>");
521 confirmationDialog.
exec();
522 QMessageBox::StandardButton retval =
static_cast<QMessageBox::StandardButton
>(confirmationDialog.result());
525 if (retval != QMessageBox::Yes) {
538 bool complete =
false;
541 QMessageBox::critical(
nullptr, tr(
"Fee bump error"), tr(
"Can't draft transaction."));
553 if (!
m_wallet->signBumpTransaction(mtx)) {
554 QMessageBox::critical(
nullptr, tr(
"Fee bump error"), tr(
"Can't sign transaction."));
558 if(!
m_wallet->commitBumpTransaction(hash, std::move(mtx), errors, new_hash)) {
559 QMessageBox::critical(
nullptr, tr(
"Fee bump error"), tr(
"Could not commit transaction") +
"<br />(" +
560 QString::fromStdString(errors[0].translated)+
")");
573 return QString::fromStdString(
m_wallet->getWalletName());
579 return name.isEmpty() ?
"["+tr(
"default wallet")+
"]" :
name;
void loadReceiveRequests(std::vector< std::string > &vReceiveRequests)
Model for list of recently generated payment requests / bitcoin: URIs.
TransactionTableModel * transactionTableModel
QString getDisplayName() const
std::shared_ptr< CWallet > m_wallet
void coinsSent(WalletModel *wallet, SendCoinsRecipient recipient, QByteArray transaction)
RecentRequestsTableModel * recentRequestsTableModel
std::unique_ptr< interfaces::Handler > m_handler_address_book_changed
static bool isWalletEnabled()
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
bool IsValidDestinationString(const std::string &str, const CChainParams ¶ms)
UnlockContext requestUnlock()
std::unique_ptr< interfaces::Handler > m_handler_unload
void unsubscribeFromCoreSignals()
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
interfaces::Wallet & wallet() const
uint256 m_cached_last_update_tip
bool balanceChanged(const WalletBalances &prev) const
SendCoinsReturn sendCoins(WalletModelTransaction &transaction)
static const bool DEFAULT_DISABLE_WALLET
std::unique_ptr< interfaces::Handler > m_handler_status_changed
QString getWalletName() const
A version of CTransaction with the PSBT format.
Double ended buffer combining vector and stream-like interfaces.
AddressTableModel * getAddressTableModel()
void setTransactionFee(const CAmount &newFee)
bool bumpFee(uint256 hash, uint256 &new_hash)
UnlockContext(WalletModel *wallet, bool valid, bool relock)
int64_t CAmount
Amount in satoshis (Can be negative)
std::string EncodeBase64(Span< const unsigned char > input)
Optional< bool > m_signal_bip125_rbf
Override the wallet's m_signal_rbf if set.
static void NotifyCanGetAddressesChanged(WalletModel *walletmodel)
bool error(const char *fmt, const Args &...args)
void setClientModel(ClientModel *client_model)
Collection of wallet balances.
void setClipboard(const QString &str)
static QString formatHtmlWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD)
Format as HTML string (with unit)
bool changePassphrase(const SecureString &oldPass, const SecureString &newPass)
static void NotifyAddressBookChanged(WalletModel *walletmodel, const CTxDestination &address, const std::string &label, bool isMine, const std::string &purpose, ChangeType status)
static secp256k1_context * ctx
void reassignAmounts(int nChangePosRet)
std::unique_ptr< interfaces::Wallet > m_wallet
SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const CCoinControl &coinControl)
void refresh(bool pk_hash_only=false)
void encryptionStatusChanged()
OptionsModel * optionsModel
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
TransactionTableModel * getTransactionTableModel()
EncryptionStatus cachedEncryptionStatus
UI model for the transaction table of a wallet.
Model for Bitcoin network client.
Qt model of the address book in the core.
static const int MODEL_UPDATE_DELAY
bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString())
std::unique_ptr< interfaces::Handler > m_handler_show_progress
virtual TransactionError fillPSBT(int sighash_type, bool sign, bool bip32derivs, PartiallySignedTransaction &psbtx, bool &complete, size_t *n_signed)=0
Fill PSBT.
EncryptionStatus getEncryptionStatus() const
uint256 getLastBlockProcessed() const
ClientModel * m_client_model
bool validateAddress(const QString &address)
static void NotifyKeyStoreStatusChanged(WalletModel *walletmodel)
void updateWatchOnlyFlag(bool fHaveWatchonly)
static void NotifyUnload(WalletModel *walletModel)
CTxDestination DecodeDestination(const std::string &str)
bool fForceCheckBalanceChanged
std::unique_ptr< interfaces::Handler > m_handler_can_get_addrs_changed
RecentRequestsTableModel * getRecentRequestsTableModel()
virtual WalletClient & walletClient()=0
Get wallet client.
Interface from Qt to configuration data structure for Bitcoin client.
Serialized script, used inside transaction inputs and outputs.
Interface to Bitcoin wallet from Qt view code.
interfaces::WalletBalances m_cached_balances
static const int PROTOCOL_VERSION
network protocol versioning
WalletModel(std::unique_ptr< interfaces::Wallet > wallet, ClientModel &client_model, const PlatformStyle *platformStyle, QObject *parent=nullptr)
bool setWalletEncrypted(bool encrypted, const SecureString &passphrase)
interfaces::Node & m_node
QList< SendCoinsRecipient > getRecipients() const
static void NotifyTransactionChanged(WalletModel *walletmodel, const uint256 &hash, ChangeType status)
void message(const QString &title, const QString &message, unsigned int style)
void CopyFrom(UnlockContext &&rhs)
void notifyWatchonlyChanged(bool fHaveWatchonly)
Data model for a walletmodel transaction.
std::string EncodeDestination(const CTxDestination &dest)
CTransactionRef & getWtx()
A mutable version of CTransaction.
AddressTableModel * addressTableModel
static void NotifyWatchonlyChanged(WalletModel *walletmodel, bool fHaveWatchonly)
uint256 getBestBlockHash()
std::unique_ptr< interfaces::Handler > m_handler_transaction_changed
virtual void commitTransaction(CTransactionRef tx, WalletValueMap value_map, WalletOrderForm order_form)=0
Commit transaction.
void checkBalanceChanged(const interfaces::WalletBalances &new_balances)
boost::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
ChangeType
General change type (added, updated, removed).
static void ShowProgress(WalletModel *walletmodel, const std::string &title, int nProgress)
void updateConfirmations()
bool saveReceiveRequest(const std::string &sAddress, const int64_t nId, const std::string &sRequest)
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 interfaces::WalletBalances &balances)
std::unique_ptr< interfaces::Handler > m_handler_watch_only_changed
void pollBalanceChanged()
OptionsModel * getOptionsModel()
void subscribeToCoreSignals()
Predefined combinations for certain default usage cases.
virtual std::vector< std::unique_ptr< Wallet > > getWallets()=0
Return interfaces for accessing wallets (if any).