@@ -2716,10 +2716,19 @@ UniValue dumptxoutset(const JSONRPCRequest& request)
27162716
27172717 FILE* file{fsbridge::fopen (temppath, " wb" )};
27182718 CAutoFile afile{file, SER_DISK, CLIENT_VERSION};
2719+ NodeContext& node = EnsureNodeContext (request.context );
2720+ UniValue result = CreateUTXOSnapshot (node, node.chainman ->ActiveChainstate (), afile);
2721+ fs::rename (temppath, path);
2722+
2723+ result.pushKV (" path" , path.string ());
2724+ return result;
2725+ }
2726+
2727+ UniValue CreateUTXOSnapshot (NodeContext& node, CChainState& chainstate, CAutoFile& afile)
2728+ {
27192729 std::unique_ptr<CCoinsViewCursor> pcursor;
27202730 CCoinsStats stats;
27212731 CBlockIndex* tip;
2722- NodeContext& node = EnsureNodeContext (request.context );
27232732
27242733 {
27252734 // We need to lock cs_main to ensure that the coinsdb isn't written to
@@ -2736,13 +2745,13 @@ UniValue dumptxoutset(const JSONRPCRequest& request)
27362745 //
27372746 LOCK (::cs_main);
27382747
2739- ::ChainstateActive () .ForceFlushStateToDisk();
2748+ chainstate .ForceFlushStateToDisk ();
27402749
2741- if (!GetUTXOStats (&:: ChainstateActive () .CoinsDB (), stats, CoinStatsHashType::NONE, node.rpc_interruption_point )) {
2750+ if (!GetUTXOStats (&chainstate .CoinsDB (), stats, CoinStatsHashType::NONE, node.rpc_interruption_point )) {
27422751 throw JSONRPCError (RPC_INTERNAL_ERROR, " Unable to read UTXO set" );
27432752 }
27442753
2745- pcursor = std::unique_ptr<CCoinsViewCursor>(:: ChainstateActive () .CoinsDB ().Cursor ());
2754+ pcursor = std::unique_ptr<CCoinsViewCursor>(chainstate .CoinsDB ().Cursor ());
27462755 tip = g_chainman.m_blockman .LookupBlockIndex (stats.hashBlock );
27472756 CHECK_NONFATAL (tip);
27482757 }
@@ -2767,13 +2776,12 @@ UniValue dumptxoutset(const JSONRPCRequest& request)
27672776 }
27682777
27692778 afile.fclose ();
2770- fs::rename (temppath, path);
27712779
27722780 UniValue result (UniValue::VOBJ);
27732781 result.pushKV (" coins_written" , stats.coins_count );
27742782 result.pushKV (" base_hash" , tip->GetBlockHash ().ToString ());
27752783 result.pushKV (" base_height" , tip->nHeight );
2776- result. pushKV ( " path " , path. string ());
2784+
27772785 return result;
27782786}
27792787
0 commit comments