Skip to content

Commit c2b779d

Browse files
committed
refactor: Manage dumptxoutset RAII classes with std::optional
Also removes unused UniValue error variable.
1 parent 4b5bf33 commit c2b779d

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/rpc/blockchain.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#include <condition_variable>
5757
#include <memory>
5858
#include <mutex>
59+
#include <optional>
5960

6061
using kernel::CCoinsStats;
6162
using kernel::CoinStatsHashType;
@@ -2786,8 +2787,8 @@ static RPCHelpMan dumptxoutset()
27862787

27872788
CConnman& connman = EnsureConnman(node);
27882789
const CBlockIndex* invalidate_index{nullptr};
2789-
std::unique_ptr<NetworkDisable> disable_network;
2790-
std::unique_ptr<TemporaryRollback> temporary_rollback;
2790+
std::optional<NetworkDisable> disable_network;
2791+
std::optional<TemporaryRollback> temporary_rollback;
27912792

27922793
// If the user wants to dump the txoutset of the current tip, we don't have
27932794
// to roll back at all
@@ -2812,18 +2813,16 @@ static RPCHelpMan dumptxoutset()
28122813
// automatically re-enables the network activity at the end of the
28132814
// process which may not be what the user wants.
28142815
if (connman.GetNetworkActive()) {
2815-
disable_network = std::make_unique<NetworkDisable>(connman);
2816+
disable_network.emplace(connman);
28162817
}
28172818

28182819
invalidate_index = WITH_LOCK(::cs_main, return node.chainman->ActiveChain().Next(target_index));
2819-
temporary_rollback = std::make_unique<TemporaryRollback>(*node.chainman, *invalidate_index);
2820+
temporary_rollback.emplace(*node.chainman, *invalidate_index);
28202821
}
28212822

28222823
Chainstate* chainstate;
28232824
std::unique_ptr<CCoinsViewCursor> cursor;
28242825
CCoinsStats stats;
2825-
UniValue result;
2826-
UniValue error;
28272826
{
28282827
// Lock the chainstate before calling PrepareUtxoSnapshot, to be able
28292828
// to get a UTXO database cursor while the chain is pointing at the
@@ -2847,7 +2846,7 @@ static RPCHelpMan dumptxoutset()
28472846
}
28482847
}
28492848

2850-
result = WriteUTXOSnapshot(*chainstate, cursor.get(), &stats, tip, afile, path, temppath, node.rpc_interruption_point);
2849+
UniValue result = WriteUTXOSnapshot(*chainstate, cursor.get(), &stats, tip, afile, path, temppath, node.rpc_interruption_point);
28512850
fs::rename(temppath, path);
28522851

28532852
result.pushKV("path", path.utf8string());

0 commit comments

Comments
 (0)