refactor: Move GetDifficulty out of rpc/server.h

It has no business in `rpcserver.h`. Define it in the interface header
of the implementation unit `rpcblockchain` where it is defined.

Also modernize the signature to:

    double GetDifficulty(const CBlockIndex* blockindex = nullptr);

(remove `extern`, replace `NULL` with `nullptr`)
This commit is contained in:
Wladimir J. van der Laan 2017-03-27 12:14:43 +02:00
parent 5114f81136
commit e6dcfeec05
6 changed files with 25 additions and 8 deletions

View file

@ -122,6 +122,7 @@ BITCOIN_CORE_H = \
protocol.h \
random.h \
reverselock.h \
rpc/blockchain.h \
rpc/client.h \
rpc/protocol.h \
rpc/server.h \

View file

@ -3,6 +3,8 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "rpc/blockchain.h"
#include "amount.h"
#include "chain.h"
#include "chainparams.h"
@ -42,13 +44,6 @@ static CUpdatedBlock latestblock;
extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry);
void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex);
/**
* Get the difficulty of the net wrt to the given block index, or the chain tip if
* not provided.
*
* @return A floating point number that is a multiple of the main net minimum
* difficulty (4295032833 hashes).
*/
double GetDifficulty(const CBlockIndex* blockindex)
{
if (blockindex == NULL)

20
src/rpc/blockchain.h Normal file
View file

@ -0,0 +1,20 @@
// Copyright (c) 2017 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_RPC_BLOCKCHAIN_H
#define BITCOIN_RPC_BLOCKCHAIN_H
class CBlockIndex;
/**
* Get the difficulty of the net wrt to the given block index, or the chain tip if
* not provided.
*
* @return A floating point number that is a multiple of the main net minimum
* difficulty (4295032833 hashes).
*/
double GetDifficulty(const CBlockIndex* blockindex = nullptr);
#endif

View file

@ -16,6 +16,7 @@
#include "miner.h"
#include "net.h"
#include "pow.h"
#include "rpc/blockchain.h"
#include "rpc/server.h"
#include "txmempool.h"
#include "util.h"

View file

@ -9,6 +9,7 @@
#include "validation.h"
#include "net.h"
#include "netbase.h"
#include "rpc/blockchain.h"
#include "rpc/server.h"
#include "timedata.h"
#include "util.h"

View file

@ -191,7 +191,6 @@ extern std::vector<unsigned char> ParseHexO(const UniValue& o, std::string strKe
extern CAmount AmountFromValue(const UniValue& value);
extern UniValue ValueFromAmount(const CAmount& amount);
extern double GetDifficulty(const CBlockIndex* blockindex = NULL);
extern std::string HelpExampleCli(const std::string& methodname, const std::string& args);
extern std::string HelpExampleRpc(const std::string& methodname, const std::string& args);