diff --git a/src/addrman.cpp b/src/addrman.cpp --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -725,7 +725,7 @@ return CAddrInfo(); } - CAddrInfo &newInfo = id_new_it->second; + const CAddrInfo &newInfo = id_new_it->second; // which tried bucket to move the entry to int tried_bucket = newInfo.GetTriedBucket(nKey, m_asmap); diff --git a/src/logging.h b/src/logging.h --- a/src/logging.h +++ b/src/logging.h @@ -150,9 +150,9 @@ bool WillLogCategory(LogFlags category) const; /** Returns a vector of the log categories */ - std::vector LogCategoriesList(); + std::vector LogCategoriesList() const; /** Returns a string with the log categories */ - std::string LogCategoriesString() { + std::string LogCategoriesString() const { return Join(LogCategoriesList(), ", ", [&](const LogCategory &i) { return i.category; }); }; diff --git a/src/logging.cpp b/src/logging.cpp --- a/src/logging.cpp +++ b/src/logging.cpp @@ -142,7 +142,7 @@ return false; } -std::vector BCLog::Logger::LogCategoriesList() { +std::vector BCLog::Logger::LogCategoriesList() const { std::vector ret; for (const CLogCategoryDesc &category_desc : LogCategories) { // Omit the special cases. diff --git a/src/miner.h b/src/miner.h --- a/src/miner.h +++ b/src/miner.h @@ -203,7 +203,7 @@ * succeed, and they're here only as an extra check in case of suboptimal * node configuration. */ - bool TestPackageTransactions(const CTxMemPool::setEntries &package); + bool TestPackageTransactions(const CTxMemPool::setEntries &package) const; /** * Return true if given transaction from mapTx has already been evaluated, * or if the transaction's cached data in mapTx is incorrect. diff --git a/src/miner.cpp b/src/miner.cpp --- a/src/miner.cpp +++ b/src/miner.cpp @@ -273,7 +273,7 @@ * - Serialized size (in case -blockmaxsize is in use) */ bool BlockAssembler::TestPackageTransactions( - const CTxMemPool::setEntries &package) { + const CTxMemPool::setEntries &package) const { uint64_t nPotentialBlockSize = nBlockSize; for (CTxMemPool::txiter it : package) { TxValidationState state; diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -61,7 +61,7 @@ } CTxMemPool &EnsureMemPool(const util::Ref &context) { - NodeContext &node = EnsureNodeContext(context); + const NodeContext &node = EnsureNodeContext(context); if (!node.mempool) { throw JSONRPCError(RPC_CLIENT_MEMPOOL_DISABLED, "Mempool disabled or instance not found"); @@ -70,7 +70,7 @@ } ChainstateManager &EnsureChainman(const util::Ref &context) { - NodeContext &node = EnsureNodeContext(context); + const NodeContext &node = EnsureNodeContext(context); if (!node.chainman) { throw JSONRPCError(RPC_INTERNAL_ERROR, "Node chainman not found"); } diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -127,8 +127,8 @@ uint32_t m_first_false_pos = NO_FALSE; public: - bool empty() { return m_stack_size == 0; } - bool all_true() { return m_first_false_pos == NO_FALSE; } + bool empty() const { return m_stack_size == 0; } + bool all_true() const { return m_first_false_pos == NO_FALSE; } void push_back(bool f) { if (m_first_false_pos == NO_FALSE && !f) { // The stack consists of all true values, and a false is added. diff --git a/src/script/sign.cpp b/src/script/sign.cpp --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -363,7 +363,7 @@ CMutableTransaction &txTo, unsigned int nIn, SigHashType sigHashType) { assert(nIn < txTo.vin.size()); - CTxIn &txin = txTo.vin[nIn]; + const CTxIn &txin = txTo.vin[nIn]; assert(txin.prevout.GetN() < txFrom.vout.size()); const CTxOut &txout = txFrom.vout[txin.prevout.GetN()]; diff --git a/src/test/checkqueue_tests.cpp b/src/test/checkqueue_tests.cpp --- a/src/test/checkqueue_tests.cpp +++ b/src/test/checkqueue_tests.cpp @@ -27,7 +27,7 @@ static const int SCRIPT_CHECK_THREADS = 3; struct FakeCheck { - bool operator()() { return true; } + bool operator()() const { return true; } void swap(FakeCheck &x){}; }; @@ -44,7 +44,7 @@ bool fails; FailingCheck(bool _fails) : fails(_fails){}; FailingCheck() : fails(true){}; - bool operator()() { return !fails; } + bool operator()() const { return !fails; } void swap(FailingCheck &x) { std::swap(fails, x.fails); }; }; @@ -65,7 +65,7 @@ struct MemoryCheck { static std::atomic fake_allocated_memory; bool b{false}; - bool operator()() { return true; } + bool operator()() const { return true; } MemoryCheck(){}; MemoryCheck(const MemoryCheck &x) { // We have to do this to make sure that destructor calls are paired @@ -90,7 +90,7 @@ // Freezing can't be the default initialized behavior given how the queue // swaps in default initialized Checks. bool should_freeze{false}; - bool operator()() { return true; } + bool operator()() const { return true; } FrozenCleanupCheck() {} ~FrozenCleanupCheck() { if (should_freeze) { diff --git a/src/test/util/setup_common.h b/src/test/util/setup_common.h --- a/src/test/util/setup_common.h +++ b/src/test/util/setup_common.h @@ -164,8 +164,8 @@ TestMemPoolEntryHelper() : nFee(), nTime(0), nHeight(1), spendsCoinbase(false), nSigOpCount(1) {} - CTxMemPoolEntry FromTx(const CMutableTransaction &tx); - CTxMemPoolEntry FromTx(const CTransactionRef &tx); + CTxMemPoolEntry FromTx(const CMutableTransaction &tx) const; + CTxMemPoolEntry FromTx(const CTransactionRef &tx) const; // Change the default value TestMemPoolEntryHelper &Fee(Amount _fee) { diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -292,11 +292,13 @@ TestChain100Setup::~TestChain100Setup() {} -CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CMutableTransaction &tx) { +CTxMemPoolEntry +TestMemPoolEntryHelper::FromTx(const CMutableTransaction &tx) const { return FromTx(MakeTransactionRef(tx)); } -CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CTransactionRef &tx) { +CTxMemPoolEntry +TestMemPoolEntryHelper::FromTx(const CTransactionRef &tx) const { return CTxMemPoolEntry(tx, nFee, nTime, nHeight, spendsCoinbase, nSigOpCount, LockPoints()); } diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -814,7 +814,7 @@ //! @returns whether or not the CoinsViews object has been fully initialized //! and we can //! safely flush this object to disk. - bool CanFlushToDisk() EXCLUSIVE_LOCKS_REQUIRED(cs_main) { + bool CanFlushToDisk() const EXCLUSIVE_LOCKS_REQUIRED(cs_main) { return m_coins_views && m_coins_views->m_cacheview; } diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -494,7 +494,7 @@ LockPoints lp; m_view.SetBackend(m_viewmempool); - CCoinsViewCache &coins_cache = ::ChainstateActive().CoinsTip(); + const CCoinsViewCache &coins_cache = ::ChainstateActive().CoinsTip(); // Do all inputs exist? for (const CTxIn &txin : tx.vin) { if (!coins_cache.HaveCoinInCache(txin.prevout)) { diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1108,7 +1108,7 @@ OutputType TransactionChangeType(const std::optional &change_type, - const std::vector &vecSend); + const std::vector &vecSend) const; /** * Insert additional inputs into the transaction by calling diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -694,7 +694,7 @@ void CWallet::AddToSpends(const TxId &wtxid) { auto it = mapWallet.find(wtxid); assert(it != mapWallet.end()); - CWalletTx &thisTx = it->second; + const CWalletTx &thisTx = it->second; // Coinbases don't spend anything! if (thisTx.IsCoinBase()) { return; @@ -1176,7 +1176,7 @@ // Can't mark abandoned if confirmed or in mempool auto it = mapWallet.find(txid); assert(it != mapWallet.end()); - CWalletTx &origtx = it->second; + const CWalletTx &origtx = it->second; if (origtx.GetDepthInMainChain() != 0 || origtx.InMempool()) { return false; } @@ -3095,7 +3095,7 @@ OutputType CWallet::TransactionChangeType(const std::optional &change_type, - const std::vector &vecSend) { + const std::vector &vecSend) const { // If -changetype is specified, always use that change type. if (change_type) { return *change_type;