diff --git a/src/amount.h b/src/amount.h --- a/src/amount.h +++ b/src/amount.h @@ -9,13 +9,91 @@ #include "serialize.h" #include +#include #include /** Amount in satoshis (Can be negative) */ -typedef int64_t CAmount; +struct CAmount { +private: + int64_t amount; + +public: + CAmount() : amount(0) {} + CAmount(int64_t _amount) : amount(_amount) {} + CAmount(const CAmount &_camount) : amount(_camount.amount) {} + + friend bool operator<(const CAmount a, const CAmount b) { + return a.amount < b.amount; + } + friend bool operator>(const CAmount a, const CAmount b) { + return a.amount > b.amount; + } + friend bool operator==(const CAmount a, const CAmount b) { + return a.amount == b.amount; + } + friend bool operator!=(const CAmount a, const CAmount b) { + return a.amount != b.amount; + } + friend bool operator<=(const CAmount a, const CAmount b) { + return a.amount <= b.amount; + } + friend bool operator>=(const CAmount a, const CAmount b) { + return a.amount >= b.amount; + } + friend CAmount operator+(const CAmount a, const CAmount b) { + return CAmount(a.amount + b.amount); + } + friend CAmount operator-(const CAmount a, const CAmount b) { + return CAmount(a.amount + b.amount); + } + /** + * Implement operator* so const CAmounts can be used as a base unit + **/ + friend CAmount operator*(const int64_t _amount, const CAmount a) { + return CAmount(a.amount * _amount); + } + friend int64_t operator/(const CAmount numerator, + const CAmount denominator) { + return numerator.amount / denominator.amount; + } + friend int64_t operator%(const CAmount numerator, + const CAmount denominator) { + return numerator.amount % denominator.amount; + } + + CAmount &operator+=(const CAmount a) { + amount += a.amount; + return *this; + } + CAmount &operator-=(const CAmount a) { + amount -= a.amount; + return *this; + } + + explicit operator double() const { return amount; } + explicit operator int64_t() const { return amount; } + + // ostream support + friend std::ostream &operator<<(std::ostream &stream, const CAmount &ca); + + // serialization support + + std::string ToString() const; + + ADD_SERIALIZE_METHODS; -static const CAmount COIN = 100000000; -static const CAmount CENT = 1000000; + template + inline void SerializationOp(Stream &s, Operation ser_action) { + READWRITE(amount); + } +}; + +std::ostream &operator<<(std::ostream &stream, const CAmount &ca) { + return stream << ca.amount; +} + +static const CAmount COIN(100000000); +static const CAmount CENT(1000000); extern const std::string CURRENCY_UNIT; @@ -80,6 +158,7 @@ nSatoshisPerK += a.nSatoshisPerK; return *this; } + std::string ToString() const; ADD_SERIALIZE_METHODS; diff --git a/src/amount.cpp b/src/amount.cpp --- a/src/amount.cpp +++ b/src/amount.cpp @@ -14,7 +14,7 @@ int64_t nSize = int64_t(nBytes_); if (nSize > 0) { - nSatoshisPerK = nFeePaid * 1000 / nSize; + nSatoshisPerK = 1000 * nFeePaid / nSize; } else { nSatoshisPerK = 0; } @@ -24,7 +24,7 @@ assert(nBytes_ <= uint64_t(std::numeric_limits::max())); int64_t nSize = int64_t(nBytes_); - CAmount nFee = nSatoshisPerK * nSize / 1000; + CAmount nFee = nSize * nSatoshisPerK / 1000; if (nFee == 0 && nSize != 0) { if (nSatoshisPerK > 0) { diff --git a/src/compressor.h b/src/compressor.h --- a/src/compressor.h +++ b/src/compressor.h @@ -95,8 +95,8 @@ CTxOut &txout; public: - static uint64_t CompressAmount(uint64_t nAmount); - static uint64_t DecompressAmount(uint64_t nAmount); + static uint64_t CompressAmount(CAmount nAmount); + static CAmount DecompressAmount(uint64_t nAmount); CTxOutCompressor(CTxOut &txoutIn) : txout(txoutIn) {} diff --git a/src/compressor.cpp b/src/compressor.cpp --- a/src/compressor.cpp +++ b/src/compressor.cpp @@ -139,7 +139,10 @@ // - 1) + 9 // (this is decodable, as d is in [1-9] and e is in [0-9]) -uint64_t CTxOutCompressor::CompressAmount(uint64_t n) { +uint64_t CTxOutCompressor::CompressAmount(CAmount ca) { + // Convert CAmount to uint64_t for bit manipulations + uint64_t n = ca / 1; + if (n == 0) { return 0; } @@ -158,7 +161,7 @@ } } -uint64_t CTxOutCompressor::DecompressAmount(uint64_t x) { +CAmount CTxOutCompressor::DecompressAmount(uint64_t x) { // x = 0 OR x = 1+10*(9*n + d - 1) + e OR x = 1+10*(n - 1) + 9 if (x == 0) { return 0; @@ -181,5 +184,5 @@ n *= 10; e--; } - return n; + return CAmount(n); } diff --git a/src/miner.cpp b/src/miner.cpp --- a/src/miner.cpp +++ b/src/miner.cpp @@ -200,7 +200,7 @@ nFees + GetBlockSubsidy(nHeight, chainparams.GetConsensus()); coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0; pblock->vtx[0] = MakeTransactionRef(coinbaseTx); - pblocktemplate->vTxFees[0] = -nFees; + pblocktemplate->vTxFees[0] = -1 * nFees; uint64_t nSerializeSize = GetSerializeSize(*pblock, SER_NETWORK, PROTOCOL_VERSION); diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -3590,7 +3590,7 @@ const uint256 &txid = txinfo.tx->GetId(); CInv inv(MSG_TX, txid); pto->setInventoryTxToSend.erase(txid); - if (filterrate) { + if (filterrate != 0) { if (txinfo.feeRate.GetFeePerK() < filterrate) { continue; } @@ -3656,7 +3656,7 @@ if (!txinfo.tx) { continue; } - if (filterrate && txinfo.feeRate.GetFeePerK() < filterrate) { + if (filterrate != 0 && txinfo.feeRate.GetFeePerK() < filterrate) { continue; } if (pto->pfilter && diff --git a/src/policy/fees.h b/src/policy/fees.h --- a/src/policy/fees.h +++ b/src/policy/fees.h @@ -200,8 +200,8 @@ // Minimum and Maximum values for tracking feerates static constexpr double MIN_FEERATE = 10; static const double MAX_FEERATE = 1e7; -static const double INF_FEERATE = MAX_MONEY; -static const double INF_PRIORITY = 1e9 * MAX_MONEY; +static const double INF_FEERATE = (double)MAX_MONEY; +static const double INF_PRIORITY = 1e9 * (double)MAX_MONEY; // We have to lump transactions into buckets based on feerate, but we want to be // able to give accurate estimates over a large range of potential feerates. diff --git a/src/policy/fees.cpp b/src/policy/fees.cpp --- a/src/policy/fees.cpp +++ b/src/policy/fees.cpp @@ -342,7 +342,7 @@ minTrackedFee = _minRelayFee < CFeeRate(MIN_FEERATE) ? CFeeRate(MIN_FEERATE) : _minRelayFee; std::vector vfeelist; - for (double bucketBoundary = minTrackedFee.GetFeePerK(); + for (double bucketBoundary = (double)minTrackedFee.GetFeePerK(); bucketBoundary <= MAX_FEERATE; bucketBoundary *= FEE_SPACING) { vfeelist.push_back(bucketBoundary); } @@ -557,16 +557,16 @@ FeeFilterRounder::FeeFilterRounder(const CFeeRate &minIncrementalFee) { CAmount minFeeLimit = - std::max(CAmount(1), minIncrementalFee.GetFeePerK() / 2); + CAmount(std::max(1LL, minIncrementalFee.GetFeePerK() / 2)); feeset.insert(0); - for (double bucketBoundary = minFeeLimit; bucketBoundary <= MAX_FEERATE; + for (double bucketBoundary = (double)minFeeLimit; bucketBoundary <= MAX_FEERATE; bucketBoundary *= FEE_SPACING) { feeset.insert(bucketBoundary); } } CAmount FeeFilterRounder::round(CAmount currentMinFee) { - std::set::iterator it = feeset.lower_bound(currentMinFee); + std::set::iterator it = feeset.lower_bound((double)currentMinFee); if ((it != feeset.begin() && insecure_rand.rand32() % 3 != 0) || it == feeset.end()) { it--; diff --git a/src/qt/bitcoinamountfield.h b/src/qt/bitcoinamountfield.h --- a/src/qt/bitcoinamountfield.h +++ b/src/qt/bitcoinamountfield.h @@ -29,11 +29,11 @@ public: explicit BitcoinAmountField(QWidget *parent = 0); - CAmount value(bool *value = 0) const; - void setValue(const CAmount &value); + qint64 value(bool *value = 0) const; + void setValue(const qint64 &value); /** Set single step in satoshis **/ - void setSingleStep(const CAmount &step); + void setSingleStep(const qint64 &step); /** Make read-only **/ void setReadOnly(bool fReadOnly); diff --git a/src/qt/bitcoinamountfield.cpp b/src/qt/bitcoinamountfield.cpp --- a/src/qt/bitcoinamountfield.cpp +++ b/src/qt/bitcoinamountfield.cpp @@ -42,7 +42,7 @@ void fixup(QString &input) const { bool valid = false; - CAmount val = parse(input, &valid); + qint64 val = parse(input, &valid); if (valid) { input = BitcoinUnits::format(currentUnit, val, false, BitcoinUnits::separatorAlways); @@ -50,11 +50,11 @@ } } - CAmount value(bool *valid_out = 0) const { + qint64 value(bool *valid_out = 0) const { return parse(text(), valid_out); } - void setValue(const CAmount &value) { + void setValue(const qint64 &value) { lineEdit()->setText(BitcoinUnits::format( currentUnit, value, false, BitcoinUnits::separatorAlways)); Q_EMIT valueChanged(); @@ -62,15 +62,15 @@ void stepBy(int steps) { bool valid = false; - CAmount val = value(&valid); + qint64 val = value(&valid); val = val + steps * singleStep; - val = qMin(qMax(val, CAmount(0)), BitcoinUnits::maxMoney()); + val = qMin(qMax(val, qint64(0)), (qint64)BitcoinUnits::maxMoney()); setValue(val); } void setDisplayUnit(int unit) { bool valid = false; - CAmount val = value(&valid); + qint64 val = value(&valid); currentUnit = unit; @@ -80,7 +80,7 @@ clear(); } - void setSingleStep(const CAmount &step) { singleStep = step; } + void setSingleStep(const qint64 &step) { singleStep = step; } QSize minimumSizeHint() const { if (cachedMinimumSizeHint.isEmpty()) { @@ -126,7 +126,7 @@ private: int currentUnit; - CAmount singleStep; + qint64 singleStep; mutable QSize cachedMinimumSizeHint; /** @@ -134,7 +134,7 @@ * return validity. * @note Must return 0 if !valid. */ - CAmount parse(const QString &text, bool *valid_out = 0) const { + qint64 parse(const QString &text, bool *valid_out = 0) const { CAmount val = 0; bool valid = BitcoinUnits::parse(currentUnit, text, &val); if (valid) { @@ -145,7 +145,7 @@ if (valid_out) { *valid_out = valid; } - return valid ? val : 0; + return valid ? (qint64)val : 0; } protected: @@ -176,7 +176,7 @@ StepEnabled rv = 0; bool valid = false; - CAmount val = value(&valid); + qint64 val = value(&valid); if (valid) { if (val > 0) { rv |= StepDownEnabled; @@ -262,11 +262,11 @@ return unit; } -CAmount BitcoinAmountField::value(bool *valid_out) const { +qint64 BitcoinAmountField::value(bool *valid_out) const { return amount->value(valid_out); } -void BitcoinAmountField::setValue(const CAmount &value) { +void BitcoinAmountField::setValue(const qint64 &value) { amount->setValue(value); } @@ -288,6 +288,6 @@ unit->setValue(newUnit); } -void BitcoinAmountField::setSingleStep(const CAmount &step) { +void BitcoinAmountField::setSingleStep(const qint64 &step) { amount->setSingleStep(step); } diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -221,7 +221,7 @@ QString ret = (URI_SCHEME + ":%1").arg(info.address); int paramCount = 0; - if (info.amount) { + if (info.amount != 0) { ret += QString("?amount=%1") .arg(BitcoinUnits::format(BitcoinUnits::BCC, info.amount, false, diff --git a/src/qt/paymentserver.cpp b/src/qt/paymentserver.cpp --- a/src/qt/paymentserver.cpp +++ b/src/qt/paymentserver.cpp @@ -793,7 +793,7 @@ qWarning() << QString("PaymentServer::%1: Payment request too large " "(%2 bytes, allowed %3 bytes).") .arg(__func__) - .arg(requestSize) + .arg((int64_t)requestSize) .arg(BIP70_MAX_PAYMENTREQUEST_SIZE); } return fVerified; @@ -805,8 +805,8 @@ qWarning() << QString("PaymentServer::%1: Payment request amount out " "of allowed range (%2, allowed 0 - %3).") .arg(__func__) - .arg(requestAmount) - .arg(MAX_MONEY); + .arg((int64_t)requestAmount) + .arg((int64_t)MAX_MONEY); } return fVerified; } diff --git a/src/qt/receiverequestdialog.cpp b/src/qt/receiverequestdialog.cpp --- a/src/qt/receiverequestdialog.cpp +++ b/src/qt/receiverequestdialog.cpp @@ -123,7 +123,7 @@ html += "" + GUIUtil::HtmlEscape(uri) + "
"; html += "" + tr("Address") + ": " + GUIUtil::HtmlEscape(info.address) + "
"; - if (info.amount) + if (info.amount != 0) html += "" + tr("Amount") + ": " + BitcoinUnits::formatHtmlWithUnit(model->getDisplayUnit(), info.amount) + diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -218,7 +218,7 @@ SLOT(updateGlobalFeeVariables())); connect(ui->checkBoxMinimumFee, SIGNAL(stateChanged(int)), this, SLOT(coinControlUpdateLabels())); - ui->customFee->setSingleStep(CWallet::GetRequiredFee(1000)); + ui->customFee->setSingleStep((qint64)CWallet::GetRequiredFee(1000)); updateFeeSectionControls(); updateMinFeeLabel(); updateSmartFeeLabel(); @@ -633,7 +633,7 @@ void SendCoinsDialog::setMinimumFee() { ui->radioCustomPerKilobyte->setChecked(true); - ui->customFee->setValue(CWallet::GetRequiredFee(1000)); + ui->customFee->setValue((qint64)CWallet::GetRequiredFee(1000)); } void SendCoinsDialog::updateFeeSectionControls() { diff --git a/src/qt/sendcoinsentry.cpp b/src/qt/sendcoinsentry.cpp --- a/src/qt/sendcoinsentry.cpp +++ b/src/qt/sendcoinsentry.cpp @@ -190,14 +190,14 @@ { ui->payTo_is->setText(recipient.address); ui->memoTextLabel_is->setText(recipient.message); - ui->payAmount_is->setValue(recipient.amount); + ui->payAmount_is->setValue((qint64)recipient.amount); ui->payAmount_is->setReadOnly(true); setCurrentWidget(ui->SendCoins_UnauthenticatedPaymentRequest); } else // authenticated { ui->payTo_s->setText(recipient.authenticatedMerchant); ui->memoTextLabel_s->setText(recipient.message); - ui->payAmount_s->setValue(recipient.amount); + ui->payAmount_s->setValue((qint64)recipient.amount); ui->payAmount_s->setReadOnly(true); setCurrentWidget(ui->SendCoins_AuthenticatedPaymentRequest); } @@ -215,7 +215,7 @@ // addressbook, don't overwrite with an // empty label ui->addAsLabel->setText(recipient.label); - ui->payAmount->setValue(recipient.amount); + ui->payAmount->setValue((qint64)recipient.amount); } } diff --git a/src/qt/transactiondesc.cpp b/src/qt/transactiondesc.cpp --- a/src/qt/transactiondesc.cpp +++ b/src/qt/transactiondesc.cpp @@ -207,7 +207,7 @@ strHTML += "" + tr("Debit") + ": " + - BitcoinUnits::formatHtmlWithUnit(unit, -txout.nValue) + + BitcoinUnits::formatHtmlWithUnit(unit, -1 * txout.nValue) + "
"; if (toSelf) strHTML += @@ -221,7 +221,7 @@ CAmount nChange = wtx.GetChange(); CAmount nValue = nCredit - nChange; strHTML += "" + tr("Total debit") + ": " + - BitcoinUnits::formatHtmlWithUnit(unit, -nValue) + + BitcoinUnits::formatHtmlWithUnit(unit, -1 * nValue) + "
"; strHTML += "" + tr("Total credit") + ": " + BitcoinUnits::formatHtmlWithUnit(unit, nValue) + @@ -231,7 +231,7 @@ CAmount nTxFee = nDebit - wtx.tx->GetValueOut(); if (nTxFee > 0) strHTML += "" + tr("Transaction fee") + ": " + - BitcoinUnits::formatHtmlWithUnit(unit, -nTxFee) + + BitcoinUnits::formatHtmlWithUnit(unit, -1 * nTxFee) + "
"; } else { // @@ -241,7 +241,7 @@ if (wallet->IsMine(txin)) strHTML += "" + tr("Debit") + ": " + BitcoinUnits::formatHtmlWithUnit( - unit, -wallet->GetDebit(txin, ISMINE_ALL)) + + unit, -1 * wallet->GetDebit(txin, ISMINE_ALL)) + "
"; } for (const CTxOut &txout : wtx.tx->vout) { @@ -319,7 +319,7 @@ if (wallet->IsMine(txin)) strHTML += "" + tr("Debit") + ": " + BitcoinUnits::formatHtmlWithUnit( - unit, -wallet->GetDebit(txin, ISMINE_ALL)) + + unit, -1 * wallet->GetDebit(txin, ISMINE_ALL)) + "
"; } for (const CTxOut &txout : wtx.tx->vout) { diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -94,7 +94,7 @@ parts.append( TransactionRecord(hash, nTime, TransactionRecord::SendToSelf, - "", -(nDebit - nChange), nCredit - nChange)); + "", -1 * (nDebit - nChange), nCredit - nChange)); // maybe pass to TransactionRecord as constructor argument parts.last().involvesWatchAddress = involvesWatchAddress; } else if (fAllFromMe) { @@ -132,7 +132,7 @@ nValue += nTxFee; nTxFee = 0; } - sub.debit = -nValue; + sub.debit = -1 * nValue; parts.append(sub); } diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -414,10 +414,10 @@ Pair("currentpriority", e.GetPriority(chainActive.Height()))); info.push_back(Pair("descendantcount", e.GetCountWithDescendants())); info.push_back(Pair("descendantsize", e.GetSizeWithDescendants())); - info.push_back(Pair("descendantfees", e.GetModFeesWithDescendants())); + info.push_back(Pair("descendantfees", (int64_t)e.GetModFeesWithDescendants())); info.push_back(Pair("ancestorcount", e.GetCountWithAncestors())); info.push_back(Pair("ancestorsize", e.GetSizeWithAncestors())); - info.push_back(Pair("ancestorfees", e.GetModFeesWithAncestors())); + info.push_back(Pair("ancestorfees", (int64_t)e.GetModFeesWithAncestors())); const CTransaction &tx = e.GetTx(); std::set setDepends; for (const CTxIn &txin : tx.vin) { diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -704,7 +704,7 @@ int index_in_template = i - 1; entry.push_back( - Pair("fee", pblocktemplate->vTxFees[index_in_template])); + Pair("fee", (int64_t)pblocktemplate->vTxFees[index_in_template])); int64_t nTxSigOps = pblocktemplate->vTxSigOpsCount[index_in_template]; entry.push_back(Pair("sigops", nTxSigOps)); @@ -978,7 +978,7 @@ nBlocks = 1; } - return mempool.estimatePriority(nBlocks); + return UniValue(mempool.estimatePriority(nBlocks)); } static UniValue estimatesmartfee(const Config &config, diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -125,7 +125,7 @@ UniValue ValueFromAmount(const CAmount &amount) { bool sign = amount < 0; - int64_t n_abs = (sign ? -amount : amount); + CAmount n_abs = (sign ? -1 * amount : amount); int64_t quotient = n_abs / COIN; int64_t remainder = n_abs % COIN; return UniValue(UniValue::VNUM, strprintf("%s%d.%08d", sign ? "-" : "", diff --git a/src/script/bitcoinconsensus.h b/src/script/bitcoinconsensus.h --- a/src/script/bitcoinconsensus.h +++ b/src/script/bitcoinconsensus.h @@ -8,6 +8,8 @@ #include +#include "amount.h" + #if defined(BUILD_BITCOIN_INTERNAL) && defined(HAVE_CONFIG_H) #include "config/bitcoin-config.h" #if defined(_WIN32) @@ -79,7 +81,7 @@ unsigned int flags, bitcoinconsensus_error *err); EXPORT_SYMBOL int bitcoinconsensus_verify_script_with_amount( - const uint8_t *scriptPubKey, unsigned int scriptPubKeyLen, int64_t amount, + const uint8_t *scriptPubKey, unsigned int scriptPubKeyLen, CAmount amount, const uint8_t *txTo, unsigned int txToLen, unsigned int nIn, unsigned int flags, bitcoinconsensus_error *err); diff --git a/src/script/bitcoinconsensus.cpp b/src/script/bitcoinconsensus.cpp --- a/src/script/bitcoinconsensus.cpp +++ b/src/script/bitcoinconsensus.cpp @@ -102,11 +102,11 @@ } int bitcoinconsensus_verify_script_with_amount( - const uint8_t *scriptPubKey, unsigned int scriptPubKeyLen, int64_t amount, + const uint8_t *scriptPubKey, unsigned int scriptPubKeyLen, CAmount amount, const uint8_t *txTo, unsigned int txToLen, unsigned int nIn, unsigned int flags, bitcoinconsensus_error *err) { - CAmount am(amount); - return ::verify_script(scriptPubKey, scriptPubKeyLen, am, txTo, txToLen, + + return ::verify_script(scriptPubKey, scriptPubKeyLen, amount, txTo, txToLen, nIn, flags, err); } diff --git a/src/test/compress_tests.cpp b/src/test/compress_tests.cpp --- a/src/test/compress_tests.cpp +++ b/src/test/compress_tests.cpp @@ -24,7 +24,7 @@ BOOST_FIXTURE_TEST_SUITE(compress_tests, BasicTestingSetup) -static bool TestEncode(uint64_t in) { +static bool TestEncode(CAmount in) { return in == CTxOutCompressor::DecompressAmount( CTxOutCompressor::CompressAmount(in)); } @@ -34,7 +34,7 @@ CTxOutCompressor::DecompressAmount(in)); } -static bool TestPair(uint64_t dec, uint64_t enc) { +static bool TestPair(CAmount dec, uint64_t enc) { return CTxOutCompressor::CompressAmount(dec) == enc && CTxOutCompressor::DecompressAmount(enc) == dec; } diff --git a/src/test/main_tests.cpp b/src/test/main_tests.cpp --- a/src/test/main_tests.cpp +++ b/src/test/main_tests.cpp @@ -17,8 +17,8 @@ int maxHalvings = 64; CAmount nInitialSubsidy = 50 * COIN; - CAmount nPreviousSubsidy = nInitialSubsidy * 2; // for height == 0 - BOOST_CHECK_EQUAL(nPreviousSubsidy, nInitialSubsidy * 2); + CAmount nPreviousSubsidy = 2 * nInitialSubsidy; // for height == 0 + BOOST_CHECK_EQUAL(nPreviousSubsidy, 2 * nInitialSubsidy); for (int nHalvings = 0; nHalvings < maxHalvings; nHalvings++) { int nHeight = nHalvings * consensusParams.nSubsidyHalvingInterval; CAmount nSubsidy = GetBlockSubsidy(nHeight, consensusParams); @@ -52,7 +52,7 @@ for (int nHeight = 0; nHeight < 14000000; nHeight += 1000) { CAmount nSubsidy = GetBlockSubsidy(nHeight, consensusParams); BOOST_CHECK(nSubsidy <= 50 * COIN); - nSum += nSubsidy * 1000; + nSum += 1000 * nSubsidy; BOOST_CHECK(MoneyRange(nSum)); } BOOST_CHECK_EQUAL(nSum, 2099999997690000ULL); diff --git a/src/test/policyestimator_tests.cpp b/src/test/policyestimator_tests.cpp --- a/src/test/policyestimator_tests.cpp +++ b/src/test/policyestimator_tests.cpp @@ -23,7 +23,7 @@ // Populate vectors of increasing fees for (int j = 0; j < 10; j++) { - feeV.push_back(basefee * (j + 1)); + feeV.push_back((j + 1) * basefee); } // Store the hashes of transactions that have been added to the mempool by diff --git a/src/test/rpc_tests.cpp b/src/test/rpc_tests.cpp --- a/src/test/rpc_tests.cpp +++ b/src/test/rpc_tests.cpp @@ -257,21 +257,21 @@ BOOST_CHECK_EQUAL(ValueFromAmount(0).write(), "0.00000000"); BOOST_CHECK_EQUAL(ValueFromAmount((COIN / 10000) * 123456789).write(), "12345.67890000"); - BOOST_CHECK_EQUAL(ValueFromAmount(-COIN).write(), "-1.00000000"); - BOOST_CHECK_EQUAL(ValueFromAmount(-COIN / 10).write(), "-0.10000000"); + BOOST_CHECK_EQUAL(ValueFromAmount(-1 * COIN).write(), "-1.00000000"); + BOOST_CHECK_EQUAL(ValueFromAmount(-1 * COIN / 10).write(), "-0.10000000"); - BOOST_CHECK_EQUAL(ValueFromAmount(COIN * 100000000).write(), + BOOST_CHECK_EQUAL(ValueFromAmount(100000000 * COIN).write(), "100000000.00000000"); - BOOST_CHECK_EQUAL(ValueFromAmount(COIN * 10000000).write(), + BOOST_CHECK_EQUAL(ValueFromAmount(10000000 * COIN).write(), "10000000.00000000"); - BOOST_CHECK_EQUAL(ValueFromAmount(COIN * 1000000).write(), + BOOST_CHECK_EQUAL(ValueFromAmount(1000000 * COIN).write(), "1000000.00000000"); - BOOST_CHECK_EQUAL(ValueFromAmount(COIN * 100000).write(), + BOOST_CHECK_EQUAL(ValueFromAmount(100000 * COIN).write(), "100000.00000000"); - BOOST_CHECK_EQUAL(ValueFromAmount(COIN * 10000).write(), "10000.00000000"); - BOOST_CHECK_EQUAL(ValueFromAmount(COIN * 1000).write(), "1000.00000000"); - BOOST_CHECK_EQUAL(ValueFromAmount(COIN * 100).write(), "100.00000000"); - BOOST_CHECK_EQUAL(ValueFromAmount(COIN * 10).write(), "10.00000000"); + BOOST_CHECK_EQUAL(ValueFromAmount(10000 * COIN).write(), "10000.00000000"); + BOOST_CHECK_EQUAL(ValueFromAmount(1000 * COIN).write(), "1000.00000000"); + BOOST_CHECK_EQUAL(ValueFromAmount(100 * COIN).write(), "100.00000000"); + BOOST_CHECK_EQUAL(ValueFromAmount(10 * COIN).write(), "10.00000000"); BOOST_CHECK_EQUAL(ValueFromAmount(COIN).write(), "1.00000000"); BOOST_CHECK_EQUAL(ValueFromAmount(COIN / 10).write(), "0.10000000"); BOOST_CHECK_EQUAL(ValueFromAmount(COIN / 100).write(), "0.01000000"); diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -154,16 +154,16 @@ BOOST_AUTO_TEST_CASE(util_FormatMoney) { BOOST_CHECK_EQUAL(FormatMoney(0), "0.00"); BOOST_CHECK_EQUAL(FormatMoney((COIN / 10000) * 123456789), "12345.6789"); - BOOST_CHECK_EQUAL(FormatMoney(-COIN), "-1.00"); - - BOOST_CHECK_EQUAL(FormatMoney(COIN * 100000000), "100000000.00"); - BOOST_CHECK_EQUAL(FormatMoney(COIN * 10000000), "10000000.00"); - BOOST_CHECK_EQUAL(FormatMoney(COIN * 1000000), "1000000.00"); - BOOST_CHECK_EQUAL(FormatMoney(COIN * 100000), "100000.00"); - BOOST_CHECK_EQUAL(FormatMoney(COIN * 10000), "10000.00"); - BOOST_CHECK_EQUAL(FormatMoney(COIN * 1000), "1000.00"); - BOOST_CHECK_EQUAL(FormatMoney(COIN * 100), "100.00"); - BOOST_CHECK_EQUAL(FormatMoney(COIN * 10), "10.00"); + BOOST_CHECK_EQUAL(FormatMoney(-1 * COIN), "-1.00"); + + BOOST_CHECK_EQUAL(FormatMoney(100000000 * COIN), "100000000.00"); + BOOST_CHECK_EQUAL(FormatMoney(10000000 * COIN), "10000000.00"); + BOOST_CHECK_EQUAL(FormatMoney(1000000 * COIN), "1000000.00"); + BOOST_CHECK_EQUAL(FormatMoney(100000 * COIN), "100000.00"); + BOOST_CHECK_EQUAL(FormatMoney(10000 * COIN), "10000.00"); + BOOST_CHECK_EQUAL(FormatMoney(1000 * COIN), "1000.00"); + BOOST_CHECK_EQUAL(FormatMoney(100 * COIN), "100.00"); + BOOST_CHECK_EQUAL(FormatMoney(10 * COIN), "10.00"); BOOST_CHECK_EQUAL(FormatMoney(COIN), "1.00"); BOOST_CHECK_EQUAL(FormatMoney(COIN / 10), "0.10"); BOOST_CHECK_EQUAL(FormatMoney(COIN / 100), "0.01"); @@ -184,21 +184,21 @@ BOOST_CHECK_EQUAL(ret, (COIN / 10000) * 123456789); BOOST_CHECK(ParseMoney("100000000.00", ret)); - BOOST_CHECK_EQUAL(ret, COIN * 100000000); + BOOST_CHECK_EQUAL(ret, 100000000 * COIN); BOOST_CHECK(ParseMoney("10000000.00", ret)); - BOOST_CHECK_EQUAL(ret, COIN * 10000000); + BOOST_CHECK_EQUAL(ret, 10000000 * COIN); BOOST_CHECK(ParseMoney("1000000.00", ret)); - BOOST_CHECK_EQUAL(ret, COIN * 1000000); + BOOST_CHECK_EQUAL(ret, 1000000 * COIN); BOOST_CHECK(ParseMoney("100000.00", ret)); - BOOST_CHECK_EQUAL(ret, COIN * 100000); + BOOST_CHECK_EQUAL(ret, 100000 * COIN); BOOST_CHECK(ParseMoney("10000.00", ret)); - BOOST_CHECK_EQUAL(ret, COIN * 10000); + BOOST_CHECK_EQUAL(ret, 10000 * COIN); BOOST_CHECK(ParseMoney("1000.00", ret)); - BOOST_CHECK_EQUAL(ret, COIN * 1000); + BOOST_CHECK_EQUAL(ret, 1000 * COIN); BOOST_CHECK(ParseMoney("100.00", ret)); - BOOST_CHECK_EQUAL(ret, COIN * 100); + BOOST_CHECK_EQUAL(ret, 100 * COIN); BOOST_CHECK(ParseMoney("10.00", ret)); - BOOST_CHECK_EQUAL(ret, COIN * 10); + BOOST_CHECK_EQUAL(ret, 10 * COIN); BOOST_CHECK(ParseMoney("1.00", ret)); BOOST_CHECK_EQUAL(ret, COIN); BOOST_CHECK(ParseMoney("1", ret)); @@ -556,39 +556,39 @@ } BOOST_AUTO_TEST_CASE(test_ParseFixedPoint) { - int64_t amount = 0; + CAmount amount = 0; BOOST_CHECK(ParseFixedPoint("0", 8, &amount)); - BOOST_CHECK_EQUAL(amount, 0LL); + BOOST_CHECK_EQUAL(amount, CAmount(0LL)); BOOST_CHECK(ParseFixedPoint("1", 8, &amount)); - BOOST_CHECK_EQUAL(amount, 100000000LL); + BOOST_CHECK_EQUAL(amount, CAmount(100000000LL)); BOOST_CHECK(ParseFixedPoint("0.0", 8, &amount)); - BOOST_CHECK_EQUAL(amount, 0LL); + BOOST_CHECK_EQUAL(amount, CAmount(0LL)); BOOST_CHECK(ParseFixedPoint("-0.1", 8, &amount)); - BOOST_CHECK_EQUAL(amount, -10000000LL); + BOOST_CHECK_EQUAL(amount, CAmount(-10000000LL)); BOOST_CHECK(ParseFixedPoint("1.1", 8, &amount)); - BOOST_CHECK_EQUAL(amount, 110000000LL); + BOOST_CHECK_EQUAL(amount, CAmount(110000000LL)); BOOST_CHECK(ParseFixedPoint("1.10000000000000000", 8, &amount)); - BOOST_CHECK_EQUAL(amount, 110000000LL); + BOOST_CHECK_EQUAL(amount, CAmount(110000000LL)); BOOST_CHECK(ParseFixedPoint("1.1e1", 8, &amount)); - BOOST_CHECK_EQUAL(amount, 1100000000LL); + BOOST_CHECK_EQUAL(amount, CAmount(1100000000LL)); BOOST_CHECK(ParseFixedPoint("1.1e-1", 8, &amount)); - BOOST_CHECK_EQUAL(amount, 11000000LL); + BOOST_CHECK_EQUAL(amount, CAmount(11000000LL)); BOOST_CHECK(ParseFixedPoint("1000", 8, &amount)); - BOOST_CHECK_EQUAL(amount, 100000000000LL); + BOOST_CHECK_EQUAL(amount, CAmount(100000000000LL)); BOOST_CHECK(ParseFixedPoint("-1000", 8, &amount)); - BOOST_CHECK_EQUAL(amount, -100000000000LL); + BOOST_CHECK_EQUAL(amount, CAmount(-100000000000LL)); BOOST_CHECK(ParseFixedPoint("0.00000001", 8, &amount)); - BOOST_CHECK_EQUAL(amount, 1LL); + BOOST_CHECK_EQUAL(amount, CAmount(1LL)); BOOST_CHECK(ParseFixedPoint("0.0000000100000000", 8, &amount)); - BOOST_CHECK_EQUAL(amount, 1LL); + BOOST_CHECK_EQUAL(amount, CAmount(1LL)); BOOST_CHECK(ParseFixedPoint("-0.00000001", 8, &amount)); - BOOST_CHECK_EQUAL(amount, -1LL); + BOOST_CHECK_EQUAL(amount, CAmount(-1LL)); BOOST_CHECK(ParseFixedPoint("1000000000.00000001", 8, &amount)); - BOOST_CHECK_EQUAL(amount, 100000000000000001LL); + BOOST_CHECK_EQUAL(amount, CAmount(100000000000000001LL)); BOOST_CHECK(ParseFixedPoint("9999999999.99999999", 8, &amount)); - BOOST_CHECK_EQUAL(amount, 999999999999999999LL); + BOOST_CHECK_EQUAL(amount, CAmount(999999999999999999LL)); BOOST_CHECK(ParseFixedPoint("-9999999999.99999999", 8, &amount)); - BOOST_CHECK_EQUAL(amount, -999999999999999999LL); + BOOST_CHECK_EQUAL(amount, CAmount(-999999999999999999LL)); BOOST_CHECK(!ParseFixedPoint("", 8, &amount)); BOOST_CHECK(!ParseFixedPoint("-", 8, &amount)); diff --git a/src/txmempool.h b/src/txmempool.h --- a/src/txmempool.h +++ b/src/txmempool.h @@ -31,7 +31,7 @@ class CBlockIndex; inline double AllowFreeThreshold() { - return COIN * 144 / 250; + return (double)COIN * 144.0L / 250.0L; } inline bool AllowFree(double dPriority) { @@ -103,7 +103,7 @@ int64_t sigOpCount; //!< Used for determining the priority of the transaction for mining in a //! block - int64_t feeDelta; + CAmount feeDelta; //!< Track the height and time at which tx was final LockPoints lockPoints; @@ -145,7 +145,7 @@ int64_t GetTime() const { return nTime; } unsigned int GetHeight() const { return entryHeight; } int64_t GetSigOpCount() const { return sigOpCount; } - int64_t GetModifiedFee() const { return nFee + feeDelta; } + CAmount GetModifiedFee() const { return nFee + feeDelta; } size_t DynamicMemoryUsage() const { return nUsageSize; } const LockPoints &GetLockPoints() const { return lockPoints; } @@ -157,7 +157,7 @@ int64_t modifyCount, int modifySigOps); // Updates the fee delta used for mining priority score, and the // modified fees with descendants. - void UpdateFeeDelta(int64_t feeDelta); + void UpdateFeeDelta(CAmount feeDelta); // Update the LockPoints after a reorg void UpdateLockPoints(const LockPoints &lp); @@ -216,7 +216,7 @@ }; struct update_fee_delta { - update_fee_delta(int64_t _feeDelta) : feeDelta(_feeDelta) {} + update_fee_delta(CAmount _feeDelta) : feeDelta(_feeDelta) {} void operator()(CTxMemPoolEntry &e) { e.UpdateFeeDelta(feeDelta); } @@ -252,19 +252,19 @@ bool fUseADescendants = UseDescendantScore(a); bool fUseBDescendants = UseDescendantScore(b); - double aModFee = fUseADescendants ? a.GetModFeesWithDescendants() + CAmount aModFee = fUseADescendants ? a.GetModFeesWithDescendants() : a.GetModifiedFee(); - double aSize = + uint64_t aSize = fUseADescendants ? a.GetSizeWithDescendants() : a.GetTxSize(); - double bModFee = fUseBDescendants ? b.GetModFeesWithDescendants() + CAmount bModFee = fUseBDescendants ? b.GetModFeesWithDescendants() : b.GetModifiedFee(); - double bSize = + uint64_t bSize = fUseBDescendants ? b.GetSizeWithDescendants() : b.GetTxSize(); // Avoid division by rewriting (a/b > c/d) as (a*d > c*b). - double f1 = aModFee * bSize; - double f2 = aSize * bModFee; + CAmount f1 = bSize * aModFee; + CAmount f2 = aSize * bModFee; if (f1 == f2) { return a.GetTime() >= b.GetTime(); @@ -274,8 +274,8 @@ // Calculate which score to use for an entry (avoiding division). bool UseDescendantScore(const CTxMemPoolEntry &a) { - double f1 = (double)a.GetModifiedFee() * a.GetSizeWithDescendants(); - double f2 = (double)a.GetModFeesWithDescendants() * a.GetTxSize(); + CAmount f1 = a.GetSizeWithDescendants() * a.GetModifiedFee(); + CAmount f2 = a.GetTxSize() * a.GetModFeesWithDescendants(); return f2 > f1; } }; @@ -287,8 +287,8 @@ class CompareTxMemPoolEntryByScore { public: bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) { - double f1 = (double)a.GetModifiedFee() * b.GetTxSize(); - double f2 = (double)b.GetModifiedFee() * a.GetTxSize(); + CAmount f1 = b.GetTxSize() * a.GetModifiedFee(); + CAmount f2 = a.GetTxSize() * b.GetModifiedFee(); if (f1 == f2) { return b.GetTx().GetId() < a.GetTx().GetId(); } @@ -306,15 +306,15 @@ class CompareTxMemPoolEntryByAncestorFee { public: bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) { - double aFees = a.GetModFeesWithAncestors(); - double aSize = a.GetSizeWithAncestors(); + CAmount aFees = a.GetModFeesWithAncestors(); + uint64_t aSize = a.GetSizeWithAncestors(); - double bFees = b.GetModFeesWithAncestors(); - double bSize = b.GetSizeWithAncestors(); + CAmount bFees = b.GetModFeesWithAncestors(); + uint64_t bSize = b.GetSizeWithAncestors(); // Avoid division by rewriting (a/b > c/d) as (a*d > c*b). - double f1 = aFees * bSize; - double f2 = aSize * bFees; + CAmount f1 = bSize * aFees; + CAmount f2 = aSize * bFees; if (f1 == f2) { return a.GetTx().GetId() < b.GetTx().GetId(); @@ -346,7 +346,7 @@ CFeeRate feeRate; /** The fee delta. */ - int64_t nFeeDelta; + CAmount nFeeDelta; }; /** @@ -466,7 +466,7 @@ mutable int64_t lastRollingFeeUpdate; mutable bool blockSinceLastRollingFeeBump; //!< minimum fee to get into the pool, decreases exponentially - mutable double rollingMinimumFeeRate; + mutable CAmount rollingMinimumFeeRate; void trackPackageRemoved(const CFeeRate &rate); diff --git a/src/txmempool.cpp b/src/txmempool.cpp --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -64,7 +64,7 @@ return dResult; } -void CTxMemPoolEntry::UpdateFeeDelta(int64_t newFeeDelta) { +void CTxMemPoolEntry::UpdateFeeDelta(CAmount newFeeDelta) { nModFeesWithDescendants += newFeeDelta - feeDelta; nModFeesWithAncestors += newFeeDelta - feeDelta; feeDelta = newFeeDelta; @@ -308,7 +308,7 @@ CalculateDescendants(removeIt, setDescendants); setDescendants.erase(removeIt); // don't update state for self int64_t modifySize = -((int64_t)removeIt->GetTxSize()); - CAmount modifyFee = -removeIt->GetModifiedFee(); + CAmount modifyFee = -1 * removeIt->GetModifiedFee(); int modifySigOps = -removeIt->GetSigOpCount(); for (txiter dit : setDescendants) { mapTx.modify(dit, update_ancestor_state(modifySize, modifyFee, @@ -422,7 +422,7 @@ mapDeltas.find(hash); if (pos != mapDeltas.end()) { const std::pair &deltas = pos->second; - if (deltas.second) { + if (deltas.second != 0) { mapTx.modify(newit, update_fee_delta(deltas.second)); } } diff --git a/src/utilmoneystr.cpp b/src/utilmoneystr.cpp --- a/src/utilmoneystr.cpp +++ b/src/utilmoneystr.cpp @@ -12,7 +12,7 @@ std::string FormatMoney(const CAmount &n) { // Note: not using straight sprintf here because we do NOT want localized // number formatting. - int64_t n_abs = (n > 0 ? n : -n); + CAmount n_abs = (n > 0 ? n : -1 * n); int64_t quotient = n_abs / COIN; int64_t remainder = n_abs % COIN; std::string str = strprintf("%d.%08d", quotient, remainder); @@ -33,17 +33,17 @@ bool ParseMoney(const char *pszIn, CAmount &nRet) { std::string strWhole; - int64_t nUnits = 0; + CAmount nUnits = 0; const char *p = pszIn; while (isspace(*p)) p++; for (; *p; p++) { if (*p == '.') { p++; - int64_t nMult = CENT * 10; + CAmount nMult = 10 * CENT; while (isdigit(*p) && (nMult > 0)) { - nUnits += nMult * (*p++ - '0'); - nMult /= 10; + nUnits += (*p++ - '0') * nMult; + nMult = nMult / CAmount(10); } break; } diff --git a/src/utilstrencodings.h b/src/utilstrencodings.h --- a/src/utilstrencodings.h +++ b/src/utilstrencodings.h @@ -9,6 +9,8 @@ #ifndef BITCOIN_UTILSTRENCODINGS_H #define BITCOIN_UTILSTRENCODINGS_H +#include "amount.h" + #include #include #include @@ -140,6 +142,6 @@ * @note The result must be in the range (-10^18,10^18), otherwise an overflow * error will trigger. */ -bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out); +bool ParseFixedPoint(const std::string &val, int decimals, CAmount *amount_out); #endif // BITCOIN_UTILSTRENCODINGS_H diff --git a/src/utilstrencodings.cpp b/src/utilstrencodings.cpp --- a/src/utilstrencodings.cpp +++ b/src/utilstrencodings.cpp @@ -580,7 +580,7 @@ } bool ParseFixedPoint(const std::string &val, int decimals, - int64_t *amount_out) { + CAmount *amount_out) { int64_t mantissa = 0; int64_t exponent = 0; int mantissa_tzeros = 0; diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -60,9 +60,9 @@ /** Default for -minrelaytxfee, minimum relay fee for transactions */ static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 1000; //! -maxtxfee default -static const CAmount DEFAULT_TRANSACTION_MAXFEE = 0.1 * COIN; +static const CAmount DEFAULT_TRANSACTION_MAXFEE = COIN / CAmount(10); //! Discourage users to set fees higher than this amount (in satoshis) per kB -static const CAmount HIGH_TX_FEE_PER_KB = 0.01 * COIN; +static const CAmount HIGH_TX_FEE_PER_KB = COIN / CAmount(100); /** -maxtxfee will warn if called with a higher fee than this amount (in * satoshis */ static const CAmount HIGH_MAX_TX_FEE = 100 * HIGH_TX_FEE_PER_KB; diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -839,7 +839,7 @@ dFreeCount += nSize; } - if (nAbsurdFee && nFees > nAbsurdFee) { + if (nAbsurdFee == 0 && nFees > nAbsurdFee) { return state.Invalid(false, REJECT_HIGHFEE, "absurdly-high-fee", strprintf("%d > %d", nFees, nAbsurdFee)); } @@ -1089,7 +1089,8 @@ CAmount nSubsidy = 50 * COIN; // Subsidy is cut in half every 210,000 blocks which will occur // approximately every 4 years. - nSubsidy >>= halvings; + nSubsidy = (int64_t)nSubsidy >> halvings; + return nSubsidy; } @@ -4842,7 +4843,7 @@ file >> nFeeDelta; CAmount amountdelta = nFeeDelta; - if (amountdelta) { + if (amountdelta != 0) { mempool.PrioritiseTransaction(tx->GetId(), tx->GetId().ToString(), prioritydummy, amountdelta); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1623,13 +1623,13 @@ entry.push_back(Pair("account", strSentAccount)); MaybePushAddress(entry, s.destination); entry.push_back(Pair("category", "send")); - entry.push_back(Pair("amount", ValueFromAmount(-s.amount))); + entry.push_back(Pair("amount", ValueFromAmount(-1 * s.amount))); if (pwalletMain->mapAddressBook.count(s.destination)) { entry.push_back(Pair( "label", pwalletMain->mapAddressBook[s.destination].name)); } entry.push_back(Pair("vout", s.vout)); - entry.push_back(Pair("fee", ValueFromAmount(-nFee))); + entry.push_back(Pair("fee", ValueFromAmount(-1 * nFee))); if (fLong) { WalletTxToJSON(wtx, entry); } diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp --- a/src/wallet/test/wallet_tests.cpp +++ b/src/wallet/test/wallet_tests.cpp @@ -238,11 +238,11 @@ // test small change avoidance empty_wallet(); - add_coin(MIN_CHANGE * 1 / 10); - add_coin(MIN_CHANGE * 2 / 10); - add_coin(MIN_CHANGE * 3 / 10); - add_coin(MIN_CHANGE * 4 / 10); - add_coin(MIN_CHANGE * 5 / 10); + add_coin((1 * MIN_CHANGE) / 10); + add_coin((2 * MIN_CHANGE) / 10); + add_coin((3 * MIN_CHANGE) / 10); + add_coin((4 * MIN_CHANGE) / 10); + add_coin((5 * MIN_CHANGE) / 10); // try making 1 * MIN_CHANGE from the 1.5 * MIN_CHANGE we'll get change // smaller than MIN_CHANGE whatever happens, so can expect MIN_CHANGE @@ -261,8 +261,8 @@ BOOST_CHECK_EQUAL(nValueRet, 1 * MIN_CHANGE); // if we add more small coins: - add_coin(MIN_CHANGE * 6 / 10); - add_coin(MIN_CHANGE * 7 / 10); + add_coin((6 * MIN_CHANGE) / 10); + add_coin((7 * MIN_CHANGE) / 10); // and try again to make 1.0 * MIN_CHANGE BOOST_CHECK(wallet.SelectCoinsMinConf(1 * MIN_CHANGE, 1, 1, 0, vCoins, @@ -292,9 +292,9 @@ // sometimes it will fail, and so we use the next biggest coin: empty_wallet(); - add_coin(MIN_CHANGE * 5 / 10); - add_coin(MIN_CHANGE * 6 / 10); - add_coin(MIN_CHANGE * 7 / 10); + add_coin((5 * MIN_CHANGE) / 10); + add_coin((6 * MIN_CHANGE) / 10); + add_coin((7 * MIN_CHANGE) / 10); add_coin(1111 * MIN_CHANGE); BOOST_CHECK(wallet.SelectCoinsMinConf(1 * MIN_CHANGE, 1, 1, 0, vCoins, setCoinsRet, nValueRet)); @@ -305,9 +305,9 @@ // but sometimes it's possible, and we use an exact subset (0.4 + 0.6 = // 1.0) empty_wallet(); - add_coin(MIN_CHANGE * 4 / 10); - add_coin(MIN_CHANGE * 6 / 10); - add_coin(MIN_CHANGE * 8 / 10); + add_coin((4 * MIN_CHANGE) / 10); + add_coin((6 * MIN_CHANGE) / 10); + add_coin((8 * MIN_CHANGE) / 10); add_coin(1111 * MIN_CHANGE); BOOST_CHECK(wallet.SelectCoinsMinConf(MIN_CHANGE, 1, 1, 0, vCoins, setCoinsRet, nValueRet)); @@ -318,26 +318,28 @@ // test avoiding small change empty_wallet(); - add_coin(MIN_CHANGE * 5 / 100); - add_coin(MIN_CHANGE * 1); - add_coin(MIN_CHANGE * 100); + add_coin((5 * MIN_CHANGE) / 100); + add_coin(1 * MIN_CHANGE); + add_coin(100 * MIN_CHANGE); // trying to make 100.01 from these three coins - BOOST_CHECK(wallet.SelectCoinsMinConf(MIN_CHANGE * 10001 / 100, 1, 1, 0, - vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK(wallet.SelectCoinsMinConf((10001 * MIN_CHANGE) / 100, 1, 1, + 0, vCoins, setCoinsRet, + nValueRet)); // we should get all coins - BOOST_CHECK_EQUAL(nValueRet, MIN_CHANGE * 10105 / 100); + BOOST_CHECK_EQUAL(nValueRet, (10105 * MIN_CHANGE) / 100); BOOST_CHECK_EQUAL(setCoinsRet.size(), 3U); // but if we try to make 99.9, we should take the bigger of the two // small coins to avoid small change - BOOST_CHECK(wallet.SelectCoinsMinConf(MIN_CHANGE * 9990 / 100, 1, 1, 0, - vCoins, setCoinsRet, nValueRet)); + BOOST_CHECK(wallet.SelectCoinsMinConf((9990 * MIN_CHANGE) / 100, 1, 1, + 0, vCoins, setCoinsRet, + nValueRet)); BOOST_CHECK_EQUAL(nValueRet, 101 * MIN_CHANGE); BOOST_CHECK_EQUAL(setCoinsRet.size(), 2U); // test with many inputs - for (CAmount amt = 1500; amt < COIN; amt *= 10) { + for (CAmount amt = 1500; amt < COIN; amt = 10 * amt) { empty_wallet(); // Create 676 inputs (= (old MAX_STANDARD_TX_SIZE == 100000) / 148 // bytes per input) @@ -349,7 +351,7 @@ if (amt - 2000 < MIN_CHANGE) { // needs more than one input: uint16_t returnSize = std::ceil((2000.0 + MIN_CHANGE) / amt); - CAmount returnValue = amt * returnSize; + CAmount returnValue = returnSize * amt; BOOST_CHECK_EQUAL(nValueRet, returnValue); BOOST_CHECK_EQUAL(setCoinsRet.size(), returnSize); } else { diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -901,7 +901,7 @@ CAccountingEntry debit; debit.nOrderPos = IncOrderPosNext(&walletdb); debit.strAccount = strFrom; - debit.nCreditDebit = -nAmount; + debit.nCreditDebit = -1 * nAmount; debit.nTime = nNow; debit.strOtherAccount = strTo; debit.strComment = strComment; @@ -2760,7 +2760,7 @@ int age = pcoin.first->GetDepthInMainChain(); assert(age >= 0); if (age != 0) age += 1; - dPriority += (double)nCredit * age; + dPriority += (double)(age * nCredit); } const CAmount nChange = nValueIn - nValueToSelect;