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};
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)
214 Q_EMIT
message(tr(
"Send Coins"), QString::fromStdString(
error.translated),
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;
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)
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
static QString formatHtmlWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD)
Format as HTML string (with unit)
@ MSG_INFORMATION
Predefined combinations for certain default usage cases.
Optional< bool > m_signal_bip125_rbf
Override the wallet's m_signal_rbf if set.
Double ended buffer combining vector and stream-like interfaces.
Serialized script, used inside transaction inputs and outputs.
Model for Bitcoin network client.
uint256 getBestBlockHash()
Interface from Qt to configuration data structure for Bitcoin client.
Model for list of recently generated payment requests / bitcoin: URIs.
UI model for the transaction table of a wallet.
void updateConfirmations()
UnlockContext(WalletModel *wallet, bool valid, bool relock)
void CopyFrom(UnlockContext &&rhs)
Interface to Bitcoin wallet from Qt view code.
OptionsModel * optionsModel
bool validateAddress(const QString &address)
AddressTableModel * addressTableModel
void loadReceiveRequests(std::vector< std::string > &vReceiveRequests)
EncryptionStatus cachedEncryptionStatus
void refresh(bool pk_hash_only=false)
uint256 m_cached_last_update_tip
ClientModel * m_client_model
std::unique_ptr< interfaces::Handler > m_handler_watch_only_changed
interfaces::Node & m_node
std::unique_ptr< interfaces::Handler > m_handler_transaction_changed
bool setWalletEncrypted(bool encrypted, const SecureString &passphrase)
void pollBalanceChanged()
SendCoinsReturn sendCoins(WalletModelTransaction &transaction)
RecentRequestsTableModel * recentRequestsTableModel
TransactionTableModel * transactionTableModel
void notifyWatchonlyChanged(bool fHaveWatchonly)
bool changePassphrase(const SecureString &oldPass, const SecureString &newPass)
bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString())
void message(const QString &title, const QString &message, unsigned int style)
void setClientModel(ClientModel *client_model)
bool saveReceiveRequest(const std::string &sAddress, const int64_t nId, const std::string &sRequest)
AddressTableModel * getAddressTableModel()
OptionsModel * getOptionsModel()
std::unique_ptr< interfaces::Handler > m_handler_can_get_addrs_changed
std::unique_ptr< interfaces::Handler > m_handler_unload
interfaces::Wallet & wallet() const
SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const CCoinControl &coinControl)
EncryptionStatus getEncryptionStatus() const
RecentRequestsTableModel * getRecentRequestsTableModel()
std::unique_ptr< interfaces::Handler > m_handler_status_changed
interfaces::WalletBalances m_cached_balances
bool fForceCheckBalanceChanged
void coinsSent(WalletModel *wallet, SendCoinsRecipient recipient, QByteArray transaction)
QString getDisplayName() const
bool bumpFee(uint256 hash, uint256 &new_hash)
void checkBalanceChanged(const interfaces::WalletBalances &new_balances)
void unsubscribeFromCoreSignals()
void updateAddressBook(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
uint256 getLastBlockProcessed() const
WalletModel(std::unique_ptr< interfaces::Wallet > wallet, ClientModel &client_model, const PlatformStyle *platformStyle, QObject *parent=nullptr)
void updateWatchOnlyFlag(bool fHaveWatchonly)
std::unique_ptr< interfaces::Handler > m_handler_address_book_changed
void encryptionStatusChanged()
std::unique_ptr< interfaces::Wallet > m_wallet
UnlockContext requestUnlock()
void balanceChanged(const interfaces::WalletBalances &balances)
static bool isWalletEnabled()
QString getWalletName() const
std::unique_ptr< interfaces::Handler > m_handler_show_progress
@ AmountWithFeeExceedsBalance
@ TransactionCreationFailed
void subscribeToCoreSignals()
TransactionTableModel * getTransactionTableModel()
Data model for a walletmodel transaction.
void setTransactionFee(const CAmount &newFee)
void reassignAmounts(int nChangePosRet)
QList< SendCoinsRecipient > getRecipients() const
CTransactionRef & getWtx()
virtual WalletClient & walletClient()=0
Get wallet client.
virtual std::vector< std::unique_ptr< Wallet > > getWallets()=0
Return interfaces for accessing wallets (if any).
virtual TransactionError fillPSBT(int sighash_type, bool sign, bool bip32derivs, PartiallySignedTransaction &psbtx, bool &complete, size_t *n_signed)=0
Fill PSBT.
virtual void commitTransaction(CTransactionRef tx, WalletValueMap value_map, WalletOrderForm order_form)=0
Commit transaction.
void push_back(const T &value)
static const int MODEL_UPDATE_DELAY
std::shared_ptr< CWallet > m_wallet
bool IsValidDestinationString(const std::string &str, const CChainParams ¶ms)
std::string EncodeDestination(const CTxDestination &dest)
CTxDestination DecodeDestination(const std::string &str)
void setClipboard(const QString &str)
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
boost::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
std::string EncodeBase64(Span< const unsigned char > input)
A mutable version of CTransaction.
A version of CTransaction with the PSBT format.
Collection of wallet balances.
bool balanceChanged(const WalletBalances &prev) const
bool error(const char *fmt, const Args &... args)
static secp256k1_context * ctx
ChangeType
General change type (added, updated, removed).
static const int PROTOCOL_VERSION
network protocol versioning
static const bool DEFAULT_DISABLE_WALLET
static void NotifyUnload(WalletModel *walletModel)
static void NotifyWatchonlyChanged(WalletModel *walletmodel, bool fHaveWatchonly)
static void NotifyCanGetAddressesChanged(WalletModel *walletmodel)
static void NotifyAddressBookChanged(WalletModel *walletmodel, const CTxDestination &address, const std::string &label, bool isMine, const std::string &purpose, ChangeType status)
static void ShowProgress(WalletModel *walletmodel, const std::string &title, int nProgress)
static void NotifyKeyStoreStatusChanged(WalletModel *walletmodel)
static void NotifyTransactionChanged(WalletModel *walletmodel, const uint256 &hash, ChangeType status)