2010-07-14 17:54:31 +02:00
|
|
|
// Copyright (c) 2010 Satoshi Nakamoto
|
2012-02-07 17:28:30 +01:00
|
|
|
// Copyright (c) 2009-2012 The Bitcoin developers
|
2010-07-14 17:54:31 +02:00
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2012-04-21 01:37:34 +02:00
|
|
|
#ifndef _BITCOINRPC_H_
|
|
|
|
#define _BITCOINRPC_H_ 1
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
|
2012-04-15 02:35:58 +02:00
|
|
|
#define BOOST_SPIRIT_THREADSAFE
|
2012-04-21 01:37:34 +02:00
|
|
|
#include "json/json_spirit_reader_template.h"
|
|
|
|
#include "json/json_spirit_writer_template.h"
|
|
|
|
#include "json/json_spirit_utils.h"
|
|
|
|
|
2010-07-14 17:54:31 +02:00
|
|
|
void ThreadRPCServer(void* parg);
|
|
|
|
int CommandLineRPC(int argc, char *argv[]);
|
2012-04-21 01:37:34 +02:00
|
|
|
|
2012-04-09 21:07:25 +02:00
|
|
|
/** Convert parameter values for RPC call from strings to command-specific JSON objects. */
|
|
|
|
json_spirit::Array RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &strParams);
|
|
|
|
|
2012-04-21 01:37:34 +02:00
|
|
|
typedef json_spirit::Value(*rpcfn_type)(const json_spirit::Array& params, bool fHelp);
|
|
|
|
|
|
|
|
class CRPCCommand
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string name;
|
|
|
|
rpcfn_type actor;
|
|
|
|
bool okSafeMode;
|
|
|
|
};
|
|
|
|
|
2012-04-09 21:07:25 +02:00
|
|
|
/**
|
|
|
|
* Bitcoin RPC command dispatcher.
|
|
|
|
*/
|
2012-04-21 01:37:34 +02:00
|
|
|
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;
|
2012-04-09 21:07:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute a method.
|
|
|
|
* @param method Method to execute
|
|
|
|
* @param params Array of arguments (JSON objects)
|
|
|
|
* @returns Result of the call.
|
|
|
|
* @throws an exception (json_spirit::Value) when an error happens.
|
|
|
|
*/
|
|
|
|
json_spirit::Value execute(const std::string &method, const json_spirit::Array ¶ms) const;
|
2012-04-21 01:37:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
extern const CRPCTable tableRPC;
|
|
|
|
|
|
|
|
#endif
|