From fa7fc5a8e0fcf9ca81e84b3631f18ae40502be60 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Fri, 22 May 2020 15:38:48 -0400 Subject: [PATCH] rpc: factor out RpcInterruptionPoint from dumptxoutset --- src/rpc/blockchain.cpp | 4 +--- src/rpc/server.cpp | 7 ++++++- src/rpc/server.h | 5 ++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index ac567e16ce6..80ae35f48ea 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -2329,9 +2329,7 @@ UniValue dumptxoutset(const JSONRPCRequest& request) unsigned int iter{0}; while (pcursor->Valid()) { - if (iter % 5000 == 0 && !IsRPCRunning()) { - throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Shutting down"); - } + if (iter % 5000 == 0) RpcInterruptionPoint(); ++iter; if (pcursor->GetKey(key) && pcursor->GetValue(coin)) { afile << key; diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 219979f0953..99c649d15a2 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -11,9 +11,9 @@ #include #include -#include #include #include +#include #include // for unique_ptr #include @@ -309,6 +309,11 @@ bool IsRPCRunning() return g_rpc_running; } +void RpcInterruptionPoint() +{ + if (!IsRPCRunning()) throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Shutting down"); +} + void SetRPCWarmupStatus(const std::string& newStatus) { LOCK(cs_rpcWarmup); diff --git a/src/rpc/server.h b/src/rpc/server.h index c91bf1f613b..d7a04ff6e8b 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -9,10 +9,10 @@ #include #include +#include #include #include #include -#include #include @@ -29,6 +29,9 @@ namespace RPCServer /** Query whether RPC is running */ bool IsRPCRunning(); +/** Throw JSONRPCError if RPC is not running */ +void RpcInterruptionPoint(); + /** * Set the RPC warmup status. When this is done, all RPC calls will error out * immediately with RPC_IN_WARMUP.