Changeset View
Changeset View
Standalone View
Standalone View
src/qt/walletmodel.cpp
Show First 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | if (fForceCheckBalanceChanged || chainActive.Height() != cachedNumBlocks) { | ||||
cachedNumBlocks = chainActive.Height(); | cachedNumBlocks = chainActive.Height(); | ||||
checkBalanceChanged(); | checkBalanceChanged(); | ||||
if (transactionTableModel) transactionTableModel->updateConfirmations(); | if (transactionTableModel) transactionTableModel->updateConfirmations(); | ||||
} | } | ||||
} | } | ||||
void WalletModel::checkBalanceChanged() { | void WalletModel::checkBalanceChanged() { | ||||
Amount newBalance = getBalance(); | Amount newBalance(getBalance()); | ||||
Amount newUnconfirmedBalance = getUnconfirmedBalance(); | Amount newUnconfirmedBalance(getUnconfirmedBalance()); | ||||
Amount newImmatureBalance = getImmatureBalance(); | Amount newImmatureBalance(getImmatureBalance()); | ||||
Amount newWatchOnlyBalance = 0; | Amount newWatchOnlyBalance(0); | ||||
Amount newWatchUnconfBalance = 0; | Amount newWatchUnconfBalance(0); | ||||
Amount newWatchImmatureBalance = 0; | Amount newWatchImmatureBalance(0); | ||||
if (haveWatchOnly()) { | if (haveWatchOnly()) { | ||||
newWatchOnlyBalance = getWatchBalance(); | newWatchOnlyBalance = getWatchBalance(); | ||||
newWatchUnconfBalance = getWatchUnconfirmedBalance(); | newWatchUnconfBalance = getWatchUnconfirmedBalance(); | ||||
newWatchImmatureBalance = getWatchImmatureBalance(); | newWatchImmatureBalance = getWatchImmatureBalance(); | ||||
} | } | ||||
if (cachedBalance != newBalance || | if (cachedBalance != newBalance || | ||||
cachedUnconfirmedBalance != newUnconfirmedBalance || | cachedUnconfirmedBalance != newUnconfirmedBalance || | ||||
Show All 32 Lines | |||||
bool WalletModel::validateAddress(const QString &address) { | bool WalletModel::validateAddress(const QString &address) { | ||||
return IsValidDestinationString(address.toStdString()); | return IsValidDestinationString(address.toStdString()); | ||||
} | } | ||||
WalletModel::SendCoinsReturn | WalletModel::SendCoinsReturn | ||||
WalletModel::prepareTransaction(WalletModelTransaction &transaction, | WalletModel::prepareTransaction(WalletModelTransaction &transaction, | ||||
const CCoinControl *coinControl) { | const CCoinControl *coinControl) { | ||||
Amount total = 0; | Amount total(0); | ||||
bool fSubtractFeeFromAmount = false; | bool fSubtractFeeFromAmount = false; | ||||
QList<SendCoinsRecipient> recipients = transaction.getRecipients(); | QList<SendCoinsRecipient> recipients = transaction.getRecipients(); | ||||
std::vector<CRecipient> vecSend; | std::vector<CRecipient> vecSend; | ||||
if (recipients.empty()) { | if (recipients.empty()) { | ||||
return OK; | return OK; | ||||
} | } | ||||
// Used to detect duplicates | // Used to detect duplicates | ||||
QSet<QString> setAddress; | QSet<QString> setAddress; | ||||
int nAddresses = 0; | int nAddresses = 0; | ||||
// Pre-check input data for validity | // Pre-check input data for validity | ||||
for (const SendCoinsRecipient &rcp : recipients) { | for (const SendCoinsRecipient &rcp : recipients) { | ||||
if (rcp.fSubtractFeeFromAmount) fSubtractFeeFromAmount = true; | if (rcp.fSubtractFeeFromAmount) fSubtractFeeFromAmount = true; | ||||
// PaymentRequest... | // PaymentRequest... | ||||
if (rcp.paymentRequest.IsInitialized()) { | if (rcp.paymentRequest.IsInitialized()) { | ||||
Amount subtotal = 0; | Amount subtotal(0); | ||||
const payments::PaymentDetails &details = | const payments::PaymentDetails &details = | ||||
rcp.paymentRequest.getDetails(); | rcp.paymentRequest.getDetails(); | ||||
for (int i = 0; i < details.outputs_size(); i++) { | for (int i = 0; i < details.outputs_size(); i++) { | ||||
const payments::Output &out = details.outputs(i); | const payments::Output &out = details.outputs(i); | ||||
if (out.amount() <= 0) continue; | if (out.amount() <= 0) continue; | ||||
subtotal += out.amount(); | subtotal += Amount(out.amount()); | ||||
const uint8_t *scriptStr = (const uint8_t *)out.script().data(); | const uint8_t *scriptStr = (const uint8_t *)out.script().data(); | ||||
CScript scriptPubKey(scriptStr, | CScript scriptPubKey(scriptStr, | ||||
scriptStr + out.script().size()); | scriptStr + out.script().size()); | ||||
Amount nAmount = out.amount(); | Amount nAmount = Amount(out.amount()); | ||||
CRecipient recipient = {scriptPubKey, Amount(nAmount), | CRecipient recipient = {scriptPubKey, Amount(nAmount), | ||||
rcp.fSubtractFeeFromAmount}; | rcp.fSubtractFeeFromAmount}; | ||||
vecSend.push_back(recipient); | vecSend.push_back(recipient); | ||||
} | } | ||||
if (subtotal <= 0) { | if (subtotal <= Amount(0)) { | ||||
return InvalidAmount; | return InvalidAmount; | ||||
} | } | ||||
total += subtotal; | total += subtotal; | ||||
} else { // User-entered bitcoin address / amount: | } else { // User-entered bitcoin address / amount: | ||||
if (!validateAddress(rcp.address)) { | if (!validateAddress(rcp.address)) { | ||||
return InvalidAddress; | return InvalidAddress; | ||||
} | } | ||||
if (rcp.amount <= 0) { | if (rcp.amount <= Amount(0)) { | ||||
return InvalidAmount; | return InvalidAmount; | ||||
} | } | ||||
setAddress.insert(rcp.address); | setAddress.insert(rcp.address); | ||||
++nAddresses; | ++nAddresses; | ||||
CScript scriptPubKey = GetScriptForDestination( | CScript scriptPubKey = GetScriptForDestination( | ||||
DecodeDestination(rcp.address.toStdString())); | DecodeDestination(rcp.address.toStdString())); | ||||
CRecipient recipient = {scriptPubKey, Amount(rcp.amount), | CRecipient recipient = {scriptPubKey, Amount(rcp.amount), | ||||
▲ Show 20 Lines • Show All 451 Lines • Show Last 20 Lines |