35 m_client_model(&client_model),
m_node(client_model.
node()),
36 optionsModel(client_model.getOptionsModel()), addressTableModel(nullptr),
37 transactionTableModel(nullptr), recentRequestsTableModel(nullptr),
38 cachedEncryptionStatus(Unencrypted), timer(new QTimer(this)) {
86 if (!
m_wallet->tryGetBalances(new_balances, block_hash)) {
117 const QString &label,
bool isMine,
118 const QString &purpose,
int status) {
137 bool fSubtractFeeFromAmount =
false;
138 QList<SendCoinsRecipient> recipients = transaction.
getRecipients();
139 std::vector<CRecipient> vecSend;
141 if (recipients.empty()) {
146 QSet<QString> setAddress;
151 if (rcp.fSubtractFeeFromAmount) {
152 fSubtractFeeFromAmount =
true;
157 if (rcp.paymentRequest.IsInitialized()) {
159 const payments::PaymentDetails &details =
160 rcp.paymentRequest.getDetails();
161 for (
int i = 0; i < details.outputs_size(); i++) {
162 const payments::Output &out = details.outputs(i);
163 if (out.amount() <= 0) {
167 subtotal += int64_t(out.amount()) *
SATOSHI;
168 const uint8_t *scriptStr = (
const uint8_t *)out.script().data();
169 CScript scriptPubKey(scriptStr,
170 scriptStr + out.script().size());
172 CRecipient recipient = {scriptPubKey, nAmount,
173 rcp.fSubtractFeeFromAmount};
174 vecSend.push_back(recipient);
193 setAddress.insert(rcp.address);
199 rcp.fSubtractFeeFromAmount};
200 vecSend.push_back(recipient);
205 if (setAddress.size() != nAddresses) {
211 if (total > nBalance) {
216 int nChangePosRet = -1;
219 auto &newTx = transaction.
getWtx();
220 newTx =
m_wallet->createTransaction(
221 vecSend, coinControl, !
wallet().privateKeysDisabled() ,
222 nChangePosRet, nFeeRequired,
error);
224 if (fSubtractFeeFromAmount && newTx) {
229 if (!fSubtractFeeFromAmount && (total + nFeeRequired) > nBalance) {
232 Q_EMIT
message(tr(
"Send Coins"),
233 QString::fromStdString(
error.translated),
241 if (nFeeRequired >
m_wallet->getDefaultMaxTxFee()) {
251 QByteArray transaction_array;
253 std::vector<std::pair<std::string, std::string>> vOrderForm;
256 if (rcp.paymentRequest.IsInitialized()) {
258 if (PaymentServer::verifyExpired(rcp.paymentRequest.getDetails())) {
264 rcp.paymentRequest.SerializeToString(&value);
265 vOrderForm.emplace_back(
"PaymentRequest", std::move(value));
269 if (!rcp.message.isEmpty()) {
272 vOrderForm.emplace_back(
"Message", rcp.message.toStdString());
277 auto &newTx = transaction.
getWtx();
282 transaction_array.append((
const char *)ssTx.
data(), ssTx.
size());
289 if (!rcp.paymentRequest.IsInitialized())
292 std::string strAddress = rcp.address.toStdString();
295 std::string strLabel = rcp.label.toStdString();
300 m_wallet->setAddressBook(dest, strLabel,
"send");
301 }
else if (
name != strLabel) {
303 m_wallet->setAddressBook(dest, strLabel,
"");
343 return m_wallet->encryptWallet(passphrase);
352 return m_wallet->unlock(passPhrase);
360 return m_wallet->changeWalletPassphrase(oldPass, newPass);
365 qDebug() <<
"NotifyUnload";
366 bool invoked = QMetaObject::invokeMethod(walletModel,
"unload");
371 qDebug() <<
"NotifyKeyStoreStatusChanged";
372 bool invoked = QMetaObject::invokeMethod(walletmodel,
"updateStatus",
373 Qt::QueuedConnection);
379 const std::string &label,
bool isMine,
380 const std::string &purpose,
382 QString strAddress = QString::fromStdString(
384 QString strLabel = QString::fromStdString(label);
385 QString strPurpose = QString::fromStdString(purpose);
387 qDebug() <<
"NotifyAddressBookChanged: " + strAddress +
" " + strLabel +
388 " isMine=" + QString::number(isMine) +
389 " purpose=" + strPurpose +
390 " status=" + QString::number(status);
391 bool invoked = QMetaObject::invokeMethod(
392 walletmodel,
"updateAddressBook", Qt::QueuedConnection,
393 Q_ARG(QString, strAddress), Q_ARG(QString, strLabel),
394 Q_ARG(
bool, isMine), Q_ARG(QString, strPurpose), Q_ARG(
int, status));
402 bool invoked = QMetaObject::invokeMethod(walletmodel,
"updateTransaction",
403 Qt::QueuedConnection);
410 bool invoked = QMetaObject::invokeMethod(
411 walletmodel,
"showProgress", Qt::QueuedConnection,
412 Q_ARG(QString, QString::fromStdString(title)), Q_ARG(
int, nProgress));
417 bool fHaveWatchonly) {
418 bool invoked = QMetaObject::invokeMethod(walletmodel,
"updateWatchOnlyFlag",
419 Qt::QueuedConnection,
420 Q_ARG(
bool, fHaveWatchonly));
426 QMetaObject::invokeMethod(walletmodel,
"canGetAddressesChanged");
437 std::placeholders::_2, std::placeholders::_3,
438 std::placeholders::_4, std::placeholders::_5));
441 std::placeholders::_2));
443 ShowProgress,
this, std::placeholders::_1, std::placeholders::_2));
477 :
wallet(_wallet), valid(_valid), relock(_relock) {}
480 if (valid && relock) {
481 wallet->setWalletLocked(
true);
492 std::vector<std::string> &vReceiveRequests) {
494 vReceiveRequests =
m_wallet->getDestValues(
"rr");
499 const std::string &sRequest) {
502 std::stringstream ss;
505 std::string key =
"rr" + ss.str();
507 return sRequest.empty() ?
m_wallet->eraseDestData(dest, key)
508 :
m_wallet->addDestData(dest, key, sRequest);
516 return QString::fromStdString(
m_wallet->getWalletName());
521 return name.isEmpty() ?
"[" + tr(
"default wallet") +
"]" :
name;
static constexpr Amount SATOSHI
std::string EncodeCashAddr(const CTxDestination &dst, const CChainParams ¶ms)
const CChainParams & Params()
Return the currently selected parameters.
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.
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Double ended buffer combining vector and stream-like interfaces.
Model for Bitcoin network client.
BlockHash getBestBlockHash() EXCLUSIVE_LOCKS_REQUIRED(!m_cached_tip_mutex)
Interface from Qt to configuration data structure for Bitcoin client.
Model for list of recently generated payment requests / bitcoincash: 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
ClientModel * m_client_model
std::unique_ptr< interfaces::Handler > m_handler_watch_only_changed
BlockHash m_cached_last_update_tip
interfaces::Node & m_node
std::unique_ptr< interfaces::Handler > m_handler_transaction_changed
void pollBalanceChanged()
Current, immature or unconfirmed balance might have changed - emit 'balanceChanged' if so.
SendCoinsReturn sendCoins(WalletModelTransaction &transaction)
RecentRequestsTableModel * recentRequestsTableModel
TransactionTableModel * transactionTableModel
bool setWalletEncrypted(const SecureString &passphrase)
void notifyWatchonlyChanged(bool fHaveWatchonly)
bool changePassphrase(const SecureString &oldPass, const SecureString &newPass)
BlockHash getLastBlockProcessed() const
bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString())
void message(const QString &title, const QString &message, unsigned int style)
void coinsSent(interfaces::Wallet &wallet, SendCoinsRecipient recipient, QByteArray transaction)
void setClientModel(ClientModel *client_model)
const CChainParams & getChainParams() const
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
SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const CCoinControl &coinControl)
EncryptionStatus getEncryptionStatus() const
interfaces::Wallet & wallet() const
RecentRequestsTableModel * getRecentRequestsTableModel()
std::unique_ptr< interfaces::Handler > m_handler_status_changed
interfaces::WalletBalances m_cached_balances
bool fForceCheckBalanceChanged
QString getDisplayName() const
void checkBalanceChanged(const interfaces::WalletBalances &new_balances)
void unsubscribeFromCoreSignals()
void updateTransaction()
New transaction, or transaction changed status.
void updateAddressBook(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
New, updated or removed address book entry.
WalletModel(std::unique_ptr< interfaces::Wallet > wallet, ClientModel &client_model, const PlatformStyle *platformStyle, QObject *parent=nullptr)
void updateWatchOnlyFlag(bool fHaveWatchonly)
Watch-only added.
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 reassignAmounts(int nChangePosRet)
void setTransactionFee(const Amount newFee)
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 void commitTransaction(CTransactionRef tx, WalletValueMap value_map, WalletOrderForm order_form)=0
Commit transaction.
static const int MODEL_UPDATE_DELAY
bool IsValidDestinationString(const std::string &str, const CChainParams ¶ms)
CTxDestination DecodeDestination(const std::string &addr, const CChainParams ¶ms)
bool error(const char *fmt, const Args &...args)
Implement std::hash so RCUPtr can be used as a key for maps or sets.
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.
std::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
static constexpr Amount zero() noexcept
A BlockHash is a unqiue identifier for a block.
A TxId is the identifier of a transaction.
Collection of wallet balances.
bool balanceChanged(const WalletBalances &prev) const
ChangeType
General change type (added, updated, removed).
static const int PROTOCOL_VERSION
network protocol versioning
std::shared_ptr< CWallet > m_wallet
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 NotifyTransactionChanged(WalletModel *walletmodel, const TxId &hash, ChangeType status)
static void ShowProgress(WalletModel *walletmodel, const std::string &title, int nProgress)
static void NotifyKeyStoreStatusChanged(WalletModel *walletmodel)