Skip to content

Commit fb8a8cf

Browse files
committed
rpc: Register calls where they are defined
Split out methods to every module, apart from 'help' and 'stop' which are implemented in rpcserver.cpp itself. - This makes it easier to add or remove RPC commands - no longer everything that includes rpcserver.h has to be rebuilt when there's a change there. - Cleans up `rpc/server.h` by getting rid of the huge cluttered list of function definitions. - Removes most of the bitcoin-specific code from rpcserver.cpp and .h. Continues bitcoin#7307 for the non-wallet.
1 parent 5131005 commit fb8a8cf

File tree

15 files changed

+165
-137
lines changed

15 files changed

+165
-137
lines changed

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ BITCOIN_CORE_H = \
130130
rpc/client.h \
131131
rpc/protocol.h \
132132
rpc/server.h \
133+
rpc/register.h \
133134
scheduler.h \
134135
script/sigcache.h \
135136
script/sign.h \

src/init.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "net.h"
2525
#include "policy/policy.h"
2626
#include "rpc/server.h"
27+
#include "rpc/register.h"
2728
#include "script/standard.h"
2829
#include "script/sigcache.h"
2930
#include "scheduler.h"
@@ -913,10 +914,11 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
913914
fPruneMode = true;
914915
}
915916

917+
RegisterAllCoreRPCCommands(tableRPC);
916918
#ifdef ENABLE_WALLET
917919
bool fDisableWallet = GetBoolArg("-disablewallet", false);
918920
if (!fDisableWallet)
919-
walletRegisterRPCCommands();
921+
RegisterWalletRPCCommands(tableRPC);
920922
#endif
921923

922924
nConnectTimeout = GetArg("-timeout", DEFAULT_CONNECT_TIMEOUT);

src/rest.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ static bool rest_block_notxdetails(HTTPRequest* req, const std::string& strURIPa
273273
return rest_block(req, strURIPart, false);
274274
}
275275

276+
// A bit of a hack - dependency on a function defined in rpc/blockchain.cpp
277+
UniValue getblockchaininfo(const UniValue& params, bool fHelp);
278+
276279
static bool rest_chaininfo(HTTPRequest* req, const std::string& strURIPart)
277280
{
278281
if (!CheckWarmup(req))

src/rpc/blockchain.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,3 +911,31 @@ UniValue reconsiderblock(const UniValue& params, bool fHelp)
911911

912912
return NullUniValue;
913913
}
914+
915+
static const CRPCCommand commands[] =
916+
{ // category name actor (function) okSafeMode
917+
// --------------------- ------------------------ ----------------------- ----------
918+
{ "blockchain", "getblockchaininfo", &getblockchaininfo, true },
919+
{ "blockchain", "getbestblockhash", &getbestblockhash, true },
920+
{ "blockchain", "getblockcount", &getblockcount, true },
921+
{ "blockchain", "getblock", &getblock, true },
922+
{ "blockchain", "getblockhash", &getblockhash, true },
923+
{ "blockchain", "getblockheader", &getblockheader, true },
924+
{ "blockchain", "getchaintips", &getchaintips, true },
925+
{ "blockchain", "getdifficulty", &getdifficulty, true },
926+
{ "blockchain", "getmempoolinfo", &getmempoolinfo, true },
927+
{ "blockchain", "getrawmempool", &getrawmempool, true },
928+
{ "blockchain", "gettxout", &gettxout, true },
929+
{ "blockchain", "gettxoutsetinfo", &gettxoutsetinfo, true },
930+
{ "blockchain", "verifychain", &verifychain, true },
931+
932+
/* Not shown in help */
933+
{ "hidden", "invalidateblock", &invalidateblock, true },
934+
{ "hidden", "reconsiderblock", &reconsiderblock, true },
935+
};
936+
937+
void RegisterBlockchainRPCCommands(CRPCTable &tableRPC)
938+
{
939+
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
940+
tableRPC.appendCommand(commands[vcidx].name, &commands[vcidx]);
941+
}

src/rpc/mining.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,3 +781,27 @@ UniValue estimatesmartpriority(const UniValue& params, bool fHelp)
781781
result.push_back(Pair("blocks", answerFound));
782782
return result;
783783
}
784+
785+
static const CRPCCommand commands[] =
786+
{ // category name actor (function) okSafeMode
787+
// --------------------- ------------------------ ----------------------- ----------
788+
{ "mining", "getnetworkhashps", &getnetworkhashps, true },
789+
{ "mining", "getmininginfo", &getmininginfo, true },
790+
{ "mining", "prioritisetransaction", &prioritisetransaction, true },
791+
{ "mining", "getblocktemplate", &getblocktemplate, true },
792+
{ "mining", "submitblock", &submitblock, true },
793+
794+
{ "generating", "generate", &generate, true },
795+
{ "generating", "generatetoaddress", &generatetoaddress, true },
796+
797+
{ "util", "estimatefee", &estimatefee, true },
798+
{ "util", "estimatepriority", &estimatepriority, true },
799+
{ "util", "estimatesmartfee", &estimatesmartfee, true },
800+
{ "util", "estimatesmartpriority", &estimatesmartpriority, true },
801+
};
802+
803+
void RegisterMiningRPCCommands(CRPCTable &tableRPC)
804+
{
805+
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
806+
tableRPC.appendCommand(commands[vcidx].name, &commands[vcidx]);
807+
}

src/rpc/misc.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,21 @@ UniValue setmocktime(const UniValue& params, bool fHelp)
396396

397397
return NullUniValue;
398398
}
399+
400+
static const CRPCCommand commands[] =
401+
{ // category name actor (function) okSafeMode
402+
// --------------------- ------------------------ ----------------------- ----------
403+
{ "control", "getinfo", &getinfo, true }, /* uses wallet if enabled */
404+
{ "util", "validateaddress", &validateaddress, true }, /* uses wallet if enabled */
405+
{ "util", "createmultisig", &createmultisig, true },
406+
{ "util", "verifymessage", &verifymessage, true },
407+
408+
/* Not shown in help */
409+
{ "hidden", "setmocktime", &setmocktime, true },
410+
};
411+
412+
void RegisterMiscRPCCommands(CRPCTable &tableRPC)
413+
{
414+
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
415+
tableRPC.appendCommand(commands[vcidx].name, &commands[vcidx]);
416+
}

src/rpc/net.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,3 +626,25 @@ UniValue clearbanned(const UniValue& params, bool fHelp)
626626

627627
return NullUniValue;
628628
}
629+
630+
static const CRPCCommand commands[] =
631+
{ // category name actor (function) okSafeMode
632+
// --------------------- ------------------------ ----------------------- ----------
633+
{ "network", "getconnectioncount", &getconnectioncount, true },
634+
{ "network", "ping", &ping, true },
635+
{ "network", "getpeerinfo", &getpeerinfo, true },
636+
{ "network", "addnode", &addnode, true },
637+
{ "network", "disconnectnode", &disconnectnode, true },
638+
{ "network", "getaddednodeinfo", &getaddednodeinfo, true },
639+
{ "network", "getnettotals", &getnettotals, true },
640+
{ "network", "getnetworkinfo", &getnetworkinfo, true },
641+
{ "network", "setban", &setban, true },
642+
{ "network", "listbanned", &listbanned, true },
643+
{ "network", "clearbanned", &clearbanned, true },
644+
};
645+
646+
void RegisterNetRPCCommands(CRPCTable &tableRPC)
647+
{
648+
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
649+
tableRPC.appendCommand(commands[vcidx].name, &commands[vcidx]);
650+
}

src/rpc/rawtransaction.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,3 +841,23 @@ UniValue sendrawtransaction(const UniValue& params, bool fHelp)
841841

842842
return hashTx.GetHex();
843843
}
844+
845+
static const CRPCCommand commands[] =
846+
{ // category name actor (function) okSafeMode
847+
// --------------------- ------------------------ ----------------------- ----------
848+
{ "rawtransactions", "getrawtransaction", &getrawtransaction, true },
849+
{ "rawtransactions", "createrawtransaction", &createrawtransaction, true },
850+
{ "rawtransactions", "decoderawtransaction", &decoderawtransaction, true },
851+
{ "rawtransactions", "decodescript", &decodescript, true },
852+
{ "rawtransactions", "sendrawtransaction", &sendrawtransaction, false },
853+
{ "rawtransactions", "signrawtransaction", &signrawtransaction, false }, /* uses wallet if enabled */
854+
855+
{ "blockchain", "gettxoutproof", &gettxoutproof, true },
856+
{ "blockchain", "verifytxoutproof", &verifytxoutproof, true },
857+
};
858+
859+
void RegisterRawTransactionRPCCommands(CRPCTable &tableRPC)
860+
{
861+
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
862+
tableRPC.appendCommand(commands[vcidx].name, &commands[vcidx]);
863+
}

src/rpc/register.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) 2009-2016 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_RPCREGISTER_H
6+
#define BITCOIN_RPCREGISTER_H
7+
8+
/** These are in one header file to avoid creating tons of single-function
9+
* headers for everything under src/rpc/ */
10+
class CRPCTable;
11+
12+
/** Register block chain RPC commands */
13+
void RegisterBlockchainRPCCommands(CRPCTable &tableRPC);
14+
/** Register P2P networking RPC commands */
15+
void RegisterNetRPCCommands(CRPCTable &tableRPC);
16+
/** Register miscellaneous RPC commands */
17+
void RegisterMiscRPCCommands(CRPCTable &tableRPC);
18+
/** Register mining RPC commands */
19+
void RegisterMiningRPCCommands(CRPCTable &tableRPC);
20+
/** Register raw transaction RPC commands */
21+
void RegisterRawTransactionRPCCommands(CRPCTable &tableRPC);
22+
23+
static inline void RegisterAllCoreRPCCommands(CRPCTable &tableRPC)
24+
{
25+
RegisterBlockchainRPCCommands(tableRPC);
26+
RegisterNetRPCCommands(tableRPC);
27+
RegisterMiscRPCCommands(tableRPC);
28+
RegisterMiningRPCCommands(tableRPC);
29+
RegisterRawTransactionRPCCommands(tableRPC);
30+
}
31+
32+
#endif

src/rpc/server.cpp

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -256,72 +256,8 @@ static const CRPCCommand vRPCCommands[] =
256256
{ // category name actor (function) okSafeMode
257257
// --------------------- ------------------------ ----------------------- ----------
258258
/* Overall control/query calls */
259-
{ "control", "getinfo", &getinfo, true }, /* uses wallet if enabled */
260259
{ "control", "help", &help, true },
261260
{ "control", "stop", &stop, true },
262-
263-
/* P2P networking */
264-
{ "network", "getnetworkinfo", &getnetworkinfo, true },
265-
{ "network", "addnode", &addnode, true },
266-
{ "network", "disconnectnode", &disconnectnode, true },
267-
{ "network", "getaddednodeinfo", &getaddednodeinfo, true },
268-
{ "network", "getconnectioncount", &getconnectioncount, true },
269-
{ "network", "getnettotals", &getnettotals, true },
270-
{ "network", "getpeerinfo", &getpeerinfo, true },
271-
{ "network", "ping", &ping, true },
272-
{ "network", "setban", &setban, true },
273-
{ "network", "listbanned", &listbanned, true },
274-
{ "network", "clearbanned", &clearbanned, true },
275-
276-
/* Block chain and UTXO */
277-
{ "blockchain", "getblockchaininfo", &getblockchaininfo, true },
278-
{ "blockchain", "getbestblockhash", &getbestblockhash, true },
279-
{ "blockchain", "getblockcount", &getblockcount, true },
280-
{ "blockchain", "getblock", &getblock, true },
281-
{ "blockchain", "getblockhash", &getblockhash, true },
282-
{ "blockchain", "getblockheader", &getblockheader, true },
283-
{ "blockchain", "getchaintips", &getchaintips, true },
284-
{ "blockchain", "getdifficulty", &getdifficulty, true },
285-
{ "blockchain", "getmempoolinfo", &getmempoolinfo, true },
286-
{ "blockchain", "getrawmempool", &getrawmempool, true },
287-
{ "blockchain", "gettxout", &gettxout, true },
288-
{ "blockchain", "gettxoutproof", &gettxoutproof, true },
289-
{ "blockchain", "verifytxoutproof", &verifytxoutproof, true },
290-
{ "blockchain", "gettxoutsetinfo", &gettxoutsetinfo, true },
291-
{ "blockchain", "verifychain", &verifychain, true },
292-
293-
/* Mining */
294-
{ "mining", "getblocktemplate", &getblocktemplate, true },
295-
{ "mining", "getmininginfo", &getmininginfo, true },
296-
{ "mining", "getnetworkhashps", &getnetworkhashps, true },
297-
{ "mining", "prioritisetransaction", &prioritisetransaction, true },
298-
{ "mining", "submitblock", &submitblock, true },
299-
300-
/* Coin generation */
301-
{ "generating", "generate", &generate, true },
302-
{ "generating", "generatetoaddress", &generatetoaddress, true },
303-
304-
/* Raw transactions */
305-
{ "rawtransactions", "createrawtransaction", &createrawtransaction, true },
306-
{ "rawtransactions", "decoderawtransaction", &decoderawtransaction, true },
307-
{ "rawtransactions", "decodescript", &decodescript, true },
308-
{ "rawtransactions", "getrawtransaction", &getrawtransaction, true },
309-
{ "rawtransactions", "sendrawtransaction", &sendrawtransaction, false },
310-
{ "rawtransactions", "signrawtransaction", &signrawtransaction, false }, /* uses wallet if enabled */
311-
312-
/* Utility functions */
313-
{ "util", "createmultisig", &createmultisig, true },
314-
{ "util", "validateaddress", &validateaddress, true }, /* uses wallet if enabled */
315-
{ "util", "verifymessage", &verifymessage, true },
316-
{ "util", "estimatefee", &estimatefee, true },
317-
{ "util", "estimatepriority", &estimatepriority, true },
318-
{ "util", "estimatesmartfee", &estimatesmartfee, true },
319-
{ "util", "estimatesmartpriority", &estimatesmartpriority, true },
320-
321-
/* Not shown in help */
322-
{ "hidden", "invalidateblock", &invalidateblock, true },
323-
{ "hidden", "reconsiderblock", &reconsiderblock, true },
324-
{ "hidden", "setmocktime", &setmocktime, true },
325261
};
326262

327263
CRPCTable::CRPCTable()

0 commit comments

Comments
 (0)