@@ -2411,10 +2411,21 @@ static RPCHelpMan dumptxoutset()
2411
2411
2412
2412
FILE* file{fsbridge::fopen (temppath, " wb" )};
2413
2413
CAutoFile afile{file, SER_DISK, CLIENT_VERSION};
2414
+ NodeContext& node = EnsureNodeContext (request.context );
2415
+ UniValue result = CreateUTXOSnapshot (node, node.chainman ->ActiveChainstate (), afile);
2416
+ fs::rename (temppath, path);
2417
+
2418
+ result.pushKV (" path" , path.string ());
2419
+ return result;
2420
+ },
2421
+ };
2422
+ }
2423
+
2424
+ UniValue CreateUTXOSnapshot (NodeContext& node, CChainState& chainstate, CAutoFile& afile)
2425
+ {
2414
2426
std::unique_ptr<CCoinsViewCursor> pcursor;
2415
2427
CCoinsStats stats;
2416
2428
CBlockIndex* tip;
2417
- NodeContext& node = EnsureNodeContext (request.context );
2418
2429
2419
2430
{
2420
2431
// We need to lock cs_main to ensure that the coinsdb isn't written to
@@ -2431,13 +2442,13 @@ static RPCHelpMan dumptxoutset()
2431
2442
//
2432
2443
LOCK (::cs_main);
2433
2444
2434
- ::ChainstateActive () .ForceFlushStateToDisk();
2445
+ chainstate .ForceFlushStateToDisk ();
2435
2446
2436
- if (!GetUTXOStats (&:: ChainstateActive () .CoinsDB (), stats, CoinStatsHashType::NONE, node.rpc_interruption_point )) {
2447
+ if (!GetUTXOStats (&chainstate .CoinsDB (), stats, CoinStatsHashType::NONE, node.rpc_interruption_point )) {
2437
2448
throw JSONRPCError (RPC_INTERNAL_ERROR, " Unable to read UTXO set" );
2438
2449
}
2439
2450
2440
- pcursor = std::unique_ptr<CCoinsViewCursor>(:: ChainstateActive () .CoinsDB ().Cursor ());
2451
+ pcursor = std::unique_ptr<CCoinsViewCursor>(chainstate .CoinsDB ().Cursor ());
2441
2452
tip = g_chainman.m_blockman .LookupBlockIndex (stats.hashBlock );
2442
2453
CHECK_NONFATAL (tip);
2443
2454
}
@@ -2462,16 +2473,13 @@ static RPCHelpMan dumptxoutset()
2462
2473
}
2463
2474
2464
2475
afile.fclose ();
2465
- fs::rename (temppath, path);
2466
2476
2467
2477
UniValue result (UniValue::VOBJ);
2468
2478
result.pushKV (" coins_written" , stats.coins_count );
2469
2479
result.pushKV (" base_hash" , tip->GetBlockHash ().ToString ());
2470
2480
result.pushKV (" base_height" , tip->nHeight );
2471
- result. pushKV ( " path " , path. string ());
2481
+
2472
2482
return result;
2473
- },
2474
- };
2475
2483
}
2476
2484
2477
2485
void RegisterBlockchainRPCCommands (CRPCTable &t)
0 commit comments