Changeset View
Changeset View
Standalone View
Standalone View
src/qt/walletmodel.cpp
Show First 20 Lines • Show All 164 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
void WalletModel::updateWatchOnlyFlag(bool fHaveWatchonly) { | void WalletModel::updateWatchOnlyFlag(bool fHaveWatchonly) { | ||||
fHaveWatchOnly = fHaveWatchonly; | fHaveWatchOnly = fHaveWatchonly; | ||||
Q_EMIT notifyWatchonlyChanged(fHaveWatchonly); | Q_EMIT notifyWatchonlyChanged(fHaveWatchonly); | ||||
} | } | ||||
bool WalletModel::validateAddress(const QString &address) { | bool WalletModel::validateAddress(const QString &address) { | ||||
CBitcoinAddress addressParsed(address.toStdString()); | return IsValidDestinationString(address.toStdString()); | ||||
return addressParsed.IsValid(); | |||||
} | } | ||||
WalletModel::SendCoinsReturn | WalletModel::SendCoinsReturn | ||||
WalletModel::prepareTransaction(WalletModelTransaction &transaction, | WalletModel::prepareTransaction(WalletModelTransaction &transaction, | ||||
const CCoinControl *coinControl) { | const CCoinControl *coinControl) { | ||||
CAmount total = 0; | CAmount total = 0; | ||||
bool fSubtractFeeFromAmount = false; | bool fSubtractFeeFromAmount = false; | ||||
QList<SendCoinsRecipient> recipients = transaction.getRecipients(); | QList<SendCoinsRecipient> recipients = transaction.getRecipients(); | ||||
Show All 38 Lines | for (const SendCoinsRecipient &rcp : recipients) { | ||||
} | } | ||||
if (rcp.amount <= 0) { | if (rcp.amount <= 0) { | ||||
return InvalidAmount; | return InvalidAmount; | ||||
} | } | ||||
setAddress.insert(rcp.address); | setAddress.insert(rcp.address); | ||||
++nAddresses; | ++nAddresses; | ||||
CScript scriptPubKey = GetScriptForDestination( | CScript scriptPubKey = GetScriptForDestination( | ||||
CBitcoinAddress(rcp.address.toStdString()).Get()); | DecodeDestination(rcp.address.toStdString())); | ||||
CRecipient recipient = {scriptPubKey, rcp.amount, | CRecipient recipient = {scriptPubKey, rcp.amount, | ||||
rcp.fSubtractFeeFromAmount}; | rcp.fSubtractFeeFromAmount}; | ||||
vecSend.push_back(recipient); | vecSend.push_back(recipient); | ||||
total += rcp.amount; | total += rcp.amount; | ||||
} | } | ||||
} | } | ||||
if (setAddress.size() != nAddresses) { | if (setAddress.size() != nAddresses) { | ||||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | WalletModel::sendCoins(WalletModelTransaction &transaction) { | ||||
} | } | ||||
// Add addresses / update labels that we've sent to to the address book, and | // Add addresses / update labels that we've sent to to the address book, and | ||||
// emit coinsSent signal for each recipient | // emit coinsSent signal for each recipient | ||||
for (const SendCoinsRecipient &rcp : transaction.getRecipients()) { | for (const SendCoinsRecipient &rcp : transaction.getRecipients()) { | ||||
// Don't touch the address book when we have a payment request | // Don't touch the address book when we have a payment request | ||||
if (!rcp.paymentRequest.IsInitialized()) { | if (!rcp.paymentRequest.IsInitialized()) { | ||||
std::string strAddress = rcp.address.toStdString(); | std::string strAddress = rcp.address.toStdString(); | ||||
CTxDestination dest = CBitcoinAddress(strAddress).Get(); | CTxDestination dest = DecodeDestination(strAddress); | ||||
std::string strLabel = rcp.label.toStdString(); | std::string strLabel = rcp.label.toStdString(); | ||||
{ | { | ||||
LOCK(wallet->cs_wallet); | LOCK(wallet->cs_wallet); | ||||
std::map<CTxDestination, CAddressBookData>::iterator mi = | std::map<CTxDestination, CAddressBookData>::iterator mi = | ||||
wallet->mapAddressBook.find(dest); | wallet->mapAddressBook.find(dest); | ||||
// Check if we have a new address or an updated label | // Check if we have a new address or an updated label | ||||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | QMetaObject::invokeMethod(walletmodel, "updateStatus", | ||||
Qt::QueuedConnection); | Qt::QueuedConnection); | ||||
} | } | ||||
static void NotifyAddressBookChanged(WalletModel *walletmodel, CWallet *wallet, | static void NotifyAddressBookChanged(WalletModel *walletmodel, CWallet *wallet, | ||||
const CTxDestination &address, | const CTxDestination &address, | ||||
const std::string &label, bool isMine, | const std::string &label, bool isMine, | ||||
const std::string &purpose, | const std::string &purpose, | ||||
ChangeType status) { | ChangeType status) { | ||||
QString strAddress = | QString strAddress = QString::fromStdString(EncodeDestination(address)); | ||||
QString::fromStdString(CBitcoinAddress(address).ToString()); | |||||
QString strLabel = QString::fromStdString(label); | QString strLabel = QString::fromStdString(label); | ||||
QString strPurpose = QString::fromStdString(purpose); | QString strPurpose = QString::fromStdString(purpose); | ||||
qDebug() << "NotifyAddressBookChanged: " + strAddress + " " + strLabel + | qDebug() << "NotifyAddressBookChanged: " + strAddress + " " + strLabel + | ||||
" isMine=" + QString::number(isMine) + " purpose=" + | " isMine=" + QString::number(isMine) + " purpose=" + | ||||
strPurpose + " status=" + QString::number(status); | strPurpose + " status=" + QString::number(status); | ||||
QMetaObject::invokeMethod(walletmodel, "updateAddressBook", | QMetaObject::invokeMethod(walletmodel, "updateAddressBook", | ||||
Qt::QueuedConnection, Q_ARG(QString, strAddress), | Qt::QueuedConnection, Q_ARG(QString, strAddress), | ||||
▲ Show 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | for (const COutput &out : vCoins) { | ||||
cout.tx->tx->vin[0].prevout.n, 0, true, true); | cout.tx->tx->vin[0].prevout.n, 0, true, true); | ||||
} | } | ||||
CTxDestination address; | CTxDestination address; | ||||
if (!out.fSpendable || | if (!out.fSpendable || | ||||
!ExtractDestination(cout.tx->tx->vout[cout.i].scriptPubKey, | !ExtractDestination(cout.tx->tx->vout[cout.i].scriptPubKey, | ||||
address)) | address)) | ||||
continue; | continue; | ||||
mapCoins[QString::fromStdString(CBitcoinAddress(address).ToString())] | mapCoins[QString::fromStdString(EncodeDestination(address))].push_back( | ||||
.push_back(out); | out); | ||||
} | } | ||||
} | } | ||||
bool WalletModel::isLockedCoin(uint256 hash, unsigned int n) const { | bool WalletModel::isLockedCoin(uint256 hash, unsigned int n) const { | ||||
LOCK2(cs_main, wallet->cs_wallet); | LOCK2(cs_main, wallet->cs_wallet); | ||||
return wallet->IsLockedCoin(hash, n); | return wallet->IsLockedCoin(hash, n); | ||||
} | } | ||||
Show All 23 Lines | for (const std::pair<CTxDestination, CAddressBookData> &item : | ||||
item2.first.substr(0, 2) == "rr") // receive request | item2.first.substr(0, 2) == "rr") // receive request | ||||
vReceiveRequests.push_back(item2.second); | vReceiveRequests.push_back(item2.second); | ||||
} | } | ||||
} | } | ||||
bool WalletModel::saveReceiveRequest(const std::string &sAddress, | bool WalletModel::saveReceiveRequest(const std::string &sAddress, | ||||
const int64_t nId, | const int64_t nId, | ||||
const std::string &sRequest) { | const std::string &sRequest) { | ||||
CTxDestination dest = CBitcoinAddress(sAddress).Get(); | CTxDestination dest = DecodeDestination(sAddress); | ||||
std::stringstream ss; | std::stringstream ss; | ||||
ss << nId; | ss << nId; | ||||
// "rr" prefix = "receive request" in destdata | // "rr" prefix = "receive request" in destdata | ||||
std::string key = "rr" + ss.str(); | std::string key = "rr" + ss.str(); | ||||
LOCK(wallet->cs_wallet); | LOCK(wallet->cs_wallet); | ||||
if (sRequest.empty()) | if (sRequest.empty()) | ||||
Show All 30 Lines |