diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -597,7 +597,8 @@ msgParams.first = tr("A fee higher than %1 is considered an absurdly high fee.") .arg(BitcoinUnits::formatWithUnit( - model->getOptionsModel()->getDisplayUnit(), maxTxFee)); + model->getOptionsModel()->getDisplayUnit(), + maxTxFee.GetSatoshis())); break; case WalletModel::PaymentRequestExpired: msgParams.first = tr("Payment request expired."); diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -1112,7 +1112,7 @@ const uint256 &txid = tx->GetId(); bool fLimitFree = false; - CAmount nMaxRawTxFee = maxTxFee; + CAmount nMaxRawTxFee = maxTxFee.GetSatoshis(); if (request.params.size() > 1 && request.params[1].get_bool()) { nMaxRawTxFee = 0; } 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 @@ -15,13 +15,13 @@ static void TestBlockSubsidyHalvings(const Consensus::Params &consensusParams) { int maxHalvings = 64; - CAmount nInitialSubsidy = 50 * COIN.GetSatoshis(); + Amount nInitialSubsidy = 50 * COIN; - CAmount nPreviousSubsidy = nInitialSubsidy * 2; // for height == 0 - BOOST_CHECK_EQUAL(nPreviousSubsidy, nInitialSubsidy * 2); + Amount 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); + Amount nSubsidy = GetBlockSubsidy(nHeight, consensusParams); BOOST_CHECK(nSubsidy <= nInitialSubsidy); BOOST_CHECK_EQUAL(nSubsidy, nPreviousSubsidy / 2); nPreviousSubsidy = nSubsidy; @@ -48,11 +48,11 @@ BOOST_AUTO_TEST_CASE(subsidy_limit_test) { const Consensus::Params &consensusParams = Params(CBaseChainParams::MAIN).GetConsensus(); - CAmount nSum = 0; + Amount nSum = 0; for (int nHeight = 0; nHeight < 14000000; nHeight += 1000) { - CAmount nSubsidy = GetBlockSubsidy(nHeight, consensusParams); + Amount 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/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -196,7 +196,7 @@ extern CFeeRate minRelayTxFee; /** Absolute maximum transaction fee (in satoshis) used by wallet and mempool * (rejects high fee in sendrawtransaction) */ -extern CAmount maxTxFee; +extern Amount maxTxFee; /** If the tip is older than this (in seconds), the node is considered to be in * initial block download. */ extern int64_t nMaxTipAge; @@ -322,7 +322,7 @@ bool ActivateBestChain( const Config &config, CValidationState &state, std::shared_ptr pblock = std::shared_ptr()); -CAmount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams); +Amount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams); /** Guess verification progress (as a fraction between 0.0=genesis and * 1.0=current tip). */ @@ -385,7 +385,7 @@ bool fLimitFree, bool *pfMissingInputs, std::list *plTxnReplaced = nullptr, bool fOverrideMempoolLimit = false, - const CAmount nAbsurdFee = 0); + const Amount nAbsurdFee = Amount(0)); /** Convert CValidationState to a human-readable message for logging */ std::string FormatStateMessage(const CValidationState &state); @@ -509,7 +509,7 @@ class CScriptCheck { private: CScript scriptPubKey; - CAmount amount; + Amount amount; const CTransaction *ptxTo; unsigned int nIn; uint32_t nFlags; @@ -522,7 +522,7 @@ : amount(0), ptxTo(0), nIn(0), nFlags(0), cacheStore(false), error(SCRIPT_ERR_UNKNOWN_ERROR), txdata() {} - CScriptCheck(const CScript &scriptPubKeyIn, const CAmount amountIn, + CScriptCheck(const CScript &scriptPubKeyIn, const Amount amountIn, const CTransaction &txToIn, unsigned int nInIn, uint32_t nFlagsIn, bool cacheIn, const PrecomputedTransactionData &txdataIn) diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -82,7 +82,7 @@ uint256 hashAssumeValid; CFeeRate minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE); -CAmount maxTxFee = DEFAULT_TRANSACTION_MAXFEE.GetSatoshis(); +Amount maxTxFee = DEFAULT_TRANSACTION_MAXFEE; CTxMemPool mempool(::minRelayTxFee); @@ -677,7 +677,7 @@ const Config &config, CTxMemPool &pool, CValidationState &state, const CTransactionRef &ptx, bool fLimitFree, bool *pfMissingInputs, int64_t nAcceptTime, std::list *plTxnReplaced, - bool fOverrideMempoolLimit, const CAmount &nAbsurdFee, + bool fOverrideMempoolLimit, const Amount nAbsurdFee, std::vector &coins_to_uncache) { AssertLockHeld(cs_main); @@ -849,7 +849,7 @@ strprintf("%d", nSigOpsCount)); } - CAmount mempoolRejectFee = + Amount mempoolRejectFee = pool.GetMinFee(GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000) .GetFee(nSize) @@ -897,7 +897,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)); } @@ -1011,7 +1011,7 @@ const Config &config, CTxMemPool &pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree, bool *pfMissingInputs, int64_t nAcceptTime, std::list *plTxnReplaced = nullptr, - bool fOverrideMempoolLimit = false, const CAmount nAbsurdFee = 0) { + bool fOverrideMempoolLimit = false, const Amount nAbsurdFee = 0) { std::vector coins_to_uncache; bool res = AcceptToMemoryPoolWorker( config, pool, state, tx, fLimitFree, pfMissingInputs, nAcceptTime, @@ -1033,7 +1033,7 @@ CValidationState &state, const CTransactionRef &tx, bool fLimitFree, bool *pfMissingInputs, std::list *plTxnReplaced, - bool fOverrideMempoolLimit, const CAmount nAbsurdFee) { + bool fOverrideMempoolLimit, const Amount nAbsurdFee) { return AcceptToMemoryPoolWithTime(config, pool, state, tx, fLimitFree, pfMissingInputs, GetTime(), plTxnReplaced, fOverrideMempoolLimit, nAbsurdFee); @@ -1165,16 +1165,15 @@ return true; } -CAmount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams) { +Amount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams) { int halvings = nHeight / consensusParams.nSubsidyHalvingInterval; // Force block reward to zero when right shift is undefined. if (halvings >= 64) return 0; - CAmount nSubsidy = 50 * COIN.GetSatoshis(); + Amount nSubsidy = 50 * COIN; // Subsidy is cut in half every 210,000 blocks which will occur // approximately every 4 years. - nSubsidy >>= halvings; - return nSubsidy; + return Amount(nSubsidy.GetSatoshis() >> halvings); } bool IsInitialBlockDownload() { @@ -1373,8 +1372,8 @@ return state.Invalid(false, 0, "", "Inputs unavailable"); } - CAmount nValueIn = 0; - CAmount nFees = 0; + Amount nValueIn = 0; + Amount nFees = 0; for (size_t i = 0; i < tx.vin.size(); i++) { const COutPoint &prevout = tx.vin[i].prevout; const Coin &coin = inputs.AccessCoin(prevout); @@ -1407,7 +1406,7 @@ } // Tally transaction fees - CAmount nTxFee = nValueIn - tx.GetValueOut().GetSatoshis(); + Amount nTxFee = nValueIn - tx.GetValueOut(); if (nTxFee < 0) { return state.DoS(100, false, REJECT_INVALID, "bad-txns-fee-negative"); } @@ -1468,7 +1467,7 @@ // additional data in, eg, the coins being spent being checked as a part // of CScriptCheck. const CScript &scriptPubKey = coin.GetTxOut().scriptPubKey; - const CAmount amount = coin.GetTxOut().nValue.GetSatoshis(); + const Amount amount = coin.GetTxOut().nValue; // Verify signature CScriptCheck check(scriptPubKey, amount, tx, i, flags, sigCacheStore, @@ -2008,7 +2007,7 @@ : nullptr); std::vector prevheights; - CAmount nFees = 0; + Amount nFees = 0; int nInputs = 0; // Sigops counting. We need to do it again because of P2SH. @@ -2104,7 +2103,7 @@ nInputs <= 1 ? 0 : 0.001 * (nTime3 - nTime2) / (nInputs - 1), nTimeConnect * 0.000001); - CAmount blockReward = + Amount blockReward = nFees + GetBlockSubsidy(pindex->nHeight, chainparams.GetConsensus()); if (block.vtx[0]->GetValueOut() > blockReward) { return state.DoS(100, error("ConnectBlock(): coinbase pays too much " @@ -4942,8 +4941,8 @@ file >> nTime; file >> nFeeDelta; - CAmount amountdelta = nFeeDelta; - if (amountdelta) { + Amount amountdelta = nFeeDelta; + if (amountdelta != 0) { mempool.PrioritiseTransaction(tx->GetId(), tx->GetId().ToString(), prioritydummy, amountdelta); @@ -4963,7 +4962,7 @@ } if (ShutdownRequested()) return false; } - std::map mapDeltas; + std::map mapDeltas; file >> mapDeltas; for (const auto &i : mapDeltas) { @@ -4986,7 +4985,7 @@ void DumpMempool(void) { int64_t start = GetTimeMicros(); - std::map mapDeltas; + std::map mapDeltas; std::vector vinfo; { diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1805,7 +1805,7 @@ LOCK(mempool.cs); CValidationState state; - wtx.AcceptToMemoryPool(maxTxFee, state); + wtx.AcceptToMemoryPool(maxTxFee.GetSatoshis(), state); } } @@ -1817,7 +1817,7 @@ CValidationState state; // GetDepthInMainChain already catches known conflicts. - if (InMempool() || AcceptToMemoryPool(maxTxFee, state)) { + if (InMempool() || AcceptToMemoryPool(maxTxFee.GetSatoshis(), state)) { LogPrintf("Relaying wtx %s\n", GetId().ToString()); if (connman) { CInv inv(MSG_TX, GetId()); @@ -3053,7 +3053,7 @@ if (fBroadcastTransactions) { // Broadcast - if (!wtxNew.AcceptToMemoryPool(maxTxFee, state)) { + if (!wtxNew.AcceptToMemoryPool(maxTxFee.GetSatoshis(), state)) { LogPrintf("CommitTransaction(): Transaction cannot be " "broadcast immediately, %s\n", state.GetRejectReason()); @@ -3127,7 +3127,7 @@ // But always obey the maximum. if (nFeeNeeded > maxTxFee) { - nFeeNeeded = maxTxFee; + nFeeNeeded = maxTxFee.GetSatoshis(); } return nFeeNeeded;