Skip to content

Commit e6dcfee

Browse files
committed
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`)
1 parent 5114f81 commit e6dcfee

File tree

6 files changed

+25
-8
lines changed

6 files changed

+25
-8
lines changed

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ BITCOIN_CORE_H = \
122122
protocol.h \
123123
random.h \
124124
reverselock.h \
125+
rpc/blockchain.h \
125126
rpc/client.h \
126127
rpc/protocol.h \
127128
rpc/server.h \

src/rpc/blockchain.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// Distributed under the MIT software license, see the accompanying
44
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

6+
#include "rpc/blockchain.h"
7+
68
#include "amount.h"
79
#include "chain.h"
810
#include "chainparams.h"
@@ -42,13 +44,6 @@ static CUpdatedBlock latestblock;
4244
extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry);
4345
void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex);
4446

45-
/**
46-
* Get the difficulty of the net wrt to the given block index, or the chain tip if
47-
* not provided.
48-
*
49-
* @return A floating point number that is a multiple of the main net minimum
50-
* difficulty (4295032833 hashes).
51-
*/
5247
double GetDifficulty(const CBlockIndex* blockindex)
5348
{
5449
if (blockindex == NULL)

src/rpc/blockchain.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) 2017 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#ifndef BITCOIN_RPC_BLOCKCHAIN_H
6+
#define BITCOIN_RPC_BLOCKCHAIN_H
7+
8+
class CBlockIndex;
9+
10+
/**
11+
* Get the difficulty of the net wrt to the given block index, or the chain tip if
12+
* not provided.
13+
*
14+
* @return A floating point number that is a multiple of the main net minimum
15+
* difficulty (4295032833 hashes).
16+
*/
17+
double GetDifficulty(const CBlockIndex* blockindex = nullptr);
18+
19+
#endif
20+

src/rpc/mining.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "miner.h"
1717
#include "net.h"
1818
#include "pow.h"
19+
#include "rpc/blockchain.h"
1920
#include "rpc/server.h"
2021
#include "txmempool.h"
2122
#include "util.h"

src/rpc/misc.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "validation.h"
1010
#include "net.h"
1111
#include "netbase.h"
12+
#include "rpc/blockchain.h"
1213
#include "rpc/server.h"
1314
#include "timedata.h"
1415
#include "util.h"

src/rpc/server.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ extern std::vector<unsigned char> ParseHexO(const UniValue& o, std::string strKe
191191

192192
extern CAmount AmountFromValue(const UniValue& value);
193193
extern UniValue ValueFromAmount(const CAmount& amount);
194-
extern double GetDifficulty(const CBlockIndex* blockindex = NULL);
195194
extern std::string HelpExampleCli(const std::string& methodname, const std::string& args);
196195
extern std::string HelpExampleRpc(const std::string& methodname, const std::string& args);
197196

0 commit comments

Comments
 (0)