Skip to content

Commit

Permalink
Merge bitcoin#15373: Move ParseConfirmTarget from rpc/mining to rpc/util
Browse files Browse the repository at this point in the history
50e6472 Move ParseConfirmTarget from rpc/mining to rpc/util (Russell Yanofsky)

Pull request description:

  Util is a better home since it's called both by wallet and mining code.

  Suggested bitcoin#15288 (comment)

Tree-SHA512: 4320caf2a3f70d2885c421de04f2ec68ff3f6519258c5155fc46e245dc1765fd15c81f260af5096318f24ff9deb88fc3c5ef40eec8b7393f467f5b963d17215b
  • Loading branch information
MarcoFalke authored and Munkybooty committed Sep 13, 2021
1 parent ae4bea6 commit 7e05caa
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
10 changes: 0 additions & 10 deletions src/rpc/mining.cpp
Expand Up @@ -40,16 +40,6 @@
#include <memory>
#include <stdint.h>

unsigned int ParseConfirmTarget(const UniValue& value)
{
int target = value.get_int();
unsigned int max_target = ::feeEstimator.HighestTargetTracked(FeeEstimateHorizon::LONG_HALFLIFE);
if (target < 1 || (unsigned int)target > max_target) {
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid conf_target, must be between %u - %u", 1, max_target));
}
return (unsigned int)target;
}

/**
* Return average network hashes per second based on the last 'lookup' blocks,
* or from the last difficulty change if 'lookup' is nonpositive.
Expand Down
3 changes: 0 additions & 3 deletions src/rpc/mining.h
Expand Up @@ -12,7 +12,4 @@
/** Generate blocks (mine) */
UniValue generateBlocks(std::shared_ptr<CReserveScript> coinbaseScript, int nGenerate, uint64_t nMaxTries, bool keepScript);

/** Check bounds on a command line confirm target */
unsigned int ParseConfirmTarget(const UniValue& value);

#endif
12 changes: 12 additions & 0 deletions src/rpc/util.cpp
Expand Up @@ -4,10 +4,12 @@

#include <key_io.h>
#include <keystore.h>
#include <policy/fees.h>
#include <pubkey.h>
#include <rpc/util.h>
#include <tinyformat.h>
#include <util/strencodings.h>
#include <validation.h>

// Converts a hex string to a public key if possible
CPubKey HexToPubKey(const std::string& hex_in)
Expand Down Expand Up @@ -92,6 +94,16 @@ UniValue DescribeAddress(const CTxDestination& dest)
return boost::apply_visitor(DescribeAddressVisitor(), dest);
}

unsigned int ParseConfirmTarget(const UniValue& value)
{
int target = value.get_int();
unsigned int max_target = ::feeEstimator.HighestTargetTracked(FeeEstimateHorizon::LONG_HALFLIFE);
if (target < 1 || (unsigned int)target > max_target) {
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid conf_target, must be between %u - %u", 1, max_target));
}
return (unsigned int)target;
}

std::string RPCHelpMan::ToString() const
{
std::string ret;
Expand Down
3 changes: 3 additions & 0 deletions src/rpc/util.h
Expand Up @@ -25,6 +25,9 @@ CScript CreateMultisigRedeemscript(const int required, const std::vector<CPubKey

UniValue DescribeAddress(const CTxDestination& dest);

//! Parse a confirm target option and raise an RPC error if it is invalid.
unsigned int ParseConfirmTarget(const UniValue& value);

struct RPCArg {
enum class Type {
OBJ,
Expand Down

0 comments on commit 7e05caa

Please sign in to comment.