Skip to content

Commit fa7fc5a

Browse files
author
MarcoFalke
committed
rpc: factor out RpcInterruptionPoint from dumptxoutset
1 parent b5c423c commit fa7fc5a

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/rpc/blockchain.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2329,9 +2329,7 @@ UniValue dumptxoutset(const JSONRPCRequest& request)
23292329
unsigned int iter{0};
23302330

23312331
while (pcursor->Valid()) {
2332-
if (iter % 5000 == 0 && !IsRPCRunning()) {
2333-
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Shutting down");
2334-
}
2332+
if (iter % 5000 == 0) RpcInterruptionPoint();
23352333
++iter;
23362334
if (pcursor->GetKey(key) && pcursor->GetValue(coin)) {
23372335
afile << key;

src/rpc/server.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
#include <util/strencodings.h>
1212
#include <util/system.h>
1313

14-
#include <boost/signals2/signal.hpp>
1514
#include <boost/algorithm/string/classification.hpp>
1615
#include <boost/algorithm/string/split.hpp>
16+
#include <boost/signals2/signal.hpp>
1717

1818
#include <memory> // for unique_ptr
1919
#include <unordered_map>
@@ -309,6 +309,11 @@ bool IsRPCRunning()
309309
return g_rpc_running;
310310
}
311311

312+
void RpcInterruptionPoint()
313+
{
314+
if (!IsRPCRunning()) throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Shutting down");
315+
}
316+
312317
void SetRPCWarmupStatus(const std::string& newStatus)
313318
{
314319
LOCK(cs_rpcWarmup);

src/rpc/server.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
#include <amount.h>
1010
#include <rpc/request.h>
1111

12+
#include <functional>
1213
#include <map>
1314
#include <stdint.h>
1415
#include <string>
15-
#include <functional>
1616

1717
#include <univalue.h>
1818

@@ -29,6 +29,9 @@ namespace RPCServer
2929
/** Query whether RPC is running */
3030
bool IsRPCRunning();
3131

32+
/** Throw JSONRPCError if RPC is not running */
33+
void RpcInterruptionPoint();
34+
3235
/**
3336
* Set the RPC warmup status. When this is done, all RPC calls will error out
3437
* immediately with RPC_IN_WARMUP.

0 commit comments

Comments
 (0)