Skip to content

Commit 4aa07fa

Browse files
committed
Merge #10095: refactor: Move GetDifficulty out of rpc/server.h
f885b67 refactor: Make rest.cpp dependency on `*toJSON` in `blockchain.cpp` explicit (Wladimir J. van der Laan) 8d8f28d refactor: Move RPCNotifyBlockChange out of `rpc/server.h` (Wladimir J. van der Laan) e6dcfee refactor: Move GetDifficulty out of `rpc/server.h` (Wladimir J. van der Laan) Tree-SHA512: fc2656611d18442f2fddba5ac1554d958151f6785c2039afdfc36735d7e71592d9686ff6cc7b2ad95180071d7514470e62c52d697c5a1e88f851bddaf5942edb
2 parents 9ab26bf + f885b67 commit 4aa07fa

File tree

8 files changed

+52
-17
lines changed

8 files changed

+52
-17
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/init.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "policy/policy.h"
2828
#include "rpc/server.h"
2929
#include "rpc/register.h"
30+
#include "rpc/blockchain.h"
3031
#include "script/standard.h"
3132
#include "script/sigcache.h"
3233
#include "scheduler.h"

src/rest.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "primitives/transaction.h"
1010
#include "validation.h"
1111
#include "httpserver.h"
12+
#include "rpc/blockchain.h"
1213
#include "rpc/server.h"
1314
#include "streams.h"
1415
#include "sync.h"
@@ -55,12 +56,9 @@ struct CCoin {
5556
}
5657
};
5758

58-
extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry);
59-
extern UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false);
60-
extern UniValue mempoolInfoToJSON();
61-
extern UniValue mempoolToJSON(bool fVerbose = false);
62-
extern void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex);
63-
extern UniValue blockheaderToJSON(const CBlockIndex* blockindex);
59+
/* Defined in rawtransaction.cpp */
60+
void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry);
61+
void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex);
6462

6563
static bool RESTERR(HTTPRequest* req, enum HTTPStatusCode status, std::string message)
6664
{

src/rpc/blockchain.cpp

Lines changed: 4 additions & 9 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)
@@ -106,7 +101,7 @@ UniValue blockheaderToJSON(const CBlockIndex* blockindex)
106101
return result;
107102
}
108103

109-
UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false)
104+
UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails)
110105
{
111106
UniValue result(UniValue::VOBJ);
112107
result.push_back(Pair("hash", blockindex->GetBlockHash().GetHex()));
@@ -383,7 +378,7 @@ void entryToJSON(UniValue &info, const CTxMemPoolEntry &e)
383378
info.push_back(Pair("depends", depends));
384379
}
385380

386-
UniValue mempoolToJSON(bool fVerbose = false)
381+
UniValue mempoolToJSON(bool fVerbose)
387382
{
388383
if (fVerbose)
389384
{

src/rpc/blockchain.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 CBlock;
9+
class CBlockIndex;
10+
class CScript;
11+
class CTransaction;
12+
class uint256;
13+
class UniValue;
14+
15+
/**
16+
* Get the difficulty of the net wrt to the given block index, or the chain tip if
17+
* not provided.
18+
*
19+
* @return A floating point number that is a multiple of the main net minimum
20+
* difficulty (4295032833 hashes).
21+
*/
22+
double GetDifficulty(const CBlockIndex* blockindex = nullptr);
23+
24+
/** Callback for when block tip changed. */
25+
void RPCNotifyBlockChange(bool ibd, const CBlockIndex *);
26+
27+
/** Block description to JSON */
28+
UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false);
29+
30+
/** Mempool information to JSON */
31+
UniValue mempoolInfoToJSON();
32+
33+
/** Mempool to JSON */
34+
UniValue mempoolToJSON(bool fVerbose = false);
35+
36+
/** Block header to JSON */
37+
UniValue blockheaderToJSON(const CBlockIndex* blockindex);
38+
39+
#endif
40+

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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,13 @@ 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

198197
bool StartRPC();
199198
void InterruptRPC();
200199
void StopRPC();
201200
std::string JSONRPCExecBatch(const UniValue& vReq);
202-
void RPCNotifyBlockChange(bool ibd, const CBlockIndex *);
203201

204202
// Retrieves any serialization flags requested in command line argument
205203
int RPCSerializationFlags();

0 commit comments

Comments
 (0)