2010-07-14 15:54:31 +00:00
|
|
|
// Copyright (c) 2010 Satoshi Nakamoto
|
2012-02-07 11:28:30 -05:00
|
|
|
// Copyright (c) 2009-2012 The Bitcoin developers
|
2010-07-14 15:54:31 +00:00
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
2012-05-18 22:02:28 +08:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2010-07-14 15:54:31 +00:00
|
|
|
|
2012-04-21 01:37:34 +02:00
|
|
|
#ifndef _BITCOINRPC_H_
|
|
|
|
#define _BITCOINRPC_H_ 1
|
|
|
|
|
|
|
|
#include <string>
|
2012-06-22 18:36:42 -04:00
|
|
|
#include <list>
|
2012-04-21 01:37:34 +02:00
|
|
|
#include <map>
|
|
|
|
|
2012-08-21 11:03:38 -04:00
|
|
|
class CBlockIndex;
|
|
|
|
|
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"
|
|
|
|
|
2012-08-21 11:58:47 -04:00
|
|
|
#include "util.h"
|
|
|
|
|
2012-10-04 10:43:40 +02:00
|
|
|
// HTTP status codes
|
|
|
|
enum HTTPStatusCode
|
|
|
|
{
|
|
|
|
HTTP_OK = 200,
|
|
|
|
HTTP_BAD_REQUEST = 400,
|
|
|
|
HTTP_UNAUTHORIZED = 401,
|
|
|
|
HTTP_FORBIDDEN = 403,
|
|
|
|
HTTP_NOT_FOUND = 404,
|
|
|
|
HTTP_INTERNAL_SERVER_ERROR = 500,
|
|
|
|
};
|
|
|
|
|
2012-10-04 09:34:44 +02:00
|
|
|
// Bitcoin RPC error codes
|
|
|
|
enum RPCErrorCode
|
|
|
|
{
|
|
|
|
// Standard JSON-RPC 2.0 errors
|
|
|
|
RPC_INVALID_REQUEST = -32600,
|
|
|
|
RPC_METHOD_NOT_FOUND = -32601,
|
|
|
|
RPC_INVALID_PARAMS = -32602,
|
|
|
|
RPC_INTERNAL_ERROR = -32603,
|
|
|
|
RPC_PARSE_ERROR = -32700,
|
|
|
|
|
|
|
|
// General application defined errors
|
|
|
|
RPC_MISC_ERROR = -1, // std::exception thrown in command handling
|
|
|
|
RPC_FORBIDDEN_BY_SAFE_MODE = -2, // Server is in safe mode, and command is not allowed in safe mode
|
|
|
|
RPC_TYPE_ERROR = -3, // Unexpected type was passed as parameter
|
|
|
|
RPC_INVALID_ADDRESS_OR_KEY = -5, // Invalid address or key
|
|
|
|
RPC_OUT_OF_MEMORY = -7, // Ran out of memory during operation
|
|
|
|
RPC_INVALID_PARAMETER = -8, // Invalid, missing or duplicate parameter
|
|
|
|
RPC_DATABASE_ERROR = -20, // Database error
|
|
|
|
RPC_DESERIALIZATION_ERROR = -22, // Error parsing or validating structure in raw format
|
2014-04-07 12:45:51 +02:00
|
|
|
RPC_FORBIDDEN_ON_PUBLIC_SERVER = -23, // public server mode is activated, this method is not allowed
|
2015-12-18 21:20:50 -02:00
|
|
|
RPC_TIMEOUT = -24, // timeout on resource retrieval
|
2015-12-20 13:35:33 -02:00
|
|
|
RPC_RESOURCE_BUSY_TRY_AGAIN = -25, // Resource is currently busy, try again later
|
2012-10-04 09:34:44 +02:00
|
|
|
|
|
|
|
// P2P client errors
|
|
|
|
RPC_CLIENT_NOT_CONNECTED = -9, // Bitcoin is not connected
|
|
|
|
RPC_CLIENT_IN_INITIAL_DOWNLOAD = -10, // Still downloading initial blocks
|
|
|
|
|
|
|
|
// Wallet errors
|
|
|
|
RPC_WALLET_ERROR = -4, // Unspecified problem with wallet (key not found etc.)
|
|
|
|
RPC_WALLET_INSUFFICIENT_FUNDS = -6, // Not enough funds in wallet or account
|
|
|
|
RPC_WALLET_INVALID_ACCOUNT_NAME = -11, // Invalid account name
|
|
|
|
RPC_WALLET_KEYPOOL_RAN_OUT = -12, // Keypool ran out, call keypoolrefill first
|
|
|
|
RPC_WALLET_UNLOCK_NEEDED = -13, // Enter the wallet passphrase with walletpassphrase first
|
|
|
|
RPC_WALLET_PASSPHRASE_INCORRECT = -14, // The wallet passphrase entered was incorrect
|
|
|
|
RPC_WALLET_WRONG_ENC_STATE = -15, // Command given in wrong wallet encryption state (encrypting an encrypted wallet etc.)
|
|
|
|
RPC_WALLET_ENCRYPTION_FAILED = -16, // Failed to encrypt the wallet
|
|
|
|
RPC_WALLET_ALREADY_UNLOCKED = -17, // Wallet is already unlocked
|
|
|
|
};
|
|
|
|
|
2012-05-23 23:20:07 -04:00
|
|
|
json_spirit::Object JSONRPCError(int code, const std::string& message);
|
|
|
|
|
2013-03-06 22:31:26 -05:00
|
|
|
void StartRPCThreads();
|
|
|
|
void StopRPCThreads();
|
2010-07-14 15:54:31 +00:00
|
|
|
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-06-22 18:36:42 -04: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 16:18:17 -04:00
|
|
|
const std::list<json_spirit::Value_type>& typesExpected, bool fAllowNull=false);
|
2012-06-22 18:36:42 -04: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 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
|
|
|
|
2013-05-07 10:47:00 -04:00
|
|
|
/*
|
|
|
|
Run func nSeconds from now. Uses boost deadline timers.
|
|
|
|
Overrides previous timer <name> (if any).
|
|
|
|
*/
|
|
|
|
void RPCRunLater(const std::string& name, boost::function<void(void)> func, int64 nSeconds);
|
|
|
|
|
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 06:18:55 -05:00
|
|
|
bool threadSafe;
|
2014-04-07 12:45:51 +02:00
|
|
|
bool allowOnPublicServer;
|
2012-04-21 01:37:34 +02:00
|
|
|
};
|
|
|
|
|
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
|
|
|
|
|
|
|
extern void InitRPCMining();
|
|
|
|
extern void ShutdownRPCMining();
|
2012-04-21 01:37:34 +02:00
|
|
|
|
2012-08-21 10:38:57 -04:00
|
|
|
extern int64 nWalletUnlockTime;
|
|
|
|
extern int64 AmountFromValue(const json_spirit::Value& value);
|
|
|
|
extern json_spirit::Value ValueFromAmount(int64 amount);
|
2012-08-21 11:03:38 -04:00
|
|
|
extern double GetDifficulty(const CBlockIndex* blockindex = NULL);
|
|
|
|
extern std::string HexBits(unsigned int nBits);
|
|
|
|
extern std::string HelpRequiringPassphrase();
|
|
|
|
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-01-23 11:45:00 -05:00
|
|
|
extern json_spirit::Value addnode(const json_spirit::Array& params, bool fHelp);
|
2013-11-10 11:54:22 -02:00
|
|
|
extern json_spirit::Value adddnsseed(const json_spirit::Array& params, bool fHelp);
|
2013-01-23 11:48:17 -05:00
|
|
|
extern json_spirit::Value getaddednodeinfo(const json_spirit::Array& params, bool fHelp);
|
2013-04-29 19:50:56 +02:00
|
|
|
|
2012-08-21 10:38:57 -04:00
|
|
|
extern json_spirit::Value dumpprivkey(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp
|
2013-10-29 17:54:23 -02:00
|
|
|
extern json_spirit::Value dumppubkey(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp
|
2014-12-19 19:41:02 -02:00
|
|
|
extern json_spirit::Value testvector(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp
|
2012-08-21 10:38:57 -04:00
|
|
|
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 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);
|
|
|
|
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);
|
|
|
|
|
2013-09-19 07:23:54 -03:00
|
|
|
extern json_spirit::Value createwalletuser(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp
|
|
|
|
extern json_spirit::Value listwalletusers(const json_spirit::Array& params, bool fHelp);
|
2012-08-21 10:38:57 -04:00
|
|
|
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 listtransactions(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);
|
2012-08-21 11:03:38 -04:00
|
|
|
extern json_spirit::Value getinfo(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 13:52:09 -04: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);
|
|
|
|
extern json_spirit::Value sendrawtransaction(const json_spirit::Array& params, bool fHelp);
|
2013-07-25 10:45:42 -03:00
|
|
|
extern json_spirit::Value sendnewusertransaction(const json_spirit::Array& params, bool fHelp);
|
2012-08-21 10:38:57 -04:00
|
|
|
|
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);
|
|
|
|
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 11:53:02 -04:00
|
|
|
extern json_spirit::Value verifychain(const json_spirit::Array& params, bool fHelp);
|
2014-02-14 17:43:44 -02:00
|
|
|
extern json_spirit::Value getlastsoftcheckpoint(const json_spirit::Array& params, bool fHelp);
|
2013-08-05 22:33:38 -03:00
|
|
|
extern json_spirit::Value dhtput(const json_spirit::Array& params, bool fHelp);
|
2014-12-22 19:33:48 -02:00
|
|
|
extern json_spirit::Value dhtputraw(const json_spirit::Array& params, bool fHelp);
|
2013-08-05 22:33:38 -03:00
|
|
|
extern json_spirit::Value dhtget(const json_spirit::Array& params, bool fHelp);
|
2013-08-20 12:18:03 -03:00
|
|
|
extern json_spirit::Value newpostmsg(const json_spirit::Array& params, bool fHelp);
|
2016-03-19 14:55:49 -03:00
|
|
|
extern json_spirit::Value newpostcustom(const json_spirit::Array& params, bool fHelp);
|
2015-04-22 12:00:51 -03:00
|
|
|
extern json_spirit::Value newpostraw(const json_spirit::Array& params, bool fHelp);
|
2013-08-20 21:08:18 -03:00
|
|
|
extern json_spirit::Value newdirectmsg(const json_spirit::Array& params, bool fHelp);
|
2013-09-18 23:09:51 -03:00
|
|
|
extern json_spirit::Value newrtmsg(const json_spirit::Array& params, bool fHelp);
|
2015-05-04 16:03:00 +03:00
|
|
|
extern json_spirit::Value newfavmsg(const json_spirit::Array& params, bool fHelp);
|
2013-09-20 18:59:31 -03:00
|
|
|
extern json_spirit::Value getposts(const json_spirit::Array& params, bool fHelp);
|
2013-10-14 18:55:56 -03:00
|
|
|
extern json_spirit::Value getdirectmsgs(const json_spirit::Array& params, bool fHelp);
|
2014-11-29 13:20:43 -02:00
|
|
|
extern json_spirit::Value getmentions(const json_spirit::Array& params, bool fHelp);
|
2015-05-04 16:03:00 +03:00
|
|
|
extern json_spirit::Value getfavs(const json_spirit::Array& params, bool fHelp);
|
2013-09-20 19:51:56 -03:00
|
|
|
extern json_spirit::Value setspammsg(const json_spirit::Array& params, bool fHelp);
|
2013-09-20 23:05:38 -03:00
|
|
|
extern json_spirit::Value getspammsg(const json_spirit::Array& params, bool fHelp);
|
2015-04-19 13:53:48 -03:00
|
|
|
extern json_spirit::Value setpreferredspamlang(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value getpreferredspamlang(const json_spirit::Array& params, bool fHelp);
|
2013-09-20 23:05:38 -03:00
|
|
|
extern json_spirit::Value follow(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value unfollow(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value getfollowing(const json_spirit::Array& params, bool fHelp);
|
2013-10-06 22:29:17 -03:00
|
|
|
extern json_spirit::Value getlasthave(const json_spirit::Array& params, bool fHelp);
|
2013-11-14 16:17:06 -02:00
|
|
|
extern json_spirit::Value getnumpieces(const json_spirit::Array& params, bool fHelp);
|
2013-09-21 17:53:55 -03:00
|
|
|
extern json_spirit::Value listusernamespartial(const json_spirit::Array& params, bool fHelp);
|
2013-10-28 22:59:43 -02:00
|
|
|
extern json_spirit::Value rescandirectmsgs(const json_spirit::Array& params, bool fHelp);
|
2013-11-23 18:25:55 -02:00
|
|
|
extern json_spirit::Value recheckusertorrent(const json_spirit::Array& params, bool fHelp);
|
2014-02-15 20:41:54 -02:00
|
|
|
extern json_spirit::Value gettrendinghashtags(const json_spirit::Array& params, bool fHelp);
|
2014-02-16 15:27:06 -03:00
|
|
|
extern json_spirit::Value getspamposts(const json_spirit::Array& params, bool fHelp);
|
2014-02-22 12:30:40 -03:00
|
|
|
extern json_spirit::Value torrentstatus(const json_spirit::Array& params, bool fHelp);
|
2014-08-27 01:03:37 +04:00
|
|
|
extern json_spirit::Value search(const json_spirit::Array& params, bool fHelp);
|
2015-04-23 19:45:13 -03:00
|
|
|
extern json_spirit::Value creategroup(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value listgroups(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value getgroupinfo(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value newgroupinvite(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value newgroupdescription(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value leavegroup(const json_spirit::Array& params, bool fHelp);
|
2015-05-30 18:21:15 -03:00
|
|
|
extern json_spirit::Value getpieceavailability(const json_spirit::Array& params, bool fHelp);
|
2015-05-30 20:49:13 -03:00
|
|
|
extern json_spirit::Value getpiecemaxseen(const json_spirit::Array& params, bool fHelp);
|
2015-12-18 21:20:50 -02:00
|
|
|
extern json_spirit::Value peekpost(const json_spirit::Array& params, bool fHelp);
|
2015-12-24 15:32:27 -02:00
|
|
|
extern json_spirit::Value uidtousername(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value usernametouid(const json_spirit::Array& params, bool fHelp);
|
2016-03-19 17:07:25 -03:00
|
|
|
extern json_spirit::Value newshorturl(const json_spirit::Array& params, bool fHelp);
|
|
|
|
extern json_spirit::Value decodeshorturl(const json_spirit::Array& params, bool fHelp);
|
2012-08-21 11:03:38 -04:00
|
|
|
|
2012-04-21 01:37:34 +02:00
|
|
|
#endif
|