Changeset View
Changeset View
Standalone View
Standalone View
src/qt/coincontroldialog.cpp
Show First 20 Lines • Show All 463 Lines • ▼ Show 20 Lines | void CoinControlDialog::updateLabels(WalletModel *model, QDialog *dialog) { | ||||
} | } | ||||
Amount nAmount(0); | Amount nAmount(0); | ||||
Amount nPayFee(0); | Amount nPayFee(0); | ||||
Amount nAfterFee(0); | Amount nAfterFee(0); | ||||
Amount nChange(0); | Amount nChange(0); | ||||
unsigned int nBytes = 0; | unsigned int nBytes = 0; | ||||
unsigned int nBytesInputs = 0; | unsigned int nBytesInputs = 0; | ||||
double dPriority = 0; | |||||
double dPriorityInputs = 0; | |||||
unsigned int nQuantity = 0; | unsigned int nQuantity = 0; | ||||
int nQuantityUncompressed = 0; | int nQuantityUncompressed = 0; | ||||
bool fAllowFree = false; | |||||
std::vector<COutPoint> vCoinControl; | std::vector<COutPoint> vCoinControl; | ||||
std::vector<COutput> vOutputs; | std::vector<COutput> vOutputs; | ||||
coinControl->ListSelected(vCoinControl); | coinControl->ListSelected(vCoinControl); | ||||
model->getOutputs(vCoinControl, vOutputs); | model->getOutputs(vCoinControl, vOutputs); | ||||
for (const COutput &out : vOutputs) { | for (const COutput &out : vOutputs) { | ||||
// unselect already spent, very unlikely scenario, this could happen | // unselect already spent, very unlikely scenario, this could happen | ||||
// when selected are spent elsewhere, like rpc or another computer | // when selected are spent elsewhere, like rpc or another computer | ||||
uint256 txhash = out.tx->GetId(); | uint256 txhash = out.tx->GetId(); | ||||
COutPoint outpt(txhash, out.i); | COutPoint outpt(txhash, out.i); | ||||
if (model->isSpent(outpt)) { | if (model->isSpent(outpt)) { | ||||
coinControl->UnSelect(outpt); | coinControl->UnSelect(outpt); | ||||
continue; | continue; | ||||
} | } | ||||
// Quantity | // Quantity | ||||
nQuantity++; | nQuantity++; | ||||
// Amount | // Amount | ||||
nAmount += out.tx->tx->vout[out.i].nValue; | nAmount += out.tx->tx->vout[out.i].nValue; | ||||
// Priority | |||||
dPriorityInputs += | |||||
(double)out.tx->tx->vout[out.i].nValue.GetSatoshis() * | |||||
(out.nDepth + 1); | |||||
// Bytes | // Bytes | ||||
CTxDestination address; | CTxDestination address; | ||||
if (ExtractDestination(out.tx->tx->vout[out.i].scriptPubKey, address)) { | if (ExtractDestination(out.tx->tx->vout[out.i].scriptPubKey, address)) { | ||||
CPubKey pubkey; | CPubKey pubkey; | ||||
CKeyID *keyid = boost::get<CKeyID>(&address); | CKeyID *keyid = boost::get<CKeyID>(&address); | ||||
if (keyid && model->getPubKey(*keyid, pubkey)) { | if (keyid && model->getPubKey(*keyid, pubkey)) { | ||||
nBytesInputs += (pubkey.IsCompressed() ? 148 : 180); | nBytesInputs += (pubkey.IsCompressed() ? 148 : 180); | ||||
if (!pubkey.IsCompressed()) nQuantityUncompressed++; | if (!pubkey.IsCompressed()) nQuantityUncompressed++; | ||||
Show All 25 Lines | if (nQuantity > 0) { | ||||
} | } | ||||
// Fee | // Fee | ||||
nPayFee = CWallet::GetMinimumFee(nBytes, nTxConfirmTarget, mempool); | nPayFee = CWallet::GetMinimumFee(nBytes, nTxConfirmTarget, mempool); | ||||
if (nPayFee > Amount(0) && coinControl->nMinimumTotalFee > nPayFee) { | if (nPayFee > Amount(0) && coinControl->nMinimumTotalFee > nPayFee) { | ||||
nPayFee = coinControl->nMinimumTotalFee; | nPayFee = coinControl->nMinimumTotalFee; | ||||
} | } | ||||
// Allow free? (require at least hard-coded threshold and default to | |||||
// that if no estimate) | |||||
double mempoolEstimatePriority = | |||||
mempool.estimateSmartPriority(nTxConfirmTarget); | |||||
// 29 = 180 - 151 (uncompressed public keys are over the limit. max 151 | |||||
// bytes of the input are ignored for priority) | |||||
dPriority = dPriorityInputs / | |||||
(nBytes - nBytesInputs + (nQuantityUncompressed * 29)); | |||||
double dPriorityNeeded = | |||||
std::max(mempoolEstimatePriority, AllowFreeThreshold()); | |||||
fAllowFree = (dPriority >= dPriorityNeeded); | |||||
if (nPayAmount > Amount(0)) { | if (nPayAmount > Amount(0)) { | ||||
nChange = nAmount - nPayAmount; | nChange = nAmount - nPayAmount; | ||||
if (!CoinControlDialog::fSubtractFeeFromAmount) nChange -= nPayFee; | if (!CoinControlDialog::fSubtractFeeFromAmount) nChange -= nPayFee; | ||||
// Never create dust outputs; if we would, just add the dust to the | // Never create dust outputs; if we would, just add the dust to the | ||||
// fee. | // fee. | ||||
if (nChange > Amount(0) && nChange < MIN_CHANGE) { | if (nChange > Amount(0) && nChange < MIN_CHANGE) { | ||||
CTxOut txout(nChange, (CScript)std::vector<uint8_t>(24, 0)); | CTxOut txout(nChange, (CScript)std::vector<uint8_t>(24, 0)); | ||||
▲ Show 20 Lines • Show All 280 Lines • Show Last 20 Lines |