diff --git a/Makefile.am b/Makefile.am index ad1c903f1acb6..0c06009442fbb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,6 +22,7 @@ endif BITCOIND_BIN=$(top_builddir)/src/$(BITCOIN_DAEMON_NAME)$(EXEEXT) BITCOIN_QT_BIN=$(top_builddir)/src/qt/$(BITCOIN_GUI_NAME)$(EXEEXT) +BITCOIN_TEST_BIN=$(top_builddir)/src/test/$(BITCOIN_TEST_NAME)$(EXEEXT) BITCOIN_CLI_BIN=$(top_builddir)/src/$(BITCOIN_CLI_NAME)$(EXEEXT) BITCOIN_TX_BIN=$(top_builddir)/src/$(BITCOIN_TX_NAME)$(EXEEXT) BITCOIN_WALLET_BIN=$(top_builddir)/src/$(BITCOIN_WALLET_TOOL_NAME)$(EXEEXT) @@ -77,6 +78,7 @@ $(BITCOIN_WIN_INSTALLER): all-recursive $(MKDIR_P) $(top_builddir)/release STRIPPROG="$(STRIP)" $(INSTALL_STRIP_PROGRAM) $(BITCOIND_BIN) $(top_builddir)/release STRIPPROG="$(STRIP)" $(INSTALL_STRIP_PROGRAM) $(BITCOIN_QT_BIN) $(top_builddir)/release + STRIPPROG="$(STRIP)" $(INSTALL_STRIP_PROGRAM) $(BITCOIN_TEST_BIN) $(top_builddir)/release STRIPPROG="$(STRIP)" $(INSTALL_STRIP_PROGRAM) $(BITCOIN_CLI_BIN) $(top_builddir)/release STRIPPROG="$(STRIP)" $(INSTALL_STRIP_PROGRAM) $(BITCOIN_TX_BIN) $(top_builddir)/release STRIPPROG="$(STRIP)" $(INSTALL_STRIP_PROGRAM) $(BITCOIN_WALLET_BIN) $(top_builddir)/release diff --git a/configure.ac b/configure.ac index d216ffd04eba3..95902d3c0fb7c 100644 --- a/configure.ac +++ b/configure.ac @@ -31,6 +31,7 @@ fi BITCOIN_DAEMON_NAME=dashd BITCOIN_GUI_NAME=dash-qt +BITCOIN_TEST_NAME=test_dash BITCOIN_CLI_NAME=dash-cli BITCOIN_TX_NAME=dash-tx BITCOIN_WALLET_TOOL_NAME=dash-wallet @@ -1932,6 +1933,7 @@ AC_SUBST(COPYRIGHT_HOLDERS_SUBSTITUTION, "_COPYRIGHT_HOLDERS_SUBSTITUTION") AC_SUBST(COPYRIGHT_HOLDERS_FINAL, "_COPYRIGHT_HOLDERS_FINAL") AC_SUBST(BITCOIN_DAEMON_NAME) AC_SUBST(BITCOIN_GUI_NAME) +AC_SUBST(BITCOIN_TEST_NAME) AC_SUBST(BITCOIN_CLI_NAME) AC_SUBST(BITCOIN_TX_NAME) AC_SUBST(BITCOIN_WALLET_TOOL_NAME) diff --git a/doc/build-openbsd.md b/doc/build-openbsd.md index 8ebcb68ed24b1..efdabae92f192 100644 --- a/doc/build-openbsd.md +++ b/doc/build-openbsd.md @@ -36,7 +36,7 @@ It is not necessary to build wallet functionality to run either `dashd` or `dash `sqlite3` is required to support [descriptor wallets](descriptors.md). ``` bash -pkg_add install sqlite3 +pkg_add sqlite3 ``` ###### Legacy Wallet Support diff --git a/doc/build-osx.md b/doc/build-osx.md index 3a9d7f0e92bee..089b66fb14ec5 100644 --- a/doc/build-osx.md +++ b/doc/build-osx.md @@ -117,14 +117,6 @@ Skip if you don't intend to use the GUI. brew install qt@5 ``` -Ensure that the `qt@5` package is installed, not the `qt` package. -If 'qt' is installed, the build process will fail. -if installed, remove the `qt` package with the following command: - -``` bash -brew uninstall qt -``` - Note: Building with Qt binaries downloaded from the Qt website is not officially supported. See the notes in [#7714](https://github.com/dashpay/dash/issues/7714). diff --git a/share/setup.nsi.in b/share/setup.nsi.in index 79097c8744af1..58abe0e86a5ec 100644 --- a/share/setup.nsi.in +++ b/share/setup.nsi.in @@ -80,8 +80,7 @@ Section -Main SEC0000 File @abs_top_builddir@/release/@BITCOIN_CLI_NAME@@EXEEXT@ File @abs_top_builddir@/release/@BITCOIN_TX_NAME@@EXEEXT@ File @abs_top_builddir@/release/@BITCOIN_WALLET_TOOL_NAME@@EXEEXT@ - SetOutPath $INSTDIR\doc - File /r /x Makefile* @abs_top_srcdir@/doc\*.* + File @abs_top_builddir@/release/@BITCOIN_TEST_NAME@@EXEEXT@ SetOutPath $INSTDIR WriteRegStr HKCU "${REGKEY}\Components" Main 1 SectionEnd @@ -129,7 +128,6 @@ Section /o -un.Main UNSEC0000 Delete /REBOOTOK $INSTDIR\COPYING.txt Delete /REBOOTOK $INSTDIR\readme.txt RMDir /r /REBOOTOK $INSTDIR\daemon - RMDir /r /REBOOTOK $INSTDIR\doc DeleteRegValue HKCU "${REGKEY}\Components" Main SectionEnd diff --git a/src/crypto/muhash.cpp b/src/crypto/muhash.cpp index b79da158ba088..8c257c9ee705d 100644 --- a/src/crypto/muhash.cpp +++ b/src/crypto/muhash.cpp @@ -298,7 +298,7 @@ void Num3072::ToBytes(unsigned char (&out)[BYTE_SIZE]) { Num3072 MuHash3072::ToNum3072(Span in) { unsigned char tmp[Num3072::BYTE_SIZE]; - uint256 hashed_in = (CHashWriter(SER_DISK, 0) << in).GetSHA256(); + uint256 hashed_in{(HashWriter{} << in).GetSHA256()}; static_assert(sizeof(tmp) % ChaCha20Aligned::BLOCKLEN == 0); ChaCha20Aligned{MakeByteSpan(hashed_in)}.Keystream(MakeWritableByteSpan(tmp)); Num3072 out{tmp}; @@ -319,7 +319,7 @@ void MuHash3072::Finalize(uint256& out) noexcept unsigned char data[Num3072::BYTE_SIZE]; m_numerator.ToBytes(data); - out = (CHashWriter(SER_DISK, 0) << data).GetSHA256(); + out = (HashWriter{} << data).GetSHA256(); } MuHash3072& MuHash3072::operator*=(const MuHash3072& mul) noexcept diff --git a/src/flat-database.h b/src/flat-database.h index 75fd91225ac98..3fd0002e4b276 100644 --- a/src/flat-database.h +++ b/src/flat-database.h @@ -49,9 +49,9 @@ class CFlatDB uint256 hash = Hash(ssObj); ssObj << hash; - // open output file, and associate with CAutoFile + // open output file, and associate with AutoFile FILE *file = fsbridge::fopen(pathDB, "wb"); - CAutoFile fileout(file, SER_DISK, CLIENT_VERSION); + AutoFile fileout{file}; if (fileout.IsNull()) { return error("%s: Failed to open file %s", __func__, fs::PathToString(pathDB)); } @@ -76,9 +76,9 @@ class CFlatDB //LOCK(objToLoad.cs); const auto start{SteadyClock::now()}; - // open input file, and associate with CAutoFile + // open input file, and associate with AutoFile FILE *file = fsbridge::fopen(pathDB, "rb"); - CAutoFile filein(file, SER_DISK, CLIENT_VERSION); + AutoFile filein{file}; if (filein.IsNull()) { // It is not actually error, maybe it's a first initialization of core. return ReadResult::FileError; diff --git a/src/hash.cpp b/src/hash.cpp index 87ffc3982a395..0544468bfd94c 100644 --- a/src/hash.cpp +++ b/src/hash.cpp @@ -82,9 +82,9 @@ uint256 SHA256Uint256(const uint256& input) return result; } -CHashWriter TaggedHash(const std::string& tag) +HashWriter TaggedHash(const std::string& tag) { - CHashWriter writer(SER_GETHASH, 0); + HashWriter writer{}; uint256 taghash; CSHA256().Write((const unsigned char*)tag.data(), tag.size()).Finalize(taghash.begin()); writer << taghash << taghash; diff --git a/src/hash.h b/src/hash.h index 5dad7c72bcf77..8db12e811cd40 100644 --- a/src/hash.h +++ b/src/hash.h @@ -242,12 +242,12 @@ unsigned int MurmurHash3(unsigned int nHashSeed, Span vData void BIP32Hash(const ChainCode &chainCode, unsigned int nChild, unsigned char header, const unsigned char data[32], unsigned char output[64]); -/** Return a CHashWriter primed for tagged hashes (as specified in BIP 340). +/** Return a HashWriter primed for tagged hashes (as specified in BIP 340). * * The returned object will have SHA256(tag) written to it twice (= 64 bytes). * A tagged hash can be computed by feeding the message into this object, and - * then calling CHashWriter::GetSHA256(). + * then calling HashWriter::GetSHA256(). */ -CHashWriter TaggedHash(const std::string& tag); +HashWriter TaggedHash(const std::string& tag); #endif // BITCOIN_HASH_H diff --git a/src/index/blockfilterindex.cpp b/src/index/blockfilterindex.cpp index c0cf84e512850..38697b4315aa6 100644 --- a/src/index/blockfilterindex.cpp +++ b/src/index/blockfilterindex.cpp @@ -166,7 +166,7 @@ bool BlockFilterIndex::CommitInternal(CDBBatch& batch) } // Flush current filter file to disk. - CAutoFile file(m_filter_fileseq->Open(pos), SER_DISK, CLIENT_VERSION); + AutoFile file{m_filter_fileseq->Open(pos)}; if (file.IsNull()) { return error("%s: Failed to open filter file %d", __func__, pos.nFile); } @@ -180,7 +180,7 @@ bool BlockFilterIndex::CommitInternal(CDBBatch& batch) bool BlockFilterIndex::ReadFilterFromDisk(const FlatFilePos& pos, const uint256& hash, BlockFilter& filter) const { - CAutoFile filein(m_filter_fileseq->Open(pos, true), SER_DISK, CLIENT_VERSION); + AutoFile filein{m_filter_fileseq->Open(pos, true)}; if (filein.IsNull()) { return false; } @@ -210,7 +210,7 @@ size_t BlockFilterIndex::WriteFilterToDisk(FlatFilePos& pos, const BlockFilter& // If writing the filter would overflow the file, flush and move to the next one. if (pos.nPos + data_size > MAX_FLTR_FILE_SIZE) { - CAutoFile last_file(m_filter_fileseq->Open(pos), SER_DISK, CLIENT_VERSION); + AutoFile last_file{m_filter_fileseq->Open(pos)}; if (last_file.IsNull()) { LogPrintf("%s: Failed to open filter file %d\n", __func__, pos.nFile); return 0; @@ -236,7 +236,7 @@ size_t BlockFilterIndex::WriteFilterToDisk(FlatFilePos& pos, const BlockFilter& return 0; } - CAutoFile fileout(m_filter_fileseq->Open(pos), SER_DISK, CLIENT_VERSION); + AutoFile fileout{m_filter_fileseq->Open(pos)}; if (fileout.IsNull()) { LogPrintf("%s: Failed to open filter file %d\n", __func__, pos.nFile); return 0; diff --git a/src/index/txindex.cpp b/src/index/txindex.cpp index 5c2c784543313..1a6a0cf7fe017 100644 --- a/src/index/txindex.cpp +++ b/src/index/txindex.cpp @@ -80,7 +80,7 @@ bool TxIndex::FindTx(const uint256& tx_hash, uint256& block_hash, CTransactionRe return false; } - CAutoFile file(OpenBlockFile(postx, true), SER_DISK, CLIENT_VERSION); + AutoFile file{OpenBlockFile(postx, true)}; if (file.IsNull()) { return error("%s: OpenBlockFile failed", __func__); } diff --git a/src/net.cpp b/src/net.cpp index 1ba0dee0cc6d3..159f712fb17f1 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -4886,7 +4886,7 @@ static void CaptureMessageToFile(const CAddress& addr, fs::create_directories(base_path); fs::path path = base_path / (is_incoming ? "msgs_recv.dat" : "msgs_sent.dat"); - CAutoFile f(fsbridge::fopen(path, "ab"), SER_DISK, CLIENT_VERSION); + AutoFile f{fsbridge::fopen(path, "ab")}; ser_writedata64(f, now.count()); f.write(MakeByteSpan(msg_type)); diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp index 0a5ca022fa732..9752b66358885 100644 --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -505,7 +505,7 @@ static bool UndoWriteToDisk(const CBlockUndo& blockundo, FlatFilePos& pos, const fileout << blockundo; // calculate & write checksum - CHashWriter hasher(SER_GETHASH, PROTOCOL_VERSION); + HashWriter hasher{}; hasher << hashBlock; hasher << blockundo; fileout << hasher.GetHash(); diff --git a/src/node/coinstats.cpp b/src/node/coinstats.cpp index c31509e153044..d824bf563de6e 100644 --- a/src/node/coinstats.cpp +++ b/src/node/coinstats.cpp @@ -50,7 +50,7 @@ CDataStream TxOutSer(const COutPoint& outpoint, const Coin& coin) { //! It is also possible, though very unlikely, that a change in this //! construction could cause a previously invalid (and potentially malicious) //! UTXO snapshot to be considered valid. -static void ApplyHash(CHashWriter& ss, const uint256& hash, const std::map& outputs) +static void ApplyHash(HashWriter& ss, const uint256& hash, const std::map& outputs) { for (auto it = outputs.begin(); it != outputs.end(); ++it) { if (it == outputs.begin()) { @@ -149,7 +149,7 @@ bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& stats, { switch (stats.m_hash_type) { case(CoinStatsHashType::HASH_SERIALIZED): { - CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); + HashWriter ss{}; return GetUTXOStats(view, blockman, stats, ss, interruption_point, pindex); } case(CoinStatsHashType::MUHASH): { @@ -164,7 +164,7 @@ bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& stats, } // The legacy hash serializes the hashBlock -static void PrepareHash(CHashWriter& ss, const CCoinsStats& stats) +static void PrepareHash(HashWriter& ss, const CCoinsStats& stats) { ss << stats.hashBlock; } @@ -172,7 +172,7 @@ static void PrepareHash(CHashWriter& ss, const CCoinsStats& stats) static void PrepareHash(MuHash3072& muhash, CCoinsStats& stats) {} static void PrepareHash(std::nullptr_t, CCoinsStats& stats) {} -static void FinalizeHash(CHashWriter& ss, CCoinsStats& stats) +static void FinalizeHash(HashWriter& ss, CCoinsStats& stats) { stats.hashSerialized = ss.GetHash(); } diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index 420dd9f6baf37..8b589e3434368 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -828,7 +828,7 @@ class ChainImpl : public Chain std::optional getHeight() override { LOCK(::cs_main); - const CChain& active = Assert(m_node.chainman)->ActiveChain(); + const CChain& active = chainman().ActiveChain(); int height = active.Height(); if (height >= 0) { return height; @@ -838,7 +838,7 @@ class ChainImpl : public Chain uint256 getBlockHash(int height) override { LOCK(::cs_main); - const CChain& active = Assert(m_node.chainman)->ActiveChain(); + const CChain& active = chainman().ActiveChain(); CBlockIndex* block = active[height]; assert(block != nullptr); return block->GetBlockHash(); @@ -846,7 +846,7 @@ class ChainImpl : public Chain bool haveBlockOnDisk(int height) override { LOCK(::cs_main); - const CChain& active = Assert(m_node.chainman)->ActiveChain(); + const CChain& active = chainman().ActiveChain(); CBlockIndex* block = active[height]; return block && ((block->nStatus & BLOCK_HAVE_DATA) != 0) && block->nTx > 0; } @@ -883,7 +883,7 @@ class ChainImpl : public Chain std::optional findLocatorFork(const CBlockLocator& locator) override { LOCK(::cs_main); - const CChainState& active = Assert(m_node.chainman)->ActiveChainstate(); + const CChainState& active = chainman().ActiveChainstate(); if (const CBlockIndex* fork = active.FindForkInGlobalIndex(locator)) { return fork->nHeight; } @@ -918,20 +918,20 @@ class ChainImpl : public Chain bool findBlock(const uint256& hash, const FoundBlock& block) override { WAIT_LOCK(cs_main, lock); - const CChain& active = Assert(m_node.chainman)->ActiveChain(); - return FillBlock(m_node.chainman->m_blockman.LookupBlockIndex(hash), block, lock, active); + const CChain& active = chainman().ActiveChain(); + return FillBlock(chainman().m_blockman.LookupBlockIndex(hash), block, lock, active); } bool findFirstBlockWithTimeAndHeight(int64_t min_time, int min_height, const FoundBlock& block) override { WAIT_LOCK(cs_main, lock); - const CChain& active = Assert(m_node.chainman)->ActiveChain(); + const CChain& active = chainman().ActiveChain(); return FillBlock(active.FindEarliestAtLeast(min_time, min_height), block, lock, active); } bool findAncestorByHeight(const uint256& block_hash, int ancestor_height, const FoundBlock& ancestor_out) override { WAIT_LOCK(cs_main, lock); - const CChain& active = Assert(m_node.chainman)->ActiveChain(); - if (const CBlockIndex* block = m_node.chainman->m_blockman.LookupBlockIndex(block_hash)) { + const CChain& active = chainman().ActiveChain(); + if (const CBlockIndex* block = chainman().m_blockman.LookupBlockIndex(block_hash)) { if (const CBlockIndex* ancestor = block->GetAncestor(ancestor_height)) { return FillBlock(ancestor, ancestor_out, lock, active); } @@ -941,18 +941,18 @@ class ChainImpl : public Chain bool findAncestorByHash(const uint256& block_hash, const uint256& ancestor_hash, const FoundBlock& ancestor_out) override { WAIT_LOCK(cs_main, lock); - const CChain& active = Assert(m_node.chainman)->ActiveChain(); - const CBlockIndex* block = m_node.chainman->m_blockman.LookupBlockIndex(block_hash); - const CBlockIndex* ancestor = m_node.chainman->m_blockman.LookupBlockIndex(ancestor_hash); + const CChain& active = chainman().ActiveChain(); + const CBlockIndex* block = chainman().m_blockman.LookupBlockIndex(block_hash); + const CBlockIndex* ancestor = chainman().m_blockman.LookupBlockIndex(ancestor_hash); if (block && ancestor && block->GetAncestor(ancestor->nHeight) != ancestor) ancestor = nullptr; return FillBlock(ancestor, ancestor_out, lock, active); } bool findCommonAncestor(const uint256& block_hash1, const uint256& block_hash2, const FoundBlock& ancestor_out, const FoundBlock& block1_out, const FoundBlock& block2_out) override { WAIT_LOCK(cs_main, lock); - const CChain& active = Assert(m_node.chainman)->ActiveChain(); - const CBlockIndex* block1 = m_node.chainman->m_blockman.LookupBlockIndex(block_hash1); - const CBlockIndex* block2 = m_node.chainman->m_blockman.LookupBlockIndex(block_hash2); + const CChain& active = chainman().ActiveChain(); + const CBlockIndex* block1 = chainman().m_blockman.LookupBlockIndex(block_hash1); + const CBlockIndex* block2 = chainman().m_blockman.LookupBlockIndex(block_hash2); const CBlockIndex* ancestor = block1 && block2 ? LastCommonAncestor(block1, block2) : nullptr; // Using & instead of && below to avoid short circuiting and leaving // output uninitialized. Cast bool to int to avoid -Wbitwise-instead-of-logical @@ -1055,7 +1055,7 @@ class ChainImpl : public Chain bool havePruned() override { LOCK(::cs_main); - return m_node.chainman->m_blockman.m_have_pruned; + return chainman().m_blockman.m_have_pruned; } bool isReadyToBroadcast() override { return !node::fImporting && !node::fReindex && !isInitialBlockDownload(); } bool isInitialBlockDownload() override { @@ -1077,7 +1077,7 @@ class ChainImpl : public Chain { if (!old_tip.IsNull()) { LOCK(::cs_main); - const CChain& active = Assert(m_node.chainman)->ActiveChain(); + const CChain& active = chainman().ActiveChain(); if (old_tip == active.Tip()->GetBlockHash()) return; } SyncWithValidationInterfaceQueue(); @@ -1130,7 +1130,7 @@ class ChainImpl : public Chain } bool hasAssumedValidChain() override { - return Assert(m_node.chainman)->IsSnapshotActive(); + return chainman().IsSnapshotActive(); } NodeContext& m_node; diff --git a/src/node/txreconciliation.cpp b/src/node/txreconciliation.cpp index 03d4258a84aa1..ed04a78cecfad 100644 --- a/src/node/txreconciliation.cpp +++ b/src/node/txreconciliation.cpp @@ -15,7 +15,7 @@ namespace { /** Static salt component used to compute short txids for sketch construction, see BIP-330. */ const std::string RECON_STATIC_SALT = "Tx Relay Salting"; -const CHashWriter RECON_SALT_HASHER = TaggedHash(RECON_STATIC_SALT); +const HashWriter RECON_SALT_HASHER = TaggedHash(RECON_STATIC_SALT); /** * Salt (specified by BIP-330) constructed from contributions from both peers. It is used diff --git a/src/policy/fees.cpp b/src/policy/fees.cpp index c5f97a13191fd..e0586637450a3 100644 --- a/src/policy/fees.cpp +++ b/src/policy/fees.cpp @@ -163,13 +163,13 @@ class TxConfirmStats unsigned int GetMaxConfirms() const { return scale * confAvg.size(); } /** Write state of estimation data to a file*/ - void Write(CAutoFile& fileout) const; + void Write(AutoFile& fileout) const; /** * Read saved state of estimation data from a file and replace all internal data structures and * variables with this state. */ - void Read(CAutoFile& filein, int nFileVersion, size_t numBuckets); + void Read(AutoFile& filein, int nFileVersion, size_t numBuckets); }; @@ -405,7 +405,7 @@ double TxConfirmStats::EstimateMedianVal(int confTarget, double sufficientTxVal, return median; } -void TxConfirmStats::Write(CAutoFile& fileout) const +void TxConfirmStats::Write(AutoFile& fileout) const { fileout << Using(decay); fileout << scale; @@ -415,7 +415,7 @@ void TxConfirmStats::Write(CAutoFile& fileout) const fileout << Using>>(failAvg); } -void TxConfirmStats::Read(CAutoFile& filein, int nFileVersion, size_t numBuckets) +void TxConfirmStats::Read(AutoFile& filein, int nFileVersion, size_t numBuckets) { // Read data file and do some very basic sanity checking // buckets and bucketMap are not updated yet, so don't access them @@ -562,7 +562,7 @@ CBlockPolicyEstimator::CBlockPolicyEstimator() // If the fee estimation file is present, read recorded estimations fs::path est_filepath = gArgs.GetDataDirNet() / FEE_ESTIMATES_FILENAME; - CAutoFile est_file(fsbridge::fopen(est_filepath, "rb"), SER_DISK, CLIENT_VERSION); + AutoFile est_file{fsbridge::fopen(est_filepath, "rb")}; if (est_file.IsNull() || !Read(est_file)) { LogPrintf("Failed to read fee estimates from %s. Continue anyway.\n", fs::PathToString(est_filepath)); } @@ -920,13 +920,13 @@ void CBlockPolicyEstimator::Flush() { FlushUnconfirmed(); fs::path est_filepath = gArgs.GetDataDirNet() / FEE_ESTIMATES_FILENAME; - CAutoFile est_file(fsbridge::fopen(est_filepath, "wb"), SER_DISK, CLIENT_VERSION); + AutoFile est_file{fsbridge::fopen(est_filepath, "wb")}; if (est_file.IsNull() || !Write(est_file)) { LogPrintf("Failed to write fee estimates to %s. Continue anyway.\n", fs::PathToString(est_filepath)); } } -bool CBlockPolicyEstimator::Write(CAutoFile& fileout) const +bool CBlockPolicyEstimator::Write(AutoFile& fileout) const { try { LOCK(m_cs_fee_estimator); @@ -951,7 +951,7 @@ bool CBlockPolicyEstimator::Write(CAutoFile& fileout) const return true; } -bool CBlockPolicyEstimator::Read(CAutoFile& filein) +bool CBlockPolicyEstimator::Read(AutoFile& filein) { try { LOCK(m_cs_fee_estimator); diff --git a/src/policy/fees.h b/src/policy/fees.h index 753d983cf8b0b..3a0ed2dc1b116 100644 --- a/src/policy/fees.h +++ b/src/policy/fees.h @@ -19,7 +19,7 @@ #include #include -class CAutoFile; +class AutoFile; class CTxMemPoolEntry; class TxConfirmStats; @@ -218,11 +218,11 @@ class CBlockPolicyEstimator EXCLUSIVE_LOCKS_REQUIRED(!m_cs_fee_estimator); /** Write estimation data to a file */ - bool Write(CAutoFile& fileout) const + bool Write(AutoFile& fileout) const EXCLUSIVE_LOCKS_REQUIRED(!m_cs_fee_estimator); /** Read estimation data from a file */ - bool Read(CAutoFile& filein) + bool Read(AutoFile& filein) EXCLUSIVE_LOCKS_REQUIRED(!m_cs_fee_estimator); /** Empty mempool transactions on shutdown to record failure to confirm for txs still in mempool */ diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 505fce3303a96..7387f553db98e 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -451,7 +451,7 @@ static RPCHelpMan syncwithvalidationinterfacequeue() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { SyncWithValidationInterfaceQueue(); - return NullUniValue; + return UniValue::VNULL; }, }; } @@ -896,11 +896,12 @@ const RPCResult getblock_vin{ { {RPCResult::Type::BOOL, "generated", "Coinbase or not"}, {RPCResult::Type::NUM, "height", "The height of the prevout"}, - {RPCResult::Type::NUM, "value", "The value in " + CURRENCY_UNIT}, + {RPCResult::Type::STR_AMOUNT, "value", "The value in " + CURRENCY_UNIT}, {RPCResult::Type::OBJ, "scriptPubKey", "", { - {RPCResult::Type::STR, "asm", "The asm"}, - {RPCResult::Type::STR_HEX, "hex", "The hex"}, + {RPCResult::Type::STR, "asm", "Disassembly of the public key script"}, + {RPCResult::Type::STR, "desc", "Inferred descriptor for the output"}, + {RPCResult::Type::STR_HEX, "hex", "The raw public key script bytes, hex-encoded"}, {RPCResult::Type::STR, "address", /*optional=*/true, "The Dash address (only if a well-defined address exists)"}, {RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"}, }}, @@ -1266,9 +1267,9 @@ static RPCHelpMan gettxout() {RPCResult::Type::STR_AMOUNT, "value", "The transaction value in " + CURRENCY_UNIT}, {RPCResult::Type::OBJ, "scriptPubKey", "", { - {RPCResult::Type::STR, "asm", "The asm"}, + {RPCResult::Type::STR, "asm", "Disassembly of the public key script"}, {RPCResult::Type::STR, "desc", "Inferred descriptor for the output"}, - {RPCResult::Type::STR_HEX, "hex", "The hex"}, + {RPCResult::Type::STR_HEX, "hex", "The raw public key script bytes, hex-encoded"}, {RPCResult::Type::STR_HEX, "type", "The type, eg pubkeyhash"}, {RPCResult::Type::STR, "address", /*optional=*/ true, "Dash address (only if a well-defined address exists)"}, }}, @@ -1309,11 +1310,11 @@ static RPCHelpMan gettxout() LOCK(mempool.cs); CCoinsViewMemPool view(coins_view, mempool); if (!view.GetCoin(out, coin) || mempool.isSpent(out)) { - return NullUniValue; + return UniValue::VNULL; } } else { if (!coins_view->GetCoin(out, coin)) { - return NullUniValue; + return UniValue::VNULL; } } @@ -1740,7 +1741,7 @@ static RPCHelpMan preciousblock() throw JSONRPCError(RPC_DATABASE_ERROR, state.ToString()); } - return NullUniValue; + return UniValue::VNULL; }, }; } @@ -1783,7 +1784,7 @@ static RPCHelpMan invalidateblock() throw JSONRPCError(RPC_DATABASE_ERROR, state.ToString()); } - return NullUniValue; + return UniValue::VNULL; }, }; } @@ -1827,7 +1828,7 @@ static RPCHelpMan reconsiderblock() throw JSONRPCError(RPC_DATABASE_ERROR, state.ToString()); } - return NullUniValue; + return UniValue::VNULL; }, }; } @@ -2460,7 +2461,7 @@ static RPCHelpMan scantxoutset() CoinsViewScanReserver reserver; if (reserver.reserve()) { // no scan in progress - return NullUniValue; + return UniValue::VNULL; } result.pushKV("progress", g_scan_progress.load()); return result; @@ -2671,7 +2672,7 @@ static RPCHelpMan dumptxoutset() } FILE* file{fsbridge::fopen(temppath, "wb")}; - CAutoFile afile{file, SER_DISK, CLIENT_VERSION}; + AutoFile afile{file}; if (afile.IsNull()) { throw JSONRPCError( RPC_INVALID_PARAMETER, @@ -2692,7 +2693,7 @@ static RPCHelpMan dumptxoutset() UniValue CreateUTXOSnapshot( NodeContext& node, CChainState& chainstate, - CAutoFile& afile, + AutoFile& afile, const fs::path& path, const fs::path& temppath) { diff --git a/src/rpc/blockchain.h b/src/rpc/blockchain.h index 6438cfcf6a029..824c9d70ba744 100644 --- a/src/rpc/blockchain.h +++ b/src/rpc/blockchain.h @@ -58,7 +58,7 @@ void CalculatePercentilesBySize(CAmount result[NUM_GETBLOCKSTATS_PERCENTILES], s UniValue CreateUTXOSnapshot( node::NodeContext& node, CChainState& chainstate, - CAutoFile& afile, + AutoFile& afile, const fs::path& path, const fs::path& tmppath); diff --git a/src/rpc/coinjoin.cpp b/src/rpc/coinjoin.cpp index ef578d7261018..e8e8165b7f763 100644 --- a/src/rpc/coinjoin.cpp +++ b/src/rpc/coinjoin.cpp @@ -83,7 +83,7 @@ static RPCHelpMan coinjoin_reset() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr wallet = GetWalletForJSONRPCRequest(request); - if (!wallet) return NullUniValue; + if (!wallet) return UniValue::VNULL; const NodeContext& node = EnsureAnyNodeContext(request.context); @@ -117,7 +117,7 @@ static RPCHelpMan coinjoin_start() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr wallet = GetWalletForJSONRPCRequest(request); - if (!wallet) return NullUniValue; + if (!wallet) return UniValue::VNULL; const NodeContext& node = EnsureAnyNodeContext(request.context); @@ -158,7 +158,7 @@ static RPCHelpMan coinjoin_status() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr wallet = GetWalletForJSONRPCRequest(request); - if (!wallet) return NullUniValue; + if (!wallet) return UniValue::VNULL; const NodeContext& node = EnsureAnyNodeContext(request.context); @@ -197,7 +197,7 @@ static RPCHelpMan coinjoin_stop() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr wallet = GetWalletForJSONRPCRequest(request); - if (!wallet) return NullUniValue; + if (!wallet) return UniValue::VNULL; const NodeContext& node = EnsureAnyNodeContext(request.context); @@ -258,7 +258,7 @@ static RPCHelpMan coinjoinsalt_generate() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); - if (!wallet) return NullUniValue; + if (!wallet) return UniValue::VNULL; const auto str_wallet = wallet->GetName(); if (wallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { @@ -322,7 +322,7 @@ static RPCHelpMan coinjoinsalt_get() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); - if (!wallet) return NullUniValue; + if (!wallet) return UniValue::VNULL; const auto str_wallet = wallet->GetName(); if (wallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { @@ -360,7 +360,7 @@ static RPCHelpMan coinjoinsalt_set() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); - if (!wallet) return NullUniValue; + if (!wallet) return UniValue::VNULL; const auto salt{ParseHashV(request.params[0], "salt")}; if (salt == uint256::ZERO) { diff --git a/src/rpc/evo.cpp b/src/rpc/evo.cpp index 81bf1ecd78144..d9c8189bd1adf 100644 --- a/src/rpc/evo.cpp +++ b/src/rpc/evo.cpp @@ -683,7 +683,7 @@ static UniValue protx_register_common_wrapper(const JSONRPCRequest& request, const bool isEvoRequested = mnType == MnType::Evo; std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; if (action == ProTxRegisterAction::External || action == ProTxRegisterAction::Fund) { EnsureWalletIsUnlocked(*pwallet); @@ -888,7 +888,7 @@ static RPCHelpMan protx_register_submit() CChainstateHelper& chain_helper = *CHECK_NONFATAL(node.chain_helper); const std::shared_ptr wallet = GetWalletForJSONRPCRequest(request); - if (!wallet) return NullUniValue; + if (!wallet) return UniValue::VNULL; EnsureWalletIsUnlocked(*wallet); @@ -997,7 +997,7 @@ static UniValue protx_update_service_common_wrapper(const JSONRPCRequest& reques const bool isEvoRequested = mnType == MnType::Evo; std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); - if (!wallet) return NullUniValue; + if (!wallet) return UniValue::VNULL; EnsureWalletIsUnlocked(*wallet); @@ -1131,7 +1131,7 @@ static RPCHelpMan protx_update_registrar_wrapper(const bool specific_legacy_bls_ CChainstateHelper& chain_helper = *CHECK_NONFATAL(node.chain_helper); std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); - if (!wallet) return NullUniValue; + if (!wallet) return UniValue::VNULL; EnsureWalletIsUnlocked(*wallet); @@ -1251,7 +1251,7 @@ static RPCHelpMan protx_revoke() CChainstateHelper& chain_helper = *CHECK_NONFATAL(node.chain_helper); std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; EnsureWalletIsUnlocked(*pwallet); diff --git a/src/rpc/governance.cpp b/src/rpc/governance.cpp index abbffc93804a1..d28eecce4a77d 100644 --- a/src/rpc/governance.cpp +++ b/src/rpc/governance.cpp @@ -150,7 +150,7 @@ static RPCHelpMan gobject_prepare() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); - if (!wallet) return NullUniValue; + if (!wallet) return UniValue::VNULL; EnsureWalletIsUnlocked(*wallet); @@ -259,7 +259,7 @@ static RPCHelpMan gobject_list_prepared() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); - if (!wallet) return NullUniValue; + if (!wallet) return UniValue::VNULL; EnsureWalletIsUnlocked(*wallet); int64_t nCount = request.params.empty() ? 10 : ParseInt64V(request.params[0], "count"); @@ -499,7 +499,7 @@ static RPCHelpMan gobject_vote_many() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr wallet = GetWalletForJSONRPCRequest(request); - if (!wallet) return NullUniValue; + if (!wallet) return UniValue::VNULL; const NodeContext& node = EnsureAnyNodeContext(request.context); @@ -552,7 +552,7 @@ static RPCHelpMan gobject_vote_alias() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr wallet = GetWalletForJSONRPCRequest(request); - if (!wallet) return NullUniValue; + if (!wallet) return UniValue::VNULL; const NodeContext& node = EnsureAnyNodeContext(request.context); diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index d3fc88b11f979..b35d70446de55 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -135,7 +135,7 @@ static RPCHelpMan masternode_outputs() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr wallet = GetWalletForJSONRPCRequest(request); - if (!wallet) return NullUniValue; + if (!wallet) return UniValue::VNULL; // Find possible candidates CCoinControl coin_control(CoinType::ONLY_MASTERNODE_COLLATERAL); @@ -242,7 +242,7 @@ static RPCHelpMan masternode_winners() { LOCK(::cs_main); pindexTip = chainman.ActiveChain().Tip(); - if (!pindexTip) return NullUniValue; + if (!pindexTip) return UniValue::VNULL; } int nCount = 10; diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 74cb13e40db79..11e6cd906d451 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -516,7 +516,7 @@ static RPCHelpMan prioritisetransaction() static UniValue BIP22ValidationResult(const BlockValidationState& state) { if (state.IsValid()) - return NullUniValue; + return UniValue::VNULL; if (state.IsError()) throw JSONRPCError(RPC_VERIFY_ERROR, state.ToString()); @@ -1083,7 +1083,7 @@ static RPCHelpMan submitheader() BlockValidationState state; chainman.ProcessNewBlockHeaders({h}, state, Params()); - if (state.IsValid()) return NullUniValue; + if (state.IsValid()) return UniValue::VNULL; if (state.IsError()) { throw JSONRPCError(RPC_VERIFY_ERROR, state.ToString()); } diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index fbd72f6c349da..266fc27672ca9 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -90,7 +90,7 @@ static RPCHelpMan ping() // Request that each node send a ping during next message processing pass peerman.SendPings(); - return NullUniValue; + return UniValue::VNULL; }, }; } @@ -340,7 +340,7 @@ static RPCHelpMan addnode() { CAddress addr; connman.OpenNetworkConnection(addr, /*fCountFailure=*/false, /*grant_outbound=*/{}, node_arg.c_str(), ConnectionType::MANUAL, use_v2transport); - return NullUniValue; + return UniValue::VNULL; } if (command == "add") @@ -356,7 +356,7 @@ static RPCHelpMan addnode() } } - return NullUniValue; + return UniValue::VNULL; }, }; } @@ -466,7 +466,7 @@ static RPCHelpMan disconnectnode() throw JSONRPCError(RPC_CLIENT_NODE_NOT_CONNECTED, "Node not found in connected nodes"); } - return NullUniValue; + return UniValue::VNULL; }, }; } @@ -804,7 +804,7 @@ static RPCHelpMan setban() throw JSONRPCError(RPC_CLIENT_INVALID_IP_OR_SUBNET, "Error: Unban failed. Requested address/subnet was not previously manually banned."); } } - return NullUniValue; + return UniValue::VNULL; }, }; } @@ -872,7 +872,7 @@ static RPCHelpMan clearbanned() banman.ClearBanned(); - return NullUniValue; + return UniValue::VNULL; }, }; } @@ -893,7 +893,7 @@ static RPCHelpMan cleardiscouraged() banman.ClearDiscouraged(); - return NullUniValue; + return UniValue::VNULL; }, }; } @@ -1079,7 +1079,7 @@ static RPCHelpMan sendmsgtopeer() throw JSONRPCError(RPC_MISC_ERROR, "Error: Could not send message to peer"); } - return NullUniValue; + return UniValue::VNULL; }, }; } diff --git a/src/rpc/node.cpp b/src/rpc/node.cpp index 0140bc17aec69..5b07cd49a76ae 100644 --- a/src/rpc/node.cpp +++ b/src/rpc/node.cpp @@ -191,7 +191,7 @@ static RPCHelpMan spork() return ret; } - return NullUniValue; + return UniValue::VNULL; }, }; } @@ -233,7 +233,7 @@ static RPCHelpMan sporkupdate() return "success"; } - return NullUniValue; + return UniValue::VNULL; }, }; } @@ -274,7 +274,7 @@ static RPCHelpMan setmocktime() } } - return NullUniValue; + return UniValue::VNULL; }, }; } @@ -847,7 +847,7 @@ static RPCHelpMan mockscheduler() CHECK_NONFATAL(node_context->scheduler); node_context->scheduler->MockForward(std::chrono::seconds(delta_seconds)); - return NullUniValue; + return UniValue::VNULL; }, }; } diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 18ff5550aae7a..3667d4543b4f2 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -148,8 +148,8 @@ static std::vector DecodeTxDoc(const std::string& txid_field_doc) {RPCResult::Type::NUM, "vout", /*optional=*/true, "The output number (if not coinbase transaction)"}, {RPCResult::Type::OBJ, "scriptSig", /*optional=*/true, "The script (if not coinbase transaction)", { - {RPCResult::Type::STR, "asm", "asm"}, - {RPCResult::Type::STR_HEX, "hex", "hex"}, + {RPCResult::Type::STR, "asm", "Disassembly of the signature script"}, + {RPCResult::Type::STR_HEX, "hex", "The raw signature script bytes, hex-encoded"}, }}, {RPCResult::Type::NUM, "sequence", "The script sequence number"}, }}, @@ -162,9 +162,9 @@ static std::vector DecodeTxDoc(const std::string& txid_field_doc) {RPCResult::Type::NUM, "n", "index"}, {RPCResult::Type::OBJ, "scriptPubKey", "", { - {RPCResult::Type::STR, "asm", "the asm"}, + {RPCResult::Type::STR, "asm", "Disassembly of the public key script"}, {RPCResult::Type::STR, "desc", "Inferred descriptor for the output"}, - {RPCResult::Type::STR_HEX, "hex", "the hex"}, + {RPCResult::Type::STR_HEX, "hex", "The raw public key script bytes, hex-encoded"}, {RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"}, {RPCResult::Type::STR, "address", /*optional=*/true, "The Dash address (only if a well-defined address exists)"}, }}, @@ -1033,8 +1033,8 @@ const RPCResult decodepsbt_inputs{ {RPCResult::Type::STR, "sighash", /*optional=*/true, "The sighash type to be used"}, {RPCResult::Type::OBJ, "redeem_script", /*optional=*/true, "", { - {RPCResult::Type::STR, "asm", "The asm"}, - {RPCResult::Type::STR_HEX, "hex", "The hex"}, + {RPCResult::Type::STR, "asm", "Disassembly of the redeem script"}, + {RPCResult::Type::STR_HEX, "hex", "The raw redeem script bytes, hex-encoded"}, {RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"}, }}, {RPCResult::Type::ARR, "bip32_derivs", /*optional=*/true, "", @@ -1048,8 +1048,8 @@ const RPCResult decodepsbt_inputs{ }}, {RPCResult::Type::OBJ, "final_scriptSig", /*optional=*/true, "", { - {RPCResult::Type::STR, "asm", "The asm"}, - {RPCResult::Type::STR_HEX, "hex", "The hex"}, + {RPCResult::Type::STR, "asm", "Disassembly of the final signature script"}, + {RPCResult::Type::STR_HEX, "hex", "The raw final signature script bytes, hex-encoded"}, }}, {RPCResult::Type::OBJ_DYN, "ripemd160_preimages", /*optional=*/true, "", { @@ -1092,8 +1092,8 @@ const RPCResult decodepsbt_outputs{ { {RPCResult::Type::OBJ, "redeem_script", /*optional=*/true, "", { - {RPCResult::Type::STR, "asm", "The asm"}, - {RPCResult::Type::STR_HEX, "hex", "The hex"}, + {RPCResult::Type::STR, "asm", "Disassembly of the redeem script"}, + {RPCResult::Type::STR_HEX, "hex", "The raw redeem script bytes, hex-encoded"}, {RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"}, }}, {RPCResult::Type::ARR, "bip32_derivs", /*optional=*/true, "", diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp index 0d7f63a82a644..e8211fe247d0a 100644 --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -1468,7 +1468,7 @@ class CTransactionSignatureSerializer template uint256 GetPrevoutsSHA256(const T& txTo) { - CHashWriter ss(SER_GETHASH, 0); + HashWriter ss{}; for (const auto& txin : txTo.vin) { ss << txin.prevout; } @@ -1479,7 +1479,7 @@ uint256 GetPrevoutsSHA256(const T& txTo) template uint256 GetSequencesSHA256(const T& txTo) { - CHashWriter ss(SER_GETHASH, 0); + HashWriter ss{}; for (const auto& txin : txTo.vin) { ss << txin.nSequence; } @@ -1490,7 +1490,7 @@ uint256 GetSequencesSHA256(const T& txTo) template uint256 GetOutputsSHA256(const T& txTo) { - CHashWriter ss(SER_GETHASH, 0); + HashWriter ss{}; for (const auto& txout : txTo.vout) { ss << txout; } @@ -1550,7 +1550,7 @@ uint256 SignatureHash(const CScript& scriptCode, const T& txTo, unsigned int nIn CTransactionSignatureSerializer txTmp(txTo, scriptCode, nIn, nHashType); // Serialize and hash - CHashWriter ss(SER_GETHASH, 0); + HashWriter ss{}; ss << txTmp << nHashType; return ss.GetHash(); } diff --git a/src/streams.h b/src/streams.h index 22972ffb25e8d..9790914f47cde 100644 --- a/src/streams.h +++ b/src/streams.h @@ -484,35 +484,28 @@ class BitStreamWriter }; - /** Non-refcounted RAII wrapper for FILE* * * Will automatically close the file when it goes out of scope if not null. * If you're returning the file pointer, return file.release(). * If you need to close the file early, use file.fclose() instead of fclose(file). */ -class CAutoFile +class AutoFile { -private: - const int nType; - const int nVersion; - +protected: FILE* file; public: - CAutoFile(FILE* filenew, int nTypeIn, int nVersionIn) : nType(nTypeIn), nVersion(nVersionIn) - { - file = filenew; - } + explicit AutoFile(FILE* filenew) : file{filenew} {} - ~CAutoFile() + ~AutoFile() { fclose(); } // Disallow copies - CAutoFile(const CAutoFile&) = delete; - CAutoFile& operator=(const CAutoFile&) = delete; + AutoFile(const AutoFile&) = delete; + AutoFile& operator=(const AutoFile&) = delete; void fclose() { @@ -523,14 +516,14 @@ class CAutoFile } /** Get wrapped FILE* with transfer of ownership. - * @note This will invalidate the CAutoFile object, and makes it the responsibility of the caller + * @note This will invalidate the AutoFile object, and makes it the responsibility of the caller * of this function to clean up the returned FILE*. */ FILE* release() { FILE* ret = file; file = nullptr; return ret; } /** Get wrapped FILE* without transfer of ownership. * @note Ownership of the FILE* will remain with this class. Use this only if the scope of the - * CAutoFile outlives use of the passed pointer. + * AutoFile outlives use of the passed pointer. */ FILE* Get() const { return file; } @@ -541,40 +534,62 @@ class CAutoFile // // Stream subset // - int GetType() const { return nType; } - int GetVersion() const { return nVersion; } - void read(Span dst) { - if (!file) - throw std::ios_base::failure("CAutoFile::read: file handle is nullptr"); + if (!file) throw std::ios_base::failure("AutoFile::read: file handle is nullptr"); if (fread(dst.data(), 1, dst.size(), file) != dst.size()) { - throw std::ios_base::failure(feof(file) ? "CAutoFile::read: end of file" : "CAutoFile::read: fread failed"); + throw std::ios_base::failure(feof(file) ? "AutoFile::read: end of file" : "AutoFile::read: fread failed"); } } void ignore(size_t nSize) { - if (!file) - throw std::ios_base::failure("CAutoFile::ignore: file handle is nullptr"); + if (!file) throw std::ios_base::failure("AutoFile::ignore: file handle is nullptr"); unsigned char data[4096]; while (nSize > 0) { size_t nNow = std::min(nSize, sizeof(data)); if (fread(data, 1, nNow, file) != nNow) - throw std::ios_base::failure(feof(file) ? "CAutoFile::ignore: end of file" : "CAutoFile::read: fread failed"); + throw std::ios_base::failure(feof(file) ? "AutoFile::ignore: end of file" : "AutoFile::read: fread failed"); nSize -= nNow; } } void write(Span src) { - if (!file) - throw std::ios_base::failure("CAutoFile::write: file handle is nullptr"); + if (!file) throw std::ios_base::failure("AutoFile::write: file handle is nullptr"); if (fwrite(src.data(), 1, src.size(), file) != src.size()) { - throw std::ios_base::failure("CAutoFile::write: write failed"); + throw std::ios_base::failure("AutoFile::write: write failed"); } } + template + AutoFile& operator<<(const T& obj) + { + if (!file) throw std::ios_base::failure("AutoFile::operator<<: file handle is nullptr"); + ::Serialize(*this, obj); + return *this; + } + + template + AutoFile& operator>>(T&& obj) + { + if (!file) throw std::ios_base::failure("AutoFile::operator>>: file handle is nullptr"); + ::Unserialize(*this, obj); + return *this; + } +}; + +class CAutoFile : public AutoFile +{ +private: + const int nType; + const int nVersion; + +public: + CAutoFile(FILE* filenew, int nTypeIn, int nVersionIn) : AutoFile{filenew}, nType(nTypeIn), nVersion(nVersionIn) {} + int GetType() const { return nType; } + int GetVersion() const { return nVersion; } + template CAutoFile& operator<<(const T& obj) { diff --git a/src/test/flatfile_tests.cpp b/src/test/flatfile_tests.cpp index bdc64a93d4f94..9d8e9286f341c 100644 --- a/src/test/flatfile_tests.cpp +++ b/src/test/flatfile_tests.cpp @@ -44,26 +44,26 @@ BOOST_AUTO_TEST_CASE(flatfile_open) // Write first line to file. { - CAutoFile file(seq.Open(FlatFilePos(0, pos1)), SER_DISK, CLIENT_VERSION); + AutoFile file{seq.Open(FlatFilePos(0, pos1))}; file << LIMITED_STRING(line1, 256); } // Attempt to append to file opened in read-only mode. { - CAutoFile file(seq.Open(FlatFilePos(0, pos2), true), SER_DISK, CLIENT_VERSION); + AutoFile file{seq.Open(FlatFilePos(0, pos2), true)}; BOOST_CHECK_THROW(file << LIMITED_STRING(line2, 256), std::ios_base::failure); } // Append second line to file. { - CAutoFile file(seq.Open(FlatFilePos(0, pos2)), SER_DISK, CLIENT_VERSION); + AutoFile file{seq.Open(FlatFilePos(0, pos2))}; file << LIMITED_STRING(line2, 256); } // Read text from file in read-only mode. { std::string text; - CAutoFile file(seq.Open(FlatFilePos(0, pos1), true), SER_DISK, CLIENT_VERSION); + AutoFile file{seq.Open(FlatFilePos(0, pos1), true)}; file >> LIMITED_STRING(text, 256); BOOST_CHECK_EQUAL(text, line1); @@ -75,7 +75,7 @@ BOOST_AUTO_TEST_CASE(flatfile_open) // Read text from file with position offset. { std::string text; - CAutoFile file(seq.Open(FlatFilePos(0, pos2)), SER_DISK, CLIENT_VERSION); + AutoFile file{seq.Open(FlatFilePos(0, pos2))}; file >> LIMITED_STRING(text, 256); BOOST_CHECK_EQUAL(text, line2); @@ -84,7 +84,7 @@ BOOST_AUTO_TEST_CASE(flatfile_open) // Ensure another file in the sequence has no data. { std::string text; - CAutoFile file(seq.Open(FlatFilePos(1, pos2)), SER_DISK, CLIENT_VERSION); + AutoFile file{seq.Open(FlatFilePos(1, pos2))}; BOOST_CHECK_THROW(file >> LIMITED_STRING(text, 256), std::ios_base::failure); } } diff --git a/src/test/fuzz/autofile.cpp b/src/test/fuzz/autofile.cpp index 30ecb2ac75a1f..953be2b64874c 100644 --- a/src/test/fuzz/autofile.cpp +++ b/src/test/fuzz/autofile.cpp @@ -17,7 +17,7 @@ FUZZ_TARGET(autofile) { FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()}; FuzzedAutoFileProvider fuzzed_auto_file_provider = ConsumeAutoFile(fuzzed_data_provider); - CAutoFile auto_file = fuzzed_auto_file_provider.open(); + AutoFile auto_file{fuzzed_auto_file_provider.open()}; LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) { CallOneOf( fuzzed_data_provider, @@ -52,8 +52,6 @@ FUZZ_TARGET(autofile) }); } (void)auto_file.Get(); - (void)auto_file.GetType(); - (void)auto_file.GetVersion(); (void)auto_file.IsNull(); if (fuzzed_data_provider.ConsumeBool()) { FILE* f = auto_file.release(); diff --git a/src/test/fuzz/parse_univalue.cpp b/src/test/fuzz/parse_univalue.cpp index fb44233f1ba63..0d889c60a8cca 100644 --- a/src/test/fuzz/parse_univalue.cpp +++ b/src/test/fuzz/parse_univalue.cpp @@ -27,7 +27,7 @@ FUZZ_TARGET(parse_univalue, .init = initialize_parse_univalue) return ParseNonRFCJSONValue(random_string); } catch (const std::runtime_error&) { valid = false; - return NullUniValue; + return UniValue{}; } }(); if (!valid) { diff --git a/src/test/fuzz/policy_estimator.cpp b/src/test/fuzz/policy_estimator.cpp index d870aebcd7f6e..3d3d41db0349b 100644 --- a/src/test/fuzz/policy_estimator.cpp +++ b/src/test/fuzz/policy_estimator.cpp @@ -70,7 +70,7 @@ FUZZ_TARGET(policy_estimator, .init = initialize_policy_estimator) } { FuzzedAutoFileProvider fuzzed_auto_file_provider = ConsumeAutoFile(fuzzed_data_provider); - CAutoFile fuzzed_auto_file = fuzzed_auto_file_provider.open(); + AutoFile fuzzed_auto_file{fuzzed_auto_file_provider.open()}; block_policy_estimator.Write(fuzzed_auto_file); block_policy_estimator.Read(fuzzed_auto_file); } diff --git a/src/test/fuzz/policy_estimator_io.cpp b/src/test/fuzz/policy_estimator_io.cpp index 8de00981e1c63..9da23b5bba721 100644 --- a/src/test/fuzz/policy_estimator_io.cpp +++ b/src/test/fuzz/policy_estimator_io.cpp @@ -20,7 +20,7 @@ FUZZ_TARGET(policy_estimator_io, .init = initialize_policy_estimator_io) { FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); FuzzedAutoFileProvider fuzzed_auto_file_provider = ConsumeAutoFile(fuzzed_data_provider); - CAutoFile fuzzed_auto_file = fuzzed_auto_file_provider.open(); + AutoFile fuzzed_auto_file{fuzzed_auto_file_provider.open()}; // Re-using block_policy_estimator across runs to avoid costly creation of CBlockPolicyEstimator object. static CBlockPolicyEstimator block_policy_estimator; if (block_policy_estimator.Read(fuzzed_auto_file)) { diff --git a/src/test/fuzz/util.h b/src/test/fuzz/util.h index c3e5ff98519fd..0f505cc794394 100644 --- a/src/test/fuzz/util.h +++ b/src/test/fuzz/util.h @@ -389,17 +389,16 @@ class FuzzedFileProvider class FuzzedAutoFileProvider { - FuzzedDataProvider& m_fuzzed_data_provider; FuzzedFileProvider m_fuzzed_file_provider; public: - FuzzedAutoFileProvider(FuzzedDataProvider& fuzzed_data_provider) : m_fuzzed_data_provider{fuzzed_data_provider}, m_fuzzed_file_provider{fuzzed_data_provider} + FuzzedAutoFileProvider(FuzzedDataProvider& fuzzed_data_provider) : m_fuzzed_file_provider{fuzzed_data_provider} { } - CAutoFile open() + AutoFile open() { - return {m_fuzzed_file_provider.open(), m_fuzzed_data_provider.ConsumeIntegral(), m_fuzzed_data_provider.ConsumeIntegral()}; + return AutoFile{m_fuzzed_file_provider.open()}; } }; diff --git a/src/test/fuzz/utxo_snapshot.cpp b/src/test/fuzz/utxo_snapshot.cpp index a587cf919fb95..b1025023ca815 100644 --- a/src/test/fuzz/utxo_snapshot.cpp +++ b/src/test/fuzz/utxo_snapshot.cpp @@ -38,13 +38,13 @@ FUZZ_TARGET(utxo_snapshot, .init = initialize_chain) Assert(!chainman.SnapshotBlockhash()); { - CAutoFile outfile{fsbridge::fopen(snapshot_path, "wb"), SER_DISK, CLIENT_VERSION}; + AutoFile outfile{fsbridge::fopen(snapshot_path, "wb")}; const auto file_data{ConsumeRandomLengthByteVector(fuzzed_data_provider)}; outfile << Span{file_data}; } const auto ActivateFuzzedSnapshot{[&] { - CAutoFile infile{fsbridge::fopen(snapshot_path, "rb"), SER_DISK, CLIENT_VERSION}; + AutoFile infile{fsbridge::fopen(snapshot_path, "rb")}; SnapshotMetadata metadata; try { infile >> metadata; diff --git a/src/test/util/chainstate.h b/src/test/util/chainstate.h index b82368aa7051a..2f0021b114480 100644 --- a/src/test/util/chainstate.h +++ b/src/test/util/chainstate.h @@ -15,7 +15,7 @@ #include -const auto NoMalleation = [](CAutoFile& file, node::SnapshotMetadata& meta){}; +const auto NoMalleation = [](AutoFile& file, node::SnapshotMetadata& meta){}; /** * Create and activate a UTXO snapshot, optionally providing a function to @@ -31,7 +31,7 @@ CreateAndActivateUTXOSnapshot(node::NodeContext& node, const fs::path root, F ma WITH_LOCK(::cs_main, height = node.chainman->ActiveHeight()); fs::path snapshot_path = root / fs::u8path(tfm::format("test_snapshot.%d.dat", height)); FILE* outfile{fsbridge::fopen(snapshot_path, "wb")}; - CAutoFile auto_outfile{outfile, SER_DISK, CLIENT_VERSION}; + AutoFile auto_outfile{outfile}; UniValue result = CreateUTXOSnapshot( node, node.chainman->ActiveChainstate(), auto_outfile, snapshot_path, snapshot_path); @@ -41,7 +41,7 @@ CreateAndActivateUTXOSnapshot(node::NodeContext& node, const fs::path root, F ma // Read the written snapshot in and then activate it. // FILE* infile{fsbridge::fopen(snapshot_path, "rb")}; - CAutoFile auto_infile{infile, SER_DISK, CLIENT_VERSION}; + AutoFile auto_infile{infile}; node::SnapshotMetadata metadata; auto_infile >> metadata; diff --git a/src/test/validation_chainstatemanager_tests.cpp b/src/test/validation_chainstatemanager_tests.cpp index 2de98a6fc65b1..0900bf53a5587 100644 --- a/src/test/validation_chainstatemanager_tests.cpp +++ b/src/test/validation_chainstatemanager_tests.cpp @@ -218,7 +218,7 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_activate_snapshot, TestChain100Setup) // Should not load malleated snapshots BOOST_REQUIRE(!CreateAndActivateUTXOSnapshot( - m_node, m_path_root, [](CAutoFile& auto_infile, SnapshotMetadata& metadata) { + m_node, m_path_root, [](AutoFile& auto_infile, SnapshotMetadata& metadata) { // A UTXO is missing but count is correct metadata.m_coins_count -= 1; @@ -229,22 +229,22 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_activate_snapshot, TestChain100Setup) auto_infile >> coin; })); BOOST_REQUIRE(!CreateAndActivateUTXOSnapshot( - m_node, m_path_root, [](CAutoFile& auto_infile, SnapshotMetadata& metadata) { + m_node, m_path_root, [](AutoFile& auto_infile, SnapshotMetadata& metadata) { // Coins count is larger than coins in file metadata.m_coins_count += 1; })); BOOST_REQUIRE(!CreateAndActivateUTXOSnapshot( - m_node, m_path_root, [](CAutoFile& auto_infile, SnapshotMetadata& metadata) { + m_node, m_path_root, [](AutoFile& auto_infile, SnapshotMetadata& metadata) { // Coins count is smaller than coins in file metadata.m_coins_count -= 1; })); BOOST_REQUIRE(!CreateAndActivateUTXOSnapshot( - m_node, m_path_root, [](CAutoFile& auto_infile, SnapshotMetadata& metadata) { + m_node, m_path_root, [](AutoFile& auto_infile, SnapshotMetadata& metadata) { // Wrong hash metadata.m_base_blockhash = uint256::ZERO; })); BOOST_REQUIRE(!CreateAndActivateUTXOSnapshot( - m_node, m_path_root, [](CAutoFile& auto_infile, SnapshotMetadata& metadata) { + m_node, m_path_root, [](AutoFile& auto_infile, SnapshotMetadata& metadata) { // Wrong hash metadata.m_base_blockhash = uint256::ONE; })); diff --git a/src/util/asmap.cpp b/src/util/asmap.cpp index 8a4f5c4d7bbdc..47f25c7aef4ac 100644 --- a/src/util/asmap.cpp +++ b/src/util/asmap.cpp @@ -198,7 +198,7 @@ std::vector DecodeAsmap(fs::path path) { std::vector bits; FILE *filestr = fsbridge::fopen(path, "rb"); - CAutoFile file(filestr, SER_DISK, CLIENT_VERSION); + AutoFile file{filestr}; if (file.IsNull()) { LogPrintf("Failed to open asmap file from disk\n"); return bits; diff --git a/src/util/message.cpp b/src/util/message.cpp index 81510735ed468..685093bb12da0 100644 --- a/src/util/message.cpp +++ b/src/util/message.cpp @@ -74,7 +74,7 @@ bool MessageSign( uint256 MessageHash(const std::string& message) { - CHashWriter hasher(SER_GETHASH, 0); + HashWriter hasher{}; hasher << MESSAGE_MAGIC << message; return hasher.GetHash(); diff --git a/src/validation.cpp b/src/validation.cpp index f0292f45ff6e0..a17c102a432cc 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -5424,7 +5424,7 @@ bool LoadMempool(CTxMemPool& pool, CChainState& active_chainstate, FopenFn mocka { int64_t nExpiryTimeout = gArgs.GetIntArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY) * 60 * 60; FILE* filestr{mockable_fopen_function(gArgs.GetDataDirNet() / "mempool.dat", "rb")}; - CAutoFile file(filestr, SER_DISK, CLIENT_VERSION); + AutoFile file{filestr}; if (file.IsNull()) { LogPrintf("Failed to open mempool file from disk. Continuing anyway.\n"); return false; @@ -5533,7 +5533,7 @@ bool DumpMempool(const CTxMemPool& pool, FopenFn mockable_fopen_function, bool s return false; } - CAutoFile file(filestr, SER_DISK, CLIENT_VERSION); + AutoFile file{filestr}; uint64_t version = MEMPOOL_DUMP_VERSION; file << version; @@ -5650,7 +5650,7 @@ const AssumeutxoData* ExpectedAssumeutxo( } bool ChainstateManager::ActivateSnapshot( - CAutoFile& coins_file, + AutoFile& coins_file, const SnapshotMetadata& metadata, bool in_memory) { @@ -5749,7 +5749,7 @@ static void FlushSnapshotToDisk(CCoinsViewCache& coins_cache, bool snapshot_load bool ChainstateManager::PopulateAndValidateSnapshot( CChainState& snapshot_chainstate, - CAutoFile& coins_file, + AutoFile& coins_file, const SnapshotMetadata& metadata) { // It's okay to release cs_main before we're done using `coins_cache` because we know diff --git a/src/validation.h b/src/validation.h index 31318029cf8e7..5fb683c9ca150 100644 --- a/src/validation.h +++ b/src/validation.h @@ -894,7 +894,7 @@ class ChainstateManager //! Internal helper for ActivateSnapshot(). [[nodiscard]] bool PopulateAndValidateSnapshot( CChainState& snapshot_chainstate, - CAutoFile& coins_file, + AutoFile& coins_file, const node::SnapshotMetadata& metadata); /** @@ -976,7 +976,7 @@ class ChainstateManager //! - Move the new chainstate to `m_snapshot_chainstate` and make it our //! ChainstateActive(). [[nodiscard]] bool ActivateSnapshot( - CAutoFile& coins_file, const node::SnapshotMetadata& metadata, bool in_memory); + AutoFile& coins_file, const node::SnapshotMetadata& metadata, bool in_memory); //! The most-work chain. CChainState& ActiveChainstate() const; diff --git a/src/wallet/dump.cpp b/src/wallet/dump.cpp index 87fc4242f9826..9e36a864b3ac4 100644 --- a/src/wallet/dump.cpp +++ b/src/wallet/dump.cpp @@ -41,7 +41,7 @@ bool DumpWallet(const ArgsManager& args, CWallet& wallet, bilingual_str& error) return false; } - CHashWriter hasher(0, 0); + HashWriter hasher{}; WalletDatabase& db = wallet.GetDatabase(); std::unique_ptr batch = db.MakeBatch(); @@ -132,7 +132,7 @@ bool CreateFromDump(const ArgsManager& args, const std::string& name, const fs:: std::ifstream dump_file{dump_path}; // Compute the checksum - CHashWriter hasher(0, 0); + HashWriter hasher{}; uint256 checksum; // Check the magic and version diff --git a/src/wallet/rpc/addresses.cpp b/src/wallet/rpc/addresses.cpp index 5752c5dd30fc7..6058e621aa6f6 100644 --- a/src/wallet/rpc/addresses.cpp +++ b/src/wallet/rpc/addresses.cpp @@ -33,7 +33,7 @@ RPCHelpMan getnewaddress() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; LOCK(pwallet->cs_wallet); @@ -71,7 +71,7 @@ RPCHelpMan getrawchangeaddress() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; LOCK(pwallet->cs_wallet); @@ -104,7 +104,7 @@ RPCHelpMan setlabel() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; LOCK(pwallet->cs_wallet); @@ -121,7 +121,7 @@ RPCHelpMan setlabel() pwallet->SetAddressBook(dest, label, "send"); } - return NullUniValue; + return UniValue::VNULL; }, }; } @@ -153,7 +153,7 @@ RPCHelpMan listaddressgroupings() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; // Make sure the results are valid at least up to the most recent block // the user could have gotten from another RPC command prior to now @@ -220,7 +220,7 @@ RPCHelpMan addmultisigaddress() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; LegacyScriptPubKeyMan& spk_man = EnsureLegacyScriptPubKeyMan(*pwallet); @@ -276,7 +276,7 @@ RPCHelpMan keypoolrefill() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; if (pwallet->IsLegacy() && pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { throw JSONRPCError(RPC_WALLET_ERROR, "Error: Private keys are disabled for this wallet"); @@ -299,7 +299,7 @@ RPCHelpMan keypoolrefill() throw JSONRPCError(RPC_WALLET_ERROR, "Error refreshing keypool."); } - return NullUniValue; + return UniValue::VNULL; }, }; } @@ -324,14 +324,14 @@ RPCHelpMan newkeypool() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; LOCK(pwallet->cs_wallet); LegacyScriptPubKeyMan& spk_man = EnsureLegacyScriptPubKeyMan(*pwallet, true); spk_man.NewKeyPool(); - return NullUniValue; + return UniValue::VNULL; }, }; } @@ -471,7 +471,7 @@ RPCHelpMan getaddressinfo() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; LOCK(pwallet->cs_wallet); @@ -581,7 +581,7 @@ RPCHelpMan getaddressesbylabel() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; LOCK(pwallet->cs_wallet); @@ -644,7 +644,7 @@ RPCHelpMan listlabels() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; LOCK(pwallet->cs_wallet); diff --git a/src/wallet/rpc/backup.cpp b/src/wallet/rpc/backup.cpp index 8d3d03bf76fa8..b53bd7892ba16 100644 --- a/src/wallet/rpc/backup.cpp +++ b/src/wallet/rpc/backup.cpp @@ -113,7 +113,7 @@ RPCHelpMan importprivkey() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { throw JSONRPCError(RPC_WALLET_ERROR, "Cannot import private keys to a wallet with private keys disabled"); @@ -171,7 +171,7 @@ RPCHelpMan importprivkey() if (fRescan) { RescanWallet(*pwallet, reserver); } - return NullUniValue; + return UniValue::VNULL; }, }; } @@ -193,7 +193,7 @@ RPCHelpMan abortrescan() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; if (!pwallet->IsScanning() || pwallet->IsAbortingRescan()) return false; pwallet->AbortRescan(); @@ -231,7 +231,7 @@ RPCHelpMan importaddress() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; EnsureLegacyScriptPubKeyMan(*pwallet, true); @@ -298,7 +298,7 @@ RPCHelpMan importaddress() } } - return NullUniValue; + return UniValue::VNULL; }, }; } @@ -316,7 +316,7 @@ RPCHelpMan importprunedfunds() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; CMutableTransaction tx; if (!DecodeHexTx(tx, request.params[0].get_str())) { @@ -351,7 +351,7 @@ RPCHelpMan importprunedfunds() CTransactionRef tx_ref = MakeTransactionRef(tx); if (pwallet->IsMine(*tx_ref)) { pwallet->AddToWallet(std::move(tx_ref), TxStateConfirmed{merkleBlock.header.GetHash(), height, static_cast(txnIndex)}); - return NullUniValue; + return UniValue::VNULL; } throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No addresses in wallet correspond to included transaction"); @@ -375,7 +375,7 @@ RPCHelpMan removeprunedfunds() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; LOCK(pwallet->cs_wallet); @@ -392,7 +392,7 @@ RPCHelpMan removeprunedfunds() throw JSONRPCError(RPC_INVALID_PARAMETER, "Transaction does not exist in wallet."); } - return NullUniValue; + return UniValue::VNULL; }, }; } @@ -422,7 +422,7 @@ RPCHelpMan importpubkey() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; EnsureLegacyScriptPubKeyMan(*pwallet, true); @@ -475,7 +475,7 @@ RPCHelpMan importpubkey() } } - return NullUniValue; + return UniValue::VNULL; }, }; } @@ -501,7 +501,7 @@ RPCHelpMan importwallet() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; EnsureLegacyScriptPubKeyMan(*pwallet, true); @@ -637,7 +637,7 @@ RPCHelpMan importwallet() if (!fGood) throw JSONRPCError(RPC_WALLET_ERROR, "Error adding some keys/scripts to wallet"); - return NullUniValue; + return UniValue::VNULL; }, }; } @@ -664,7 +664,7 @@ RPCHelpMan importelectrumwallet() { std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; if (pwallet->chain().havePruned()) throw JSONRPCError(RPC_WALLET_ERROR, "Importing wallets is disabled in pruned mode"); @@ -817,7 +817,7 @@ RPCHelpMan importelectrumwallet() if (!fGood) throw JSONRPCError(RPC_WALLET_ERROR, "Error adding some keys to wallet"); - return NullUniValue; + return UniValue::VNULL; }, }; } @@ -842,7 +842,7 @@ RPCHelpMan dumpprivkey() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; const LegacyScriptPubKeyMan& spk_man = EnsureConstLegacyScriptPubKeyMan(*pwallet); @@ -889,7 +889,7 @@ RPCHelpMan dumphdinfo() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; LOCK(pwallet->cs_wallet); @@ -943,7 +943,7 @@ RPCHelpMan dumpwallet() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; const CWallet& wallet = *pwallet; const LegacyScriptPubKeyMan& spk_man = EnsureConstLegacyScriptPubKeyMan(wallet); @@ -1551,7 +1551,7 @@ RPCHelpMan importmulti() const UniValue& requests = mainRequest.params[0]; std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(mainRequest); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; CWallet& wallet{*pwallet}; // Make sure the results are valid at least up to the most recent block @@ -1855,7 +1855,7 @@ RPCHelpMan importdescriptors() { { // Acquire the wallet std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(main_request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; CWallet& wallet{*pwallet}; // Make sure the results are valid at least up to the most recent block @@ -1994,7 +1994,7 @@ RPCHelpMan listdescriptors() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr wallet = GetWalletForJSONRPCRequest(request); - if (!wallet) return NullUniValue; + if (!wallet) return UniValue::VNULL; if (!wallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS)) { throw JSONRPCError(RPC_WALLET_ERROR, "listdescriptors is not available for non-descriptor wallets"); @@ -2080,7 +2080,7 @@ RPCHelpMan backupwallet() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; // Make sure the results are valid at least up to the most recent block // the user could have gotten from another RPC command prior to now @@ -2093,7 +2093,7 @@ RPCHelpMan backupwallet() throw JSONRPCError(RPC_WALLET_ERROR, "Error: Wallet backup failed!"); } - return NullUniValue; + return UniValue::VNULL; }, }; } diff --git a/src/wallet/rpc/coins.cpp b/src/wallet/rpc/coins.cpp index 84accf15ce1ba..c31b3eba313c9 100644 --- a/src/wallet/rpc/coins.cpp +++ b/src/wallet/rpc/coins.cpp @@ -104,7 +104,7 @@ RPCHelpMan getreceivedbyaddress() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; // Make sure the results are valid at least up to the most recent block // the user could have gotten from another RPC command prior to now @@ -145,7 +145,7 @@ RPCHelpMan getreceivedbylabel() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; // Make sure the results are valid at least up to the most recent block // the user could have gotten from another RPC command prior to now @@ -185,7 +185,7 @@ RPCHelpMan getbalance() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; // Make sure the results are valid at least up to the most recent block // the user could have gotten from another RPC command prior to now @@ -229,7 +229,7 @@ RPCHelpMan getunconfirmedbalance() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; // Make sure the results are valid at least up to the most recent block // the user could have gotten from another RPC command prior to now @@ -288,7 +288,7 @@ RPCHelpMan lockunspent() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; // Make sure the results are valid at least up to the most recent block // the user could have gotten from another RPC command prior to now @@ -413,7 +413,7 @@ RPCHelpMan listlockunspent() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; LOCK(pwallet->cs_wallet); @@ -461,7 +461,7 @@ RPCHelpMan getbalances() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr rpc_wallet = GetWalletForJSONRPCRequest(request); - if (!rpc_wallet) return NullUniValue; + if (!rpc_wallet) return UniValue::VNULL; const CWallet& wallet = *rpc_wallet; // Make sure the results are valid at least up to the most recent block @@ -563,7 +563,7 @@ RPCHelpMan listunspent() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; int nMinDepth = 1; if (!request.params[0].isNull()) { diff --git a/src/wallet/rpc/encrypt.cpp b/src/wallet/rpc/encrypt.cpp index 4bf0a881c7441..5dffbb848a17f 100644 --- a/src/wallet/rpc/encrypt.cpp +++ b/src/wallet/rpc/encrypt.cpp @@ -34,7 +34,7 @@ RPCHelpMan walletpassphrase() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); - if (!wallet) return NullUniValue; + if (!wallet) return UniValue::VNULL; CWallet* const pwallet = wallet.get(); int64_t nSleepTime; @@ -118,7 +118,7 @@ RPCHelpMan walletpassphrase() } }, nSleepTime); - return NullUniValue; + return UniValue::VNULL; }, }; } @@ -139,7 +139,7 @@ RPCHelpMan walletpassphrasechange() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; LOCK(pwallet->cs_wallet); @@ -171,7 +171,7 @@ RPCHelpMan walletpassphrasechange() } } - return NullUniValue; + return UniValue::VNULL; }, }; } @@ -197,7 +197,7 @@ RPCHelpMan walletlock() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; LOCK(pwallet->cs_wallet); @@ -208,7 +208,7 @@ RPCHelpMan walletlock() pwallet->Lock(); pwallet->nRelockTime = 0; - return NullUniValue; + return UniValue::VNULL; }, }; } @@ -240,7 +240,7 @@ RPCHelpMan encryptwallet() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; LOCK(pwallet->cs_wallet); diff --git a/src/wallet/rpc/signmessage.cpp b/src/wallet/rpc/signmessage.cpp index 2bd851f5e9fe7..fb670fbe24e8c 100644 --- a/src/wallet/rpc/signmessage.cpp +++ b/src/wallet/rpc/signmessage.cpp @@ -36,7 +36,7 @@ RPCHelpMan signmessage() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; LOCK(pwallet->cs_wallet); diff --git a/src/wallet/rpc/spend.cpp b/src/wallet/rpc/spend.cpp index f874f6dbac0d8..309da88bff3a1 100644 --- a/src/wallet/rpc/spend.cpp +++ b/src/wallet/rpc/spend.cpp @@ -168,7 +168,7 @@ RPCHelpMan sendtoaddress() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; // Make sure the results are valid at least up to the most recent block // the user could have gotten from another RPC command prior to now @@ -275,7 +275,7 @@ RPCHelpMan sendmany() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; // Make sure the results are valid at least up to the most recent block // the user could have gotten from another RPC command prior to now @@ -332,7 +332,7 @@ RPCHelpMan settxfee() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; LOCK(pwallet->cs_wallet); @@ -613,7 +613,7 @@ RPCHelpMan fundrawtransaction() RPCTypeCheck(request.params, {UniValue::VSTR, UniValueType(), UniValue::VBOOL}); std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; // parse hex string from parameter CMutableTransaction tx; @@ -695,7 +695,7 @@ RPCHelpMan signrawtransactionwithwallet() RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VARR, UniValue::VSTR}, true); const std::shared_ptr pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; CMutableTransaction mtx; if (!DecodeHexTx(mtx, request.params[0].get_str())) { @@ -845,7 +845,7 @@ RPCHelpMan send() ); std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; UniValue options{request.params[4].isNull() ? UniValue::VOBJ : request.params[4]}; if (options.exists("estimate_mode") || options.exists("conf_target")) { @@ -975,7 +975,7 @@ RPCHelpMan walletprocesspsbt() RPCTypeCheck(request.params, {UniValue::VSTR}); const std::shared_ptr pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; const CWallet& wallet{*pwallet}; // Make sure the results are valid at least up to the most recent block @@ -1128,7 +1128,7 @@ RPCHelpMan walletcreatefundedpsbt() ); std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; CWallet& wallet{*pwallet}; // Make sure the results are valid at least up to the most recent block diff --git a/src/wallet/rpc/transactions.cpp b/src/wallet/rpc/transactions.cpp index 3870162016db5..879f17c440dc0 100644 --- a/src/wallet/rpc/transactions.cpp +++ b/src/wallet/rpc/transactions.cpp @@ -251,7 +251,7 @@ RPCHelpMan listreceivedbyaddress() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; // Make sure the results are valid at least up to the most recent block // the user could have gotten from another RPC command prior to now @@ -298,7 +298,7 @@ RPCHelpMan listreceivedbylabel() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; // Make sure the results are valid at least up to the most recent block // the user could have gotten from another RPC command prior to now @@ -491,7 +491,7 @@ RPCHelpMan listtransactions() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; // Make sure the results are valid at least up to the most recent block // the user could have gotten from another RPC command prior to now @@ -607,7 +607,7 @@ RPCHelpMan listsinceblock() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; const CWallet& wallet = *pwallet; // Make sure the results are valid at least up to the most recent block @@ -746,7 +746,7 @@ RPCHelpMan gettransaction() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; // Make sure the results are valid at least up to the most recent block // the user could have gotten from another RPC command prior to now @@ -819,7 +819,7 @@ RPCHelpMan abandontransaction() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; // Make sure the results are valid at least up to the most recent block // the user could have gotten from another RPC command prior to now @@ -836,7 +836,7 @@ RPCHelpMan abandontransaction() throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not eligible for abandonment"); } - return NullUniValue; + return UniValue::VNULL; }, }; } @@ -864,7 +864,7 @@ RPCHelpMan rescanblockchain() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; CWallet& wallet{*pwallet}; // Make sure the results are valid at least up to the most recent block diff --git a/src/wallet/rpc/wallet.cpp b/src/wallet/rpc/wallet.cpp index b55a93fe51858..d8f124480e1ad 100644 --- a/src/wallet/rpc/wallet.cpp +++ b/src/wallet/rpc/wallet.cpp @@ -64,7 +64,7 @@ static RPCHelpMan listaddressbalances() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; LOCK(pwallet->cs_wallet); @@ -104,7 +104,7 @@ static RPCHelpMan setcoinjoinrounds() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr wallet = GetWalletForJSONRPCRequest(request); - if (!wallet) return NullUniValue; + if (!wallet) return UniValue::VNULL; int nRounds = request.params[0].getInt(); @@ -113,7 +113,7 @@ static RPCHelpMan setcoinjoinrounds() CCoinJoinClientOptions::SetRounds(nRounds); - return NullUniValue; + return UniValue::VNULL; }, }; } @@ -135,7 +135,7 @@ static RPCHelpMan setcoinjoinamount() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr wallet = GetWalletForJSONRPCRequest(request); - if (!wallet) return NullUniValue; + if (!wallet) return UniValue::VNULL; int nAmount = request.params[0].getInt(); @@ -144,7 +144,7 @@ static RPCHelpMan setcoinjoinamount() CCoinJoinClientOptions::SetAmount(nAmount); - return NullUniValue; + return UniValue::VNULL; }, }; } @@ -200,7 +200,7 @@ static RPCHelpMan getwalletinfo() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { const std::shared_ptr pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; // Make sure the results are valid at least up to the most recent block // the user could have gotten from another RPC command prior to now @@ -365,7 +365,7 @@ static RPCHelpMan upgradetohd() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; bool generate_mnemonic = request.params[0].isNull() || request.params[0].get_str().empty(); bool mnemonic_passphrase_has_null{false}; @@ -570,7 +570,7 @@ static RPCHelpMan setwalletflag() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; std::string flag_str = request.params[0].get_str(); @@ -776,7 +776,7 @@ static RPCHelpMan wipewallettxes() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); - if (!wallet) return NullUniValue; + if (!wallet) return UniValue::VNULL; CWallet* const pwallet = wallet.get(); WalletRescanReserver reserver(*pwallet); @@ -825,7 +825,7 @@ static RPCHelpMan wipewallettxes() pwallet->ShowProgress(strprintf("%s " + _("Wiping wallet transactions…").translated, pwallet->GetDisplayName()), 100); - return NullUniValue; + return UniValue::VNULL; }, }; } @@ -854,7 +854,7 @@ static RPCHelpMan sethdseed() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; LegacyScriptPubKeyMan& spk_man = EnsureLegacyScriptPubKeyMan(*pwallet, true); @@ -902,7 +902,7 @@ static RPCHelpMan sethdseed() if (flush_key_pool) spk_man.NewKeyPool(); - return NullUniValue; + return UniValue::VNULL; }, }; } @@ -933,7 +933,7 @@ static RPCHelpMan upgradewallet() [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { std::shared_ptr const pwallet = GetWalletForJSONRPCRequest(request); - if (!pwallet) return NullUniValue; + if (!pwallet) return UniValue::VNULL; RPCTypeCheck(request.params, {UniValue::VNUM}, true); diff --git a/test/functional/feature_addrman.py b/test/functional/feature_addrman.py index 490b554a3225e..3f3d3ca2fb37b 100755 --- a/test/functional/feature_addrman.py +++ b/test/functional/feature_addrman.py @@ -94,7 +94,7 @@ def run_test(self): with open(peers_dat, "wb") as f: f.write(serialize_addrman()[:-1]) self.nodes[0].assert_start_raises_init_error( - expected_msg=init_error("CAutoFile::read: end of file.*"), + expected_msg=init_error("AutoFile::read: end of file.*"), match=ErrorMatch.FULL_REGEX, ) diff --git a/test/functional/feature_dbcrash.py b/test/functional/feature_dbcrash.py index dd8230f3a1f1d..1607c9a452958 100755 --- a/test/functional/feature_dbcrash.py +++ b/test/functional/feature_dbcrash.py @@ -196,9 +196,8 @@ def generate_small_transactions(self, node, count, utxo_list): from_node=node, utxos_to_spend=utxos_to_spend, num_outputs=3, - fee_per_output=FEE // 3 + fee_per_output=FEE // 3, ) - num_transactions += 1 def run_test(self): diff --git a/test/functional/feature_fee_estimation.py b/test/functional/feature_fee_estimation.py index c9fc12470fb7d..d8f3c535e32b1 100755 --- a/test/functional/feature_fee_estimation.py +++ b/test/functional/feature_fee_estimation.py @@ -51,7 +51,8 @@ def small_txpuzzle_randfee( raise RuntimeError(f"Insufficient funds: need {amount + fee}, have {total_in}") tx = wallet.create_self_transfer_multi( utxos_to_spend=utxos_to_spend, - fee_per_output=0)["tx"] + fee_per_output=0, + )["tx"] tx.vout[0].nValue = int((total_in - amount - fee) * COIN) tx.vout.append(deepcopy(tx.vout[0])) tx.vout[1].nValue = int(amount * COIN) diff --git a/test/functional/rpc_blockchain.py b/test/functional/rpc_blockchain.py index 6ffaaa75f0f90..819c004a3e4a1 100755 --- a/test/functional/rpc_blockchain.py +++ b/test/functional/rpc_blockchain.py @@ -35,6 +35,7 @@ from test_framework.governance import EXPECTED_STDERR_NO_GOV_PRUNE from test_framework.messages import ( CBlockHeader, + dashhash, from_hex, msg_block, ) @@ -491,6 +492,10 @@ def _test_getblock(self): self.wallet.send_self_transfer(fee_rate=fee_per_kb, from_node=node) blockhash = self.generate(node, 1)[0] + def assert_hexblock_hashes(verbosity): + block = node.getblock(blockhash, verbosity) + assert_equal(blockhash, dashhash(bytes.fromhex(block[:160]))[::-1].hex()) + def assert_fee_not_in_block(verbosity): block = node.getblock(blockhash, verbosity) assert 'fee' not in block['tx'][1] @@ -525,8 +530,13 @@ def assert_vin_does_not_contain_prevout(verbosity): for vin in tx["vin"]: assert "prevout" not in vin + self.log.info("Test that getblock with verbosity 0 hashes to expected value") + assert_hexblock_hashes(0) + assert_hexblock_hashes(False) + self.log.info("Test that getblock with verbosity 1 doesn't include fee") assert_fee_not_in_block(1) + assert_fee_not_in_block(True) self.log.info('Test that getblock with verbosity 2 and 3 includes expected fee') assert_fee_in_block(2) diff --git a/test/functional/rpc_mempool_info.py b/test/functional/rpc_mempool_info.py index cd7a48d387ea9..9b5a3b91123fd 100755 --- a/test/functional/rpc_mempool_info.py +++ b/test/functional/rpc_mempool_info.py @@ -4,7 +4,6 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test RPCs that retrieve information from the mempool.""" -from test_framework.blocktools import COINBASE_MATURITY from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, @@ -19,7 +18,6 @@ def set_test_params(self): def run_test(self): self.wallet = MiniWallet(self.nodes[0]) - self.generate(self.wallet, COINBASE_MATURITY + 1) self.wallet.rescan_utxos() confirmed_utxo = self.wallet.get_utxo()