aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2012-04-21 01:37:34 +0200
committerPieter Wuille <pieter.wuille@gmail.com>2012-04-21 01:37:34 +0200
commite46704dd904192d8731eae1226805252e5252a0e (patch)
treef666357cc03a91c4be20331983c335d1ad603ad2 /src
parent9862229d4d852279b937c18cdbe076418585844e (diff)
Expose CRPCTable via bitcoinrpc.h for testing
Diffstat (limited to 'src')
-rw-r--r--src/bitcoinrpc.cpp31
-rw-r--r--src/bitcoinrpc.h34
-rw-r--r--src/test/rpc_tests.cpp9
3 files changed, 41 insertions, 33 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp
index 24b1220770..206347faf8 100644
--- a/src/bitcoinrpc.cpp
+++ b/src/bitcoinrpc.cpp
@@ -10,6 +10,7 @@
#include "net.h"
#include "init.h"
#include "ui_interface.h"
+#include "bitcoinrpc.h"
#undef printf
#include <boost/asio.hpp>
@@ -22,9 +23,6 @@
#include <boost/filesystem/fstream.hpp>
typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> SSLStream;
-#include "json/json_spirit_reader_template.h"
-#include "json/json_spirit_writer_template.h"
-#include "json/json_spirit_utils.h"
#define printf OutputDebugStringF
// MinGW 3.4.5 gets "fatal error: had to relocate PCH" if the json headers are
// precompiled in headers.h. The problem might be when the pch file goes over
@@ -37,27 +35,6 @@ using namespace boost::asio;
using namespace json_spirit;
void ThreadRPCServer2(void* parg);
-typedef Value(*rpcfn_type)(const Array& params, bool fHelp);
-
-class CRPCCommand
-{
-public:
- string name;
- rpcfn_type actor;
- bool okSafeMode;
-};
-
-class CRPCTable
-{
-private:
- map<string, const CRPCCommand*> mapCommands;
-public:
- CRPCTable();
- const CRPCCommand* operator[](string name) const;
- string help(string name) const;
-};
-
-const CRPCTable tableRPC;
static std::string strRPCUserColonPass;
@@ -2028,7 +2005,7 @@ Value getblock(const Array& params, bool fHelp)
//
-static CRPCCommand vRPCCommands[] =
+static const CRPCCommand vRPCCommands[] =
{ // name function safe mode?
// ------------------------ ----------------------- ----------
{ "help", &help, true },
@@ -2084,7 +2061,7 @@ CRPCTable::CRPCTable()
unsigned int vcidx;
for (vcidx = 0; vcidx < (sizeof(vRPCCommands) / sizeof(vRPCCommands[0])); vcidx++)
{
- CRPCCommand *pcmd;
+ const CRPCCommand *pcmd;
pcmd = &vRPCCommands[vcidx];
mapCommands[pcmd->name] = pcmd;
@@ -2785,3 +2762,5 @@ int main(int argc, char *argv[])
return 0;
}
#endif
+
+const CRPCTable tableRPC;
diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h
index a9cf3296f7..6b7293ed19 100644
--- a/src/bitcoinrpc.h
+++ b/src/bitcoinrpc.h
@@ -3,5 +3,39 @@
// Distributed under the MIT/X11 software license, see the accompanying
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
+#ifndef _BITCOINRPC_H_
+#define _BITCOINRPC_H_ 1
+
+#include <string>
+#include <map>
+
+#include "json/json_spirit_reader_template.h"
+#include "json/json_spirit_writer_template.h"
+#include "json/json_spirit_utils.h"
+
void ThreadRPCServer(void* parg);
int CommandLineRPC(int argc, char *argv[]);
+
+typedef json_spirit::Value(*rpcfn_type)(const json_spirit::Array& params, bool fHelp);
+
+class CRPCCommand
+{
+public:
+ std::string name;
+ rpcfn_type actor;
+ bool okSafeMode;
+};
+
+class CRPCTable
+{
+private:
+ std::map<std::string, const CRPCCommand*> mapCommands;
+public:
+ CRPCTable();
+ const CRPCCommand* operator[](std::string name) const;
+ std::string help(std::string name) const;
+};
+
+extern const CRPCTable tableRPC;
+
+#endif
diff --git a/src/test/rpc_tests.cpp b/src/test/rpc_tests.cpp
index 87462f765b..7a438e5d51 100644
--- a/src/test/rpc_tests.cpp
+++ b/src/test/rpc_tests.cpp
@@ -3,16 +3,11 @@
#include "base58.h"
#include "util.h"
-#include "json/json_spirit_reader_template.h"
-#include "json/json_spirit_writer_template.h"
-#include "json/json_spirit_utils.h"
+#include "bitcoinrpc.h"
using namespace std;
using namespace json_spirit;
-typedef Value(*rpcfn_type)(const Array& params, bool fHelp);
-extern map<string, rpcfn_type> mapCallTable;
-
BOOST_AUTO_TEST_SUITE(rpc_tests)
static Array
@@ -36,7 +31,7 @@ struct TestNetFixture
BOOST_FIXTURE_TEST_CASE(rpc_addmultisig, TestNetFixture)
{
- rpcfn_type addmultisig = mapCallTable["addmultisigaddress"];
+ rpcfn_type addmultisig = tableRPC["addmultisigaddress"]->actor;
// old, 65-byte-long:
const char* address1Hex = "0434e3e09f49ea168c5bbf53f877ff4206923858aab7c7e1df25bc263978107c95e35065a27ef6f1b27222db0ec97e0e895eaca603d3ee0d4c060ce3d8a00286c8";