2010-07-14 11:54:31 -04:00
|
|
|
// Copyright (c) 2010 Satoshi Nakamoto
|
2014-12-16 22:47:57 -03:00
|
|
|
// Copyright (c) 2009-2014 The Bitcoin Core developers
|
2014-10-29 23:14:08 -03:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2012-05-18 10:02:28 -04:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2010-07-14 11:54:31 -04:00
|
|
|
|
2014-11-03 12:16:40 -03:00
|
|
|
#ifndef BITCOIN_RPCSERVER_H
|
|
|
|
#define BITCOIN_RPCSERVER_H
|
2012-04-20 20:37:34 -03:00
|
|
|
|
2014-04-22 19:46:19 -03:00
|
|
|
#include "amount.h"
|
2013-11-20 10:18:57 -03:00
|
|
|
#include "rpcprotocol.h"
|
2014-10-31 05:36:30 -03:00
|
|
|
#include "uint256.h"
|
2013-04-13 02:13:08 -03:00
|
|
|
|
2012-06-22 18:36:42 -04:00
|
|
|
#include <list>
|
2012-04-20 20:37:34 -03:00
|
|
|
#include <map>
|
2013-04-13 02:13:08 -03:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <string>
|
2012-08-21 11:03:38 -04:00
|
|
|
|
2012-04-20 20:37:34 -03:00
|
|
|
#include "json/json_spirit_reader_template.h"
|
|
|
|
#include "json/json_spirit_utils.h"
|
2013-04-13 02:13:08 -03:00
|
|
|
#include "json/json_spirit_writer_template.h"
|
2012-04-20 20:37:34 -03:00
|
|
|
|
2013-04-13 02:13:08 -03:00
|
|
|
class CBlockIndex;
|
2014-04-28 09:23:29 -04:00
|
|
|
class CNetAddr;
|
2012-05-23 23:20:07 -04:00
|
|
|
|
2014-06-27 00:10:53 -04: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-29 23:14:08 -03:00
|
|
|
/** Start RPC threads */
|
2013-03-07 00:31:26 -03:00
|
|
|
void StartRPCThreads();
|
2014-10-29 23:14:08 -03:00
|
|
|
/**
|
|
|
|
* Alternative to StartRPCThreads for the GUI, when no server is
|
2014-01-17 12:32:35 -03: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-19 23:19:29 -03:00
|
|
|
/** Stop RPC threads */
|
2013-03-07 00:31:26 -03:00
|
|
|
void StopRPCThreads();
|
2014-11-19 23:19:29 -03:00
|
|
|
/** Query whether RPC is running */
|
2012-05-13 00:43:24 -04:00
|
|
|
bool IsRPCRunning();
|
2012-04-09 16:07:25 -03:00
|
|
|
|
2014-11-19 23:19:29 -03:00
|
|
|
/**
|
|
|
|
* Set the RPC warmup status. When this is done, all RPC calls will error out
|
2014-10-29 14:08:31 -03: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 09:51:02 -03:00
|
|
|
/* returns the current warmup state. */
|
|
|
|
bool RPCIsInWarmup(std::string *statusOut);
|
|
|
|
|
2014-10-29 23:14:08 -03: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-22 18:36:42 -04:00
|
|
|
void RPCTypeCheck(const json_spirit::Array& params,
|
2012-08-20 16:18:17 -04:00
|
|
|
const std::list<json_spirit::Value_type>& typesExpected, bool fAllowNull=false);
|
2014-10-29 23:14:08 -03:00
|
|
|
/**
|
|
|
|
* Check for expected keys/value types in an Object.
|
|
|
|
* Use like: RPCTypeCheck(object, boost::assign::map_list_of("name", str_type)("value", int_type));
|
|
|
|
*/
|
2012-06-22 18:36:42 -04:00
|
|
|
void RPCTypeCheck(const json_spirit::Object& o,
|
2012-08-20 16:18:17 -04:00
|
|
|
const std::map<std::string, json_spirit::Value_type>& typesExpected, bool fAllowNull=false);
|
2012-06-22 18:36:42 -04:00
|
|
|
|
2014-10-29 23:14:08 -03:00
|
|
|
/**
|
|
|
|
* Run func nSeconds from now. Uses boost deadline timers.
|
|
|
|
* Overrides previous timer <name> (if any).
|
2013-05-07 10:47:00 -04:00
|
|
|
*/
|
2013-04-13 02:13:08 -03:00
|
|
|
void RPCRunLater(const std::string& name, boost::function<void(void)> func, int64_t nSeconds);
|
2013-05-07 10:47:00 -04:00
|
|
|
|
2014-04-28 09:23:29 -04:00
|
|
|
//! Convert boost::asio address to CNetAddr
|
|
|
|
extern CNetAddr BoostAsioToCNetAddr(boost::asio::ip::address address);
|
|
|
|
|
2012-04-20 20:37:34 -03:00
|
|
|
typedef json_spirit::Value(*rpcfn_type)(const json_spirit::Array& params, bool fHelp);
|
|
|
|
|
|
|
|
class CRPCCommand
|
|
|
|
{
|
|
|
|
public:
|
2014-07-15 15:38:52 -04:00
|
|
|
std::string category;
|
2012-04-20 20:37:34 -03:00
|
|
|
std::string name;
|
|
|
|
rpcfn_type actor;
|
|
|
|
bool okSafeMode;
|
2013-03-07 08:18:55 -03:00
|
|
|
bool threadSafe;
|
2013-08-25 00:00:02 -04:00
|
|
|
bool reqWallet;
|
2012-04-20 20:37:34 -03:00
|
|
|
};
|
|
|
|
|
2012-04-09 16:07:25 -03:00
|
|
|
/**
|
|
|
|
* Bitcoin RPC command dispatcher.
|
|
|
|
*/
|
2012-04-20 20:37:34 -03: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 16:07:25 -03: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-20 20:37:34 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
extern const CRPCTable tableRPC;
|
2013-05-30 09:51:41 -04:00
|
|
|
|
2014-10-29 23:14:08 -03:00
|
|
|
/**
|
|
|
|
* Utilities: convert hex-encoded Values
|
|
|
|
* (throws error if not hex).
|
|
|
|
*/
|
2013-07-15 02:24:33 -04: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 09:51:41 -04:00
|
|
|
extern void InitRPCMining();
|
|
|
|
extern void ShutdownRPCMining();
|
2012-04-20 20:37:34 -03:00
|
|
|
|
2013-04-13 02:13:08 -03:00
|
|
|
extern int64_t nWalletUnlockTime;
|
2014-04-22 19:46:19 -03:00
|
|
|
extern CAmount AmountFromValue(const json_spirit::Value& value);
|
|
|
|
extern json_spirit::Value ValueFromAmount(const CAmount& amount);
|
2012-08-21 11:03:38 -04:00
|
|
|
extern double GetDifficulty(const CBlockIndex* blockindex = NULL);
|
|
|
|
extern std::string HelpRequiringPassphrase();
|
2013-10-29 08:29:44 -03:00
|
|
|
extern std::string HelpExampleCli(std::string methodname, std::string args);
|
|
|
|
extern std::string HelpExampleRpc(std::string methodname, std::string args);
|
|
|
|
|
2012-08-21 11:03:38 -04:00
|
|
|
extern void EnsureWalletIsUnlocked();
|
2012-08-21 10:38:57 -04: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 07:34:33 -04:00
|
|
|
extern json_spirit::Value ping(const json_spirit::Array& params, bool fHelp);
|
2013-01-23 13:45:00 -03:00
|
|
|
extern json_spirit::Value addnode(const json_spirit::Array& params, bool fHelp);
|
2013-01-23 13:48:17 -03:00
|
|
|
extern json_spirit::Value getaddednodeinfo(const json_spirit::Array& params, bool fHelp);
|
2013-08-22 12:09:32 -04:00
|
|
|
extern json_spirit::Value getnettotals(const json_spirit::Array& params, bool fHelp);
|
2013-04-29 13:50:56 -04:00
|
|
|
|
2012-08-21 10:38:57 -04: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-25 19:06:01 -04:00
|
|
|
extern json_spirit::Value importaddress(const json_spirit::Array& params, bool fHelp);
|
2013-04-29 13:50:56 -04: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 10:38:57 -04: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);
|
2013-05-17 06:57:05 -04:00
|
|
|
extern json_spirit::Value getnetworkhashps(const json_spirit::Array& params, bool fHelp);
|
2012-08-21 10:38:57 -04:00
|
|
|
extern json_spirit::Value getmininginfo(const json_spirit::Array& params, bool fHelp);
|
2012-07-11 14:52:41 -04:00
|
|
|
extern json_spirit::Value prioritisetransaction(const json_spirit::Array& params, bool fHelp);
|
2012-08-21 10:38:57 -04: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 09:19:54 -03: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 10:38:57 -04: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 16:29:52 -04:00
|
|
|
extern json_spirit::Value getrawchangeaddress(const json_spirit::Array& params, bool fHelp);
|
2012-08-21 10:38:57 -04: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 08:48:52 -03:00
|
|
|
extern json_spirit::Value getunconfirmedbalance(const json_spirit::Array& params, bool fHelp);
|
2012-08-21 10:38:57 -04: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 10:32:40 -03:00
|
|
|
extern json_spirit::Value createmultisig(const json_spirit::Array& params, bool fHelp);
|
2012-08-21 10:38:57 -04: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 12:48:42 -04:00
|
|
|
extern json_spirit::Value listaddressgroupings(const json_spirit::Array& params, bool fHelp);
|
2012-08-21 10:38:57 -04: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 11:03:38 -04:00
|
|
|
extern json_spirit::Value getinfo(const json_spirit::Array& params, bool fHelp);
|
2014-02-21 01:56:04 -03:00
|
|
|
extern json_spirit::Value getwalletinfo(const json_spirit::Array& params, bool fHelp);
|
2014-05-05 07:22:28 -04: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-12 20:59:41 -03:00
|
|
|
extern json_spirit::Value setmocktime(const json_spirit::Array& params, bool fHelp);
|
2012-08-21 10:38:57 -04: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 14:52:09 -03: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 10:38:57 -04: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 01:22:10 -04:00
|
|
|
extern json_spirit::Value decodescript(const json_spirit::Array& params, bool fHelp);
|
2012-08-21 10:38:57 -04: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);
|
|
|
|
|
2012-08-21 11:03:38 -04:00
|
|
|
extern json_spirit::Value getblockcount(const json_spirit::Array& params, bool fHelp); // in rpcblockchain.cpp
|
2013-07-03 11:02:29 -04:00
|
|
|
extern json_spirit::Value getbestblockhash(const json_spirit::Array& params, bool fHelp);
|
2012-08-21 11:03:38 -04: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-06 23:58:19 -04:00
|
|
|
extern json_spirit::Value getmempoolinfo(const json_spirit::Array& params, bool fHelp);
|
2012-08-21 11:03:38 -04: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 18:04:54 -03: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 11:53:02 -04:00
|
|
|
extern json_spirit::Value verifychain(const json_spirit::Array& params, bool fHelp);
|
2014-08-03 12:12:19 -04:00
|
|
|
extern json_spirit::Value getchaintips(const json_spirit::Array& params, bool fHelp);
|
2014-11-19 05:39:42 -03: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 11:03:38 -04:00
|
|
|
|
2014-11-11 06:52:43 -03:00
|
|
|
// in rest.cpp
|
|
|
|
extern bool HTTPReq_REST(AcceptedConnection *conn,
|
2014-12-16 09:45:27 -03:00
|
|
|
const std::string& strURI,
|
|
|
|
const std::map<std::string, std::string>& mapHeaders,
|
2014-11-11 06:52:43 -03:00
|
|
|
bool fRun);
|
|
|
|
|
2014-11-03 12:16:40 -03:00
|
|
|
#endif // BITCOIN_RPCSERVER_H
|