2010-07-14 17:54:31 +02:00
|
|
|
// Copyright (c) 2010 Satoshi Nakamoto
|
2014-02-08 22:50:24 +01:00
|
|
|
// Copyright (c) 2009-2014 The Bitcoin developers
|
2010-07-14 17:54:31 +02:00
|
|
|
// Distributed under the MIT/X11 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
|
|
|
|
2013-11-20 14:18:57 +01:00
|
|
|
#ifndef _BITCOINRPC_SERVER_H_
|
|
|
|
#define _BITCOINRPC_SERVER_H_ 1
|
2012-04-21 01:37:34 +02:00
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
#include "uint256.h"
|
2013-11-20 14:18:57 +01:00
|
|
|
#include "rpcprotocol.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
|
|
|
|
2012-04-21 01:37:34 +02:00
|
|
|
#include "json/json_spirit_reader_template.h"
|
|
|
|
#include "json/json_spirit_utils.h"
|
2013-04-13 07:13:08 +02:00
|
|
|
#include "json/json_spirit_writer_template.h"
|
2012-04-21 01:37:34 +02:00
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
class CBlockIndex;
|
2012-05-24 05:20:07 +02:00
|
|
|
|
2014-01-17 16:32:35 +01:00
|
|
|
/* Start RPC threads */
|
2013-03-07 04:31:26 +01:00
|
|
|
void StartRPCThreads();
|
2014-01-17 16:32:35 +01:00
|
|
|
/* Alternative to StartRPCThreads for the GUI, when no server is
|
|
|
|
* 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();
|
|
|
|
/* Stop RPC threads */
|
2013-03-07 04:31:26 +01:00
|
|
|
void StopRPCThreads();
|
2012-04-09 21:07:25 +02:00
|
|
|
|
2012-06-23 00:36:42 +02: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));
|
|
|
|
*/
|
|
|
|
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);
|
2012-06-23 00:36:42 +02: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));
|
|
|
|
*/
|
|
|
|
void RPCTypeCheck(const json_spirit::Object& o,
|
2012-08-20 22:18:17 +02:00
|
|
|
const std::map<std::string, json_spirit::Value_type>& typesExpected, bool fAllowNull=false);
|
2012-06-23 00:36:42 +02:00
|
|
|
|
2013-05-07 16:47:00 +02:00
|
|
|
/*
|
|
|
|
Run func nSeconds from now. Uses boost deadline timers.
|
|
|
|
Overrides previous timer <name> (if any).
|
|
|
|
*/
|
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
|
|
|
|
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;
|
2013-03-07 12:18:55 +01:00
|
|
|
bool threadSafe;
|
2013-08-25 06:00:02 +02:00
|
|
|
bool reqWallet;
|
2012-04-21 01:37:34 +02:00
|
|
|
};
|
|
|
|
|
2012-04-09 21:07:25 +02:00
|
|
|
/**
|
2014-12-09 23:19:26 +01:00
|
|
|
* Darkcoin RPC command dispatcher.
|
2012-04-09 21:07:25 +02:00
|
|
|
*/
|
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
|
|
|
|
2013-07-15 08:24:33 +02:00
|
|
|
//
|
|
|
|
// Utilities: convert hex-encoded Values
|
|
|
|
// (throws error if not hex).
|
|
|
|
//
|
|
|
|
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;
|
|
|
|
extern int64_t AmountFromValue(const json_spirit::Value& value);
|
|
|
|
extern json_spirit::Value ValueFromAmount(int64_t amount);
|
2012-08-21 17:03:38 +02:00
|
|
|
extern double GetDifficulty(const CBlockIndex* blockindex = NULL);
|
|
|
|
extern std::string HexBits(unsigned int nBits);
|
|
|
|
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-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);
|
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 gethashespersec(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value getmininginfo(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value getwork(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value getblocktemplate(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value submitblock(const json_spirit::Array& params, bool fHelp);
|
|
|
|
|
|
|
|
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);
|
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);
|
|
|
|
|
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);
|
|
|
|
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);
|
2012-08-21 17:03:38 +02:00
|
|
|
|
2012-04-21 01:37:34 +02:00
|
|
|
#endif
|