2010-07-14 17:54:31 +02:00
|
|
|
// Copyright (c) 2010 Satoshi Nakamoto
|
2014-12-17 02:47:57 +01:00
|
|
|
// Copyright (c) 2009-2014 The Bitcoin Core developers
|
2014-10-30 03:14:08 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2012-05-18 16:02:28 +02:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2010-07-14 17:54:31 +02:00
|
|
|
|
2014-11-03 16:16:40 +01:00
|
|
|
#ifndef BITCOIN_RPCSERVER_H
|
|
|
|
#define BITCOIN_RPCSERVER_H
|
2012-04-21 01:37:34 +02:00
|
|
|
|
2014-04-23 00:46:19 +02:00
|
|
|
#include "amount.h"
|
2013-11-20 14:18:57 +01:00
|
|
|
#include "rpcprotocol.h"
|
2014-10-31 09:36:30 +01:00
|
|
|
#include "uint256.h"
|
2013-04-13 07:13:08 +02:00
|
|
|
|
2012-06-23 00:36:42 +02:00
|
|
|
#include <list>
|
2012-04-21 01:37:34 +02:00
|
|
|
#include <map>
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <string>
|
2012-08-21 17:03:38 +02:00
|
|
|
|
2014-08-20 21:15:16 +02:00
|
|
|
#include <boost/function.hpp>
|
|
|
|
#include "json_spirit_wrapper.h"
|
2012-04-21 01:37:34 +02:00
|
|
|
|
2014-10-19 10:46:17 +02:00
|
|
|
class CRPCCommand;
|
|
|
|
|
|
|
|
namespace RPCServer
|
|
|
|
{
|
|
|
|
void OnStarted(boost::function<void ()> slot);
|
|
|
|
void OnStopped(boost::function<void ()> slot);
|
|
|
|
void OnPreCommand(boost::function<void (const CRPCCommand&)> slot);
|
|
|
|
void OnPostCommand(boost::function<void (const CRPCCommand&)> slot);
|
|
|
|
}
|
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
class CBlockIndex;
|
2014-04-28 15:23:29 +02:00
|
|
|
class CNetAddr;
|
2012-05-24 05:20:07 +02:00
|
|
|
|
2014-06-27 06:10:53 +02:00
|
|
|
class AcceptedConnection
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~AcceptedConnection() {}
|
|
|
|
|
|
|
|
virtual std::iostream& stream() = 0;
|
|
|
|
virtual std::string peer_address_to_string() const = 0;
|
|
|
|
virtual void close() = 0;
|
|
|
|
};
|
|
|
|
|
2014-10-30 03:14:08 +01:00
|
|
|
/** Start RPC threads */
|
2013-03-07 04:31:26 +01:00
|
|
|
void StartRPCThreads();
|
2014-10-30 03:14:08 +01:00
|
|
|
/**
|
|
|
|
* Alternative to StartRPCThreads for the GUI, when no server is
|
2014-01-17 16:32:35 +01:00
|
|
|
* used. The RPC thread in this case is only used to handle timeouts.
|
|
|
|
* If real RPC threads have already been started this is a no-op.
|
|
|
|
*/
|
|
|
|
void StartDummyRPCThread();
|
2014-11-20 03:19:29 +01:00
|
|
|
/** Stop RPC threads */
|
2013-03-07 04:31:26 +01:00
|
|
|
void StopRPCThreads();
|
2014-11-20 03:19:29 +01:00
|
|
|
/** Query whether RPC is running */
|
2012-05-13 06:43:24 +02:00
|
|
|
bool IsRPCRunning();
|
2012-04-09 21:07:25 +02:00
|
|
|
|
2014-11-20 03:19:29 +01:00
|
|
|
/**
|
|
|
|
* Set the RPC warmup status. When this is done, all RPC calls will error out
|
2014-10-29 18:08:31 +01:00
|
|
|
* immediately with RPC_IN_WARMUP.
|
|
|
|
*/
|
|
|
|
void SetRPCWarmupStatus(const std::string& newStatus);
|
|
|
|
/* Mark warmup as done. RPC calls will be processed from now on. */
|
|
|
|
void SetRPCWarmupFinished();
|
|
|
|
|
2014-11-26 13:51:02 +01:00
|
|
|
/* returns the current warmup state. */
|
|
|
|
bool RPCIsInWarmup(std::string *statusOut);
|
|
|
|
|
2014-10-30 03:14:08 +01:00
|
|
|
/**
|
|
|
|
* Type-check arguments; throws JSONRPCError if wrong type given. Does not check that
|
|
|
|
* the right number of arguments are passed, just that any passed are the correct type.
|
|
|
|
* Use like: RPCTypeCheck(params, boost::assign::list_of(str_type)(int_type)(obj_type));
|
|
|
|
*/
|
2012-06-23 00:36:42 +02:00
|
|
|
void RPCTypeCheck(const json_spirit::Array& params,
|
2012-08-20 22:18:17 +02:00
|
|
|
const std::list<json_spirit::Value_type>& typesExpected, bool fAllowNull=false);
|
2014-08-20 21:15:16 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Check for expected keys/value types in an Object.
|
|
|
|
Use like: RPCTypeCheckObj(object, boost::assign::map_list_of("name", str_type)("value", int_type));
|
|
|
|
*/
|
|
|
|
void RPCTypeCheckObj(const UniValue& o,
|
|
|
|
const std::map<std::string, UniValue::VType>& typesExpected, bool fAllowNull=false);
|
2012-06-23 00:36:42 +02:00
|
|
|
|
2014-10-30 03:14:08 +01:00
|
|
|
/**
|
|
|
|
* Run func nSeconds from now. Uses boost deadline timers.
|
|
|
|
* Overrides previous timer <name> (if any).
|
2013-05-07 16:47:00 +02:00
|
|
|
*/
|
2013-04-13 07:13:08 +02:00
|
|
|
void RPCRunLater(const std::string& name, boost::function<void(void)> func, int64_t nSeconds);
|
2013-05-07 16:47:00 +02:00
|
|
|
|
2014-04-28 15:23:29 +02:00
|
|
|
//! Convert boost::asio address to CNetAddr
|
|
|
|
extern CNetAddr BoostAsioToCNetAddr(boost::asio::ip::address address);
|
|
|
|
|
2012-04-21 01:37:34 +02:00
|
|
|
typedef json_spirit::Value(*rpcfn_type)(const json_spirit::Array& params, bool fHelp);
|
|
|
|
|
|
|
|
class CRPCCommand
|
|
|
|
{
|
|
|
|
public:
|
2014-07-15 21:38:52 +02:00
|
|
|
std::string category;
|
2012-04-21 01:37:34 +02:00
|
|
|
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;
|
2013-05-30 15:51:41 +02:00
|
|
|
|
2014-10-30 03:14:08 +01:00
|
|
|
/**
|
|
|
|
* Utilities: convert hex-encoded Values
|
|
|
|
* (throws error if not hex).
|
|
|
|
*/
|
2013-07-15 08:24:33 +02:00
|
|
|
extern uint256 ParseHashV(const json_spirit::Value& v, std::string strName);
|
|
|
|
extern uint256 ParseHashO(const json_spirit::Object& o, std::string strKey);
|
|
|
|
extern std::vector<unsigned char> ParseHexV(const json_spirit::Value& v, std::string strName);
|
|
|
|
extern std::vector<unsigned char> ParseHexO(const json_spirit::Object& o, std::string strKey);
|
|
|
|
|
2013-05-30 15:51:41 +02:00
|
|
|
extern void InitRPCMining();
|
|
|
|
extern void ShutdownRPCMining();
|
2012-04-21 01:37:34 +02:00
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
extern int64_t nWalletUnlockTime;
|
2014-04-23 00:46:19 +02:00
|
|
|
extern CAmount AmountFromValue(const json_spirit::Value& value);
|
|
|
|
extern json_spirit::Value ValueFromAmount(const CAmount& amount);
|
2012-08-21 17:03:38 +02:00
|
|
|
extern double GetDifficulty(const CBlockIndex* blockindex = NULL);
|
|
|
|
extern std::string HelpRequiringPassphrase();
|
2013-10-29 12:29:44 +01:00
|
|
|
extern std::string HelpExampleCli(std::string methodname, std::string args);
|
|
|
|
extern std::string HelpExampleRpc(std::string methodname, std::string args);
|
|
|
|
|
2012-08-21 17:03:38 +02:00
|
|
|
extern void EnsureWalletIsUnlocked();
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
extern json_spirit::Value getconnectioncount(const json_spirit::Array& params, bool fHelp); // in rpcnet.cpp
|
|
|
|
extern json_spirit::Value getpeerinfo(const json_spirit::Array& params, bool fHelp);
|
2013-08-22 13:34:33 +02:00
|
|
|
extern json_spirit::Value ping(const json_spirit::Array& params, bool fHelp);
|
2013-01-23 17:45:00 +01:00
|
|
|
extern json_spirit::Value addnode(const json_spirit::Array& params, bool fHelp);
|
2013-01-23 17:48:17 +01:00
|
|
|
extern json_spirit::Value getaddednodeinfo(const json_spirit::Array& params, bool fHelp);
|
2013-08-22 18:09:32 +02:00
|
|
|
extern json_spirit::Value getnettotals(const json_spirit::Array& params, bool fHelp);
|
2013-04-29 19:50:56 +02:00
|
|
|
|
2012-08-21 16:38:57 +02:00
|
|
|
extern json_spirit::Value dumpprivkey(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp
|
|
|
|
extern json_spirit::Value importprivkey(const json_spirit::Array& params, bool fHelp);
|
2013-07-26 01:06:01 +02:00
|
|
|
extern json_spirit::Value importaddress(const json_spirit::Array& params, bool fHelp);
|
2013-04-29 19:50:56 +02:00
|
|
|
extern json_spirit::Value dumpwallet(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value importwallet(const json_spirit::Array& params, bool fHelp);
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
extern json_spirit::Value getgenerate(const json_spirit::Array& params, bool fHelp); // in rpcmining.cpp
|
|
|
|
extern json_spirit::Value setgenerate(const json_spirit::Array& params, bool fHelp);
|
2015-04-01 05:28:28 +02:00
|
|
|
extern json_spirit::Value generate(const json_spirit::Array& params, bool fHelp);
|
2013-05-17 12:57:05 +02:00
|
|
|
extern json_spirit::Value getnetworkhashps(const json_spirit::Array& params, bool fHelp);
|
2012-08-21 16:38:57 +02:00
|
|
|
extern json_spirit::Value getmininginfo(const json_spirit::Array& params, bool fHelp);
|
2012-07-11 20:52:41 +02:00
|
|
|
extern json_spirit::Value prioritisetransaction(const json_spirit::Array& params, bool fHelp);
|
2012-08-21 16:38:57 +02:00
|
|
|
extern json_spirit::Value getblocktemplate(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value submitblock(const json_spirit::Array& params, bool fHelp);
|
2014-03-17 13:19:54 +01:00
|
|
|
extern json_spirit::Value estimatefee(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value estimatepriority(const json_spirit::Array& params, bool fHelp);
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
extern json_spirit::Value getnewaddress(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp
|
|
|
|
extern json_spirit::Value getaccountaddress(const json_spirit::Array& params, bool fHelp);
|
2013-08-28 22:29:52 +02:00
|
|
|
extern json_spirit::Value getrawchangeaddress(const json_spirit::Array& params, bool fHelp);
|
2012-08-21 16:38:57 +02:00
|
|
|
extern json_spirit::Value setaccount(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value getaccount(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value getaddressesbyaccount(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value sendtoaddress(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value signmessage(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value verifymessage(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value getreceivedbyaddress(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value getreceivedbyaccount(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value getbalance(const json_spirit::Array& params, bool fHelp);
|
2013-11-24 12:48:52 +01:00
|
|
|
extern json_spirit::Value getunconfirmedbalance(const json_spirit::Array& params, bool fHelp);
|
2012-08-21 16:38:57 +02:00
|
|
|
extern json_spirit::Value movecmd(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value sendfrom(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value sendmany(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value addmultisigaddress(const json_spirit::Array& params, bool fHelp);
|
2012-09-10 15:32:40 +02:00
|
|
|
extern json_spirit::Value createmultisig(const json_spirit::Array& params, bool fHelp);
|
2012-08-21 16:38:57 +02:00
|
|
|
extern json_spirit::Value listreceivedbyaddress(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value listreceivedbyaccount(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value listtransactions(const json_spirit::Array& params, bool fHelp);
|
2012-08-01 18:48:42 +02:00
|
|
|
extern json_spirit::Value listaddressgroupings(const json_spirit::Array& params, bool fHelp);
|
2012-08-21 16:38:57 +02:00
|
|
|
extern json_spirit::Value listaccounts(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value listsinceblock(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value gettransaction(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value backupwallet(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value keypoolrefill(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value walletpassphrase(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value walletpassphrasechange(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value walletlock(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value encryptwallet(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value validateaddress(const json_spirit::Array& params, bool fHelp);
|
2012-08-21 17:03:38 +02:00
|
|
|
extern json_spirit::Value getinfo(const json_spirit::Array& params, bool fHelp);
|
2014-02-21 05:56:04 +01:00
|
|
|
extern json_spirit::Value getwalletinfo(const json_spirit::Array& params, bool fHelp);
|
2014-05-05 13:22:28 +02:00
|
|
|
extern json_spirit::Value getblockchaininfo(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value getnetworkinfo(const json_spirit::Array& params, bool fHelp);
|
2014-11-13 00:59:41 +01:00
|
|
|
extern json_spirit::Value setmocktime(const json_spirit::Array& params, bool fHelp);
|
2015-03-23 18:47:18 +01:00
|
|
|
extern json_spirit::Value resendwallettransactions(const json_spirit::Array& params, bool fHelp);
|
2012-08-21 16:38:57 +02:00
|
|
|
|
|
|
|
extern json_spirit::Value getrawtransaction(const json_spirit::Array& params, bool fHelp); // in rcprawtransaction.cpp
|
|
|
|
extern json_spirit::Value listunspent(const json_spirit::Array& params, bool fHelp);
|
2012-09-27 19:52:09 +02:00
|
|
|
extern json_spirit::Value lockunspent(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value listlockunspent(const json_spirit::Array& params, bool fHelp);
|
2012-08-21 16:38:57 +02:00
|
|
|
extern json_spirit::Value createrawtransaction(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value decoderawtransaction(const json_spirit::Array& params, bool fHelp);
|
2013-07-15 07:22:10 +02:00
|
|
|
extern json_spirit::Value decodescript(const json_spirit::Array& params, bool fHelp);
|
2012-08-21 16:38:57 +02:00
|
|
|
extern json_spirit::Value signrawtransaction(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value sendrawtransaction(const json_spirit::Array& params, bool fHelp);
|
2014-11-02 00:01:48 +01:00
|
|
|
extern json_spirit::Value gettxoutproof(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value verifytxoutproof(const json_spirit::Array& params, bool fHelp);
|
2012-08-21 16:38:57 +02:00
|
|
|
|
2012-08-21 17:03:38 +02:00
|
|
|
extern json_spirit::Value getblockcount(const json_spirit::Array& params, bool fHelp); // in rpcblockchain.cpp
|
2013-07-03 17:02:29 +02:00
|
|
|
extern json_spirit::Value getbestblockhash(const json_spirit::Array& params, bool fHelp);
|
2012-08-21 17:03:38 +02:00
|
|
|
extern json_spirit::Value getdifficulty(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value settxfee(const json_spirit::Array& params, bool fHelp);
|
2014-08-07 05:58:19 +02:00
|
|
|
extern json_spirit::Value getmempoolinfo(const json_spirit::Array& params, bool fHelp);
|
2012-08-21 17:03:38 +02:00
|
|
|
extern json_spirit::Value getrawmempool(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value getblockhash(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value getblock(const json_spirit::Array& params, bool fHelp);
|
2012-09-25 23:04:54 +02:00
|
|
|
extern json_spirit::Value gettxoutsetinfo(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value gettxout(const json_spirit::Array& params, bool fHelp);
|
2013-06-19 17:53:02 +02:00
|
|
|
extern json_spirit::Value verifychain(const json_spirit::Array& params, bool fHelp);
|
2014-08-03 18:12:19 +02:00
|
|
|
extern json_spirit::Value getchaintips(const json_spirit::Array& params, bool fHelp);
|
2014-11-19 09:39:42 +01:00
|
|
|
extern json_spirit::Value invalidateblock(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value reconsiderblock(const json_spirit::Array& params, bool fHelp);
|
2012-08-21 17:03:38 +02:00
|
|
|
|
2014-11-11 10:52:43 +01:00
|
|
|
// in rest.cpp
|
|
|
|
extern bool HTTPReq_REST(AcceptedConnection *conn,
|
2014-12-16 13:45:27 +01:00
|
|
|
const std::string& strURI,
|
2014-12-01 12:38:42 +01:00
|
|
|
const std::string& strRequest,
|
2014-12-16 13:45:27 +01:00
|
|
|
const std::map<std::string, std::string>& mapHeaders,
|
2014-11-11 10:52:43 +01:00
|
|
|
bool fRun);
|
|
|
|
|
2014-11-03 16:16:40 +01:00
|
|
|
#endif // BITCOIN_RPCSERVER_H
|