Skip to content

Commit 50e6472

Browse files
committed
Move ParseConfirmTarget from rpc/mining to rpc/util
Util is a better home since it's called both by wallet and mining code. Suggested bitcoin/bitcoin#15288 (comment)
1 parent 2945492 commit 50e6472

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

src/rpc/mining.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@
3131
#include <memory>
3232
#include <stdint.h>
3333

34-
unsigned int ParseConfirmTarget(const UniValue& value)
35-
{
36-
int target = value.get_int();
37-
unsigned int max_target = ::feeEstimator.HighestTargetTracked(FeeEstimateHorizon::LONG_HALFLIFE);
38-
if (target < 1 || (unsigned int)target > max_target) {
39-
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid conf_target, must be between %u - %u", 1, max_target));
40-
}
41-
return (unsigned int)target;
42-
}
43-
4434
/**
4535
* Return average network hashes per second based on the last 'lookup' blocks,
4636
* or from the last difficulty change if 'lookup' is nonpositive.

src/rpc/mining.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,4 @@
1212
/** Generate blocks (mine) */
1313
UniValue generateBlocks(std::shared_ptr<CReserveScript> coinbaseScript, int nGenerate, uint64_t nMaxTries, bool keepScript);
1414

15-
/** Check bounds on a command line confirm target */
16-
unsigned int ParseConfirmTarget(const UniValue& value);
17-
1815
#endif

src/rpc/util.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
#include <key_io.h>
66
#include <keystore.h>
7+
#include <policy/fees.h>
78
#include <rpc/protocol.h>
89
#include <rpc/util.h>
910
#include <tinyformat.h>
1011
#include <util/strencodings.h>
12+
#include <validation.h>
1113

1214
InitInterfaces* g_rpc_interfaces = nullptr;
1315

@@ -129,6 +131,16 @@ UniValue DescribeAddress(const CTxDestination& dest)
129131
return boost::apply_visitor(DescribeAddressVisitor(), dest);
130132
}
131133

134+
unsigned int ParseConfirmTarget(const UniValue& value)
135+
{
136+
int target = value.get_int();
137+
unsigned int max_target = ::feeEstimator.HighestTargetTracked(FeeEstimateHorizon::LONG_HALFLIFE);
138+
if (target < 1 || (unsigned int)target > max_target) {
139+
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid conf_target, must be between %u - %u", 1, max_target));
140+
}
141+
return (unsigned int)target;
142+
}
143+
132144
struct Section {
133145
Section(const std::string& left, const std::string& right)
134146
: m_left{left}, m_right{right} {}

src/rpc/util.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ CScript CreateMultisigRedeemscript(const int required, const std::vector<CPubKey
2828

2929
UniValue DescribeAddress(const CTxDestination& dest);
3030

31+
//! Parse a confirm target option and raise an RPC error if it is invalid.
32+
unsigned int ParseConfirmTarget(const UniValue& value);
33+
3134
struct RPCArg {
3235
enum class Type {
3336
OBJ,

0 commit comments

Comments
 (0)