diff --git a/src/amount.h b/src/amount.h --- a/src/amount.h +++ b/src/amount.h @@ -29,7 +29,7 @@ constexpr Amount(const Amount &_camount) : amount(_camount.amount) {} // Allow access to underlying value for non-monetary operations - int64_t GetSatoshis() const { return amount; } + int64_t GetSatoshis() const { return *this / Amount(1); } /** * Implement standard operators @@ -109,7 +109,7 @@ * Modulus */ constexpr int64_t operator%(const Amount b) const { - return amount % b.amount; + return Amount(amount % b.amount) / Amount(1); } constexpr Amount operator%(const int64_t b) const { return Amount(amount % b); @@ -140,8 +140,10 @@ } }; -static const Amount COIN(100000000); -static const Amount CENT(1000000); +static const Amount SATOSHI(1); +static const Amount CASH = 100 * SATOSHI; +static const Amount COIN = 100000000 * SATOSHI; +static const Amount CENT = COIN / 100; extern const std::string CURRENCY_UNIT; diff --git a/src/coins.cpp b/src/coins.cpp --- a/src/coins.cpp +++ b/src/coins.cpp @@ -320,7 +320,7 @@ continue; } if (int64_t(coin.GetHeight()) <= nHeight) { - dResult += double(coin.GetTxOut().nValue.GetSatoshis()) * + dResult += double(coin.GetTxOut().nValue / SATOSHI) * (nHeight - coin.GetHeight()); inChainInputValue += coin.GetTxOut().nValue; } diff --git a/src/miner.h b/src/miner.h --- a/src/miner.h +++ b/src/miner.h @@ -72,10 +72,8 @@ struct CompareModifiedEntry { bool operator()(const CTxMemPoolModifiedEntry &a, const CTxMemPoolModifiedEntry &b) const { - double f1 = double(b.nSizeWithAncestors * - a.nModFeesWithAncestors.GetSatoshis()); - double f2 = double(a.nSizeWithAncestors * - b.nModFeesWithAncestors.GetSatoshis()); + double f1 = b.nSizeWithAncestors * (a.nModFeesWithAncestors / SATOSHI); + double f2 = a.nSizeWithAncestors * (b.nModFeesWithAncestors / SATOSHI); if (f1 == f2) { return CTxMemPool::CompareIteratorByHash()(a.iter, b.iter); } @@ -89,8 +87,9 @@ struct CompareTxIterByAncestorCount { bool operator()(const CTxMemPool::txiter &a, const CTxMemPool::txiter &b) const { - if (a->GetCountWithAncestors() != b->GetCountWithAncestors()) + if (a->GetCountWithAncestors() != b->GetCountWithAncestors()) { return a->GetCountWithAncestors() < b->GetCountWithAncestors(); + } return CTxMemPool::CompareIteratorByHash()(a, b); } }; diff --git a/src/policy/fees.cpp b/src/policy/fees.cpp --- a/src/policy/fees.cpp +++ b/src/policy/fees.cpp @@ -343,13 +343,13 @@ static_assert(MIN_FEERATE > Amount(0), "Min feerate must be nonzero"); CFeeRate minFeeRate(MIN_FEERATE); std::vector vfeelist; - for (double bucketBoundary = minFeeRate.GetFeePerK().GetSatoshis(); - bucketBoundary <= double(MAX_FEERATE.GetSatoshis()); + for (double bucketBoundary = minFeeRate.GetFeePerK() / SATOSHI; + bucketBoundary <= double(MAX_FEERATE / SATOSHI); bucketBoundary *= FEE_SPACING) { vfeelist.push_back(bucketBoundary); } - vfeelist.push_back(double(INF_FEERATE.GetSatoshis())); + vfeelist.push_back(double(INF_FEERATE / SATOSHI)); feeStats.Initialize(vfeelist, MAX_BLOCK_CONFIRMS, DEFAULT_DECAY); } @@ -386,7 +386,7 @@ mapMemPoolTxs[txid].blockHeight = txHeight; mapMemPoolTxs[txid].bucketIndex = - feeStats.NewTx(txHeight, double(feeRate.GetFeePerK().GetSatoshis())); + feeStats.NewTx(txHeight, double(feeRate.GetFeePerK() / SATOSHI)); } bool CBlockPolicyEstimator::processBlockTx(unsigned int nBlockHeight, @@ -412,8 +412,7 @@ // Feerates are stored and reported as BCH-per-kb: CFeeRate feeRate(entry->GetFee(), entry->GetTxSize()); - feeStats.Record(blocksToConfirm, - (double)feeRate.GetFeePerK().GetSatoshis()); + feeStats.Record(blocksToConfirm, double(feeRate.GetFeePerK() / SATOSHI)); return true; } @@ -540,8 +539,8 @@ Amount minFeeLimit = std::max(Amount(1), minIncrementalFee.GetFeePerK() / 2); feeset.insert(Amount(0)); - for (double bucketBoundary = minFeeLimit.GetSatoshis(); - bucketBoundary <= double(MAX_FEERATE.GetSatoshis()); + for (double bucketBoundary = minFeeLimit / SATOSHI; + bucketBoundary <= double(MAX_FEERATE / SATOSHI); bucketBoundary *= FEE_SPACING) { feeset.insert(Amount(int64_t(bucketBoundary))); } diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -411,11 +411,10 @@ info.push_back(Pair("descendantcount", e.GetCountWithDescendants())); info.push_back(Pair("descendantsize", e.GetSizeWithDescendants())); info.push_back( - Pair("descendantfees", e.GetModFeesWithDescendants().GetSatoshis())); + Pair("descendantfees", e.GetModFeesWithDescendants() / SATOSHI)); info.push_back(Pair("ancestorcount", e.GetCountWithAncestors())); info.push_back(Pair("ancestorsize", e.GetSizeWithAncestors())); - info.push_back( - Pair("ancestorfees", e.GetModFeesWithAncestors().GetSatoshis())); + info.push_back(Pair("ancestorfees", e.GetModFeesWithAncestors() / SATOSHI)); const CTransaction &tx = e.GetTx(); std::set setDepends; for (const CTxIn &txin : tx.vin) { @@ -875,7 +874,7 @@ for (const auto output : outputs) { ss << VARINT(output.first + 1); ss << output.second.GetTxOut().scriptPubKey; - ss << VARINT(output.second.GetTxOut().nValue.GetSatoshis()); + ss << VARINT(output.second.GetTxOut().nValue / SATOSHI); stats.nTransactionOutputs++; stats.nTotalAmount += output.second.GetTxOut().nValue; stats.nBogoSize += diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -675,8 +675,8 @@ entry.push_back(Pair("depends", deps)); int index_in_template = i - 1; - entry.push_back(Pair( - "fee", pblocktemplate->vTxFees[index_in_template].GetSatoshis())); + entry.push_back( + Pair("fee", pblocktemplate->vTxFees[index_in_template] / SATOSHI)); int64_t nTxSigOps = pblocktemplate->vTxSigOpsCount[index_in_template]; entry.push_back(Pair("sigops", nTxSigOps)); @@ -770,9 +770,8 @@ result.push_back(Pair("previousblockhash", pblock->hashPrevBlock.GetHex())); result.push_back(Pair("transactions", transactions)); result.push_back(Pair("coinbaseaux", aux)); - result.push_back( - Pair("coinbasevalue", - (int64_t)pblock->vtx[0]->vout[0].nValue.GetSatoshis())); + result.push_back(Pair("coinbasevalue", + int64_t(pblock->vtx[0]->vout[0].nValue / SATOSHI))); result.push_back(Pair("longpollid", chainActive.Tip()->GetBlockHash().GetHex() + i64tostr(nTransactionsUpdatedLast))); diff --git a/src/txmempool.h b/src/txmempool.h --- a/src/txmempool.h +++ b/src/txmempool.h @@ -32,7 +32,7 @@ class Config; inline double AllowFreeThreshold() { - return COIN.GetSatoshis() * 144 / 250; + return (144 * COIN) / (250 * SATOSHI); } inline bool AllowFree(double dPriority) { @@ -256,14 +256,14 @@ bool fUseBDescendants = UseDescendantScore(b); double aModFee = (fUseADescendants ? a.GetModFeesWithDescendants() - : a.GetModifiedFee()) - .GetSatoshis(); + : a.GetModifiedFee()) / + SATOSHI; double aSize = fUseADescendants ? a.GetSizeWithDescendants() : a.GetTxSize(); double bModFee = (fUseBDescendants ? b.GetModFeesWithDescendants() - : b.GetModifiedFee()) - .GetSatoshis(); + : b.GetModifiedFee()) / + SATOSHI; double bSize = fUseBDescendants ? b.GetSizeWithDescendants() : b.GetTxSize(); @@ -279,10 +279,8 @@ // Calculate which score to use for an entry (avoiding division). bool UseDescendantScore(const CTxMemPoolEntry &a) const { - double f1 = double(a.GetSizeWithDescendants() * - a.GetModifiedFee().GetSatoshis()); - double f2 = - double(a.GetTxSize() * a.GetModFeesWithDescendants().GetSatoshis()); + double f1 = a.GetSizeWithDescendants() * (a.GetModifiedFee() / SATOSHI); + double f2 = a.GetTxSize() * (a.GetModFeesWithDescendants() / SATOSHI); return f2 > f1; } }; @@ -294,8 +292,8 @@ class CompareTxMemPoolEntryByScore { public: bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const { - double f1 = double(b.GetTxSize() * a.GetModifiedFee().GetSatoshis()); - double f2 = double(a.GetTxSize() * b.GetModifiedFee().GetSatoshis()); + double f1 = b.GetTxSize() * (a.GetModifiedFee() / SATOSHI); + double f2 = a.GetTxSize() * (b.GetModifiedFee() / SATOSHI); if (f1 == f2) { return b.GetTx().GetId() < a.GetTx().GetId(); } @@ -313,10 +311,10 @@ class CompareTxMemPoolEntryByAncestorFee { public: bool operator()(const CTxMemPoolEntry &a, const CTxMemPoolEntry &b) const { - double aFees = double(a.GetModFeesWithAncestors().GetSatoshis()); + double aFees = a.GetModFeesWithAncestors() / SATOSHI; double aSize = a.GetSizeWithAncestors(); - double bFees = double(b.GetModFeesWithAncestors().GetSatoshis()); + double bFees = b.GetModFeesWithAncestors() / SATOSHI; double bSize = b.GetSizeWithAncestors(); // Avoid division by rewriting (a/b > c/d) as (a*d > c*b). diff --git a/src/txmempool.cpp b/src/txmempool.cpp --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -1180,8 +1180,8 @@ void CTxMemPool::trackPackageRemoved(const CFeeRate &rate) { AssertLockHeld(cs); - if (rate.GetFeePerK().GetSatoshis() > rollingMinimumFeeRate) { - rollingMinimumFeeRate = rate.GetFeePerK().GetSatoshis(); + if ((rate.GetFeePerK() / SATOSHI) > rollingMinimumFeeRate) { + rollingMinimumFeeRate = rate.GetFeePerK() / SATOSHI; blockSinceLastRollingFeeBump = false; } }