]> Git Repo - VerusCoin.git/blame - src/rpcserver.h
test
[VerusCoin.git] / src / rpcserver.h
CommitLineData
8bd66202 1// Copyright (c) 2010 Satoshi Nakamoto
f914f1a7 2// Copyright (c) 2009-2014 The Bitcoin Core developers
77920402 3// Distributed under the MIT software license, see the accompanying
3a25a2b9 4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
8bd66202 5
84738627
PJ
6#ifndef BITCOIN_RPCSERVER_H
7#define BITCOIN_RPCSERVER_H
e46704dd 8
a372168e 9#include "amount.h"
fb78cc23 10#include "rpcprotocol.h"
771d5002 11#include "uint256.h"
51ed9ec9 12
899d373b 13#include <list>
e46704dd 14#include <map>
51ed9ec9
BD
15#include <stdint.h>
16#include <string>
fc72c078 17#include <memory>
c625ae04 18
e46704dd 19#include "json/json_spirit_reader_template.h"
e46704dd 20#include "json/json_spirit_utils.h"
51ed9ec9 21#include "json/json_spirit_writer_template.h"
e46704dd 22
fc72c078 23class AsyncRPCQueue;
4401b2d7
EL
24class CRPCCommand;
25
26namespace RPCServer
27{
28 void OnStarted(boost::function<void ()> slot);
29 void OnStopped(boost::function<void ()> slot);
30 void OnPreCommand(boost::function<void (const CRPCCommand&)> slot);
31 void OnPostCommand(boost::function<void (const CRPCCommand&)> slot);
32}
33
51ed9ec9 34class CBlockIndex;
21bf3d25 35class CNetAddr;
480d44bd 36
ed5769f5
JG
37class AcceptedConnection
38{
39public:
40 virtual ~AcceptedConnection() {}
41
42 virtual std::iostream& stream() = 0;
43 virtual std::string peer_address_to_string() const = 0;
44 virtual void close() = 0;
45};
46
77920402 47/** Start RPC threads */
21eb5ada 48void StartRPCThreads();
77920402
MF
49/**
50 * Alternative to StartRPCThreads for the GUI, when no server is
a8db31c8
WL
51 * used. The RPC thread in this case is only used to handle timeouts.
52 * If real RPC threads have already been started this is a no-op.
53 */
54void StartDummyRPCThread();
72fb3d29 55/** Stop RPC threads */
21eb5ada 56void StopRPCThreads();
72fb3d29 57/** Query whether RPC is running */
ff6a7af1 58bool IsRPCRunning();
460c51fd 59
fc72c078
S
60/** Get the async queue*/
61std::shared_ptr<AsyncRPCQueue> getAsyncRPCQueue();
62
63
72fb3d29
MF
64/**
65 * Set the RPC warmup status. When this is done, all RPC calls will error out
af82884a
DK
66 * immediately with RPC_IN_WARMUP.
67 */
68void SetRPCWarmupStatus(const std::string& newStatus);
69/* Mark warmup as done. RPC calls will be processed from now on. */
70void SetRPCWarmupFinished();
71
78bdc810
JS
72/* returns the current warmup state. */
73bool RPCIsInWarmup(std::string *statusOut);
74
77920402
MF
75/**
76 * Type-check arguments; throws JSONRPCError if wrong type given. Does not check that
77 * the right number of arguments are passed, just that any passed are the correct type.
78 * Use like: RPCTypeCheck(params, boost::assign::list_of(str_type)(int_type)(obj_type));
79 */
899d373b 80void RPCTypeCheck(const json_spirit::Array& params,
cc6dfd1f 81 const std::list<json_spirit::Value_type>& typesExpected, bool fAllowNull=false);
77920402
MF
82/**
83 * Check for expected keys/value types in an Object.
84 * Use like: RPCTypeCheck(object, boost::assign::map_list_of("name", str_type)("value", int_type));
85 */
899d373b 86void RPCTypeCheck(const json_spirit::Object& o,
cc6dfd1f 87 const std::map<std::string, json_spirit::Value_type>& typesExpected, bool fAllowNull=false);
899d373b 88
77920402
MF
89/**
90 * Run func nSeconds from now. Uses boost deadline timers.
91 * Overrides previous timer <name> (if any).
92f2c1fe 92 */
51ed9ec9 93void RPCRunLater(const std::string& name, boost::function<void(void)> func, int64_t nSeconds);
92f2c1fe 94
21bf3d25
WL
95//! Convert boost::asio address to CNetAddr
96extern CNetAddr BoostAsioToCNetAddr(boost::asio::ip::address address);
97
e46704dd
PW
98typedef json_spirit::Value(*rpcfn_type)(const json_spirit::Array& params, bool fHelp);
99
100class CRPCCommand
101{
102public:
6b5b7cbf 103 std::string category;
e46704dd
PW
104 std::string name;
105 rpcfn_type actor;
106 bool okSafeMode;
107};
108
460c51fd
WL
109/**
110 * Bitcoin RPC command dispatcher.
111 */
e46704dd
PW
112class CRPCTable
113{
114private:
115 std::map<std::string, const CRPCCommand*> mapCommands;
116public:
117 CRPCTable();
118 const CRPCCommand* operator[](std::string name) const;
119 std::string help(std::string name) const;
460c51fd
WL
120
121 /**
122 * Execute a method.
123 * @param method Method to execute
124 * @param params Array of arguments (JSON objects)
125 * @returns Result of the call.
126 * @throws an exception (json_spirit::Value) when an error happens.
127 */
128 json_spirit::Value execute(const std::string &method, const json_spirit::Array &params) const;
e46704dd
PW
129};
130
131extern const CRPCTable tableRPC;
d98bf10f 132
77920402
MF
133/**
134 * Utilities: convert hex-encoded Values
135 * (throws error if not hex).
136 */
463c9710
PT
137extern uint256 ParseHashV(const json_spirit::Value& v, std::string strName);
138extern uint256 ParseHashO(const json_spirit::Object& o, std::string strKey);
139extern std::vector<unsigned char> ParseHexV(const json_spirit::Value& v, std::string strName);
140extern std::vector<unsigned char> ParseHexO(const json_spirit::Object& o, std::string strKey);
141
d98bf10f
WL
142extern void InitRPCMining();
143extern void ShutdownRPCMining();
e46704dd 144
51ed9ec9 145extern int64_t nWalletUnlockTime;
a372168e
MF
146extern CAmount AmountFromValue(const json_spirit::Value& value);
147extern json_spirit::Value ValueFromAmount(const CAmount& amount);
c625ae04 148extern double GetDifficulty(const CBlockIndex* blockindex = NULL);
695a7a88 149extern double GetNetworkDifficulty(const CBlockIndex* blockindex = NULL);
c625ae04 150extern std::string HelpRequiringPassphrase();
a6099ef3 151extern std::string HelpExampleCli(std::string methodname, std::string args);
152extern std::string HelpExampleRpc(std::string methodname, std::string args);
153
c625ae04 154extern void EnsureWalletIsUnlocked();
e3bc5698
JG
155
156extern json_spirit::Value getconnectioncount(const json_spirit::Array& params, bool fHelp); // in rpcnet.cpp
157extern json_spirit::Value getpeerinfo(const json_spirit::Array& params, bool fHelp);
971bb3e9 158extern json_spirit::Value ping(const json_spirit::Array& params, bool fHelp);
72a348fd 159extern json_spirit::Value addnode(const json_spirit::Array& params, bool fHelp);
67a11bd6 160extern json_spirit::Value getaddednodeinfo(const json_spirit::Array& params, bool fHelp);
ce14345a 161extern json_spirit::Value getnettotals(const json_spirit::Array& params, bool fHelp);
4e534aa9 162
e3bc5698
JG
163extern json_spirit::Value dumpprivkey(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp
164extern json_spirit::Value importprivkey(const json_spirit::Array& params, bool fHelp);
c8988460 165extern json_spirit::Value importaddress(const json_spirit::Array& params, bool fHelp);
4e534aa9
PW
166extern json_spirit::Value dumpwallet(const json_spirit::Array& params, bool fHelp);
167extern json_spirit::Value importwallet(const json_spirit::Array& params, bool fHelp);
e3bc5698
JG
168
169extern json_spirit::Value getgenerate(const json_spirit::Array& params, bool fHelp); // in rpcmining.cpp
170extern json_spirit::Value setgenerate(const json_spirit::Array& params, bool fHelp);
6b04508e 171extern json_spirit::Value generate(const json_spirit::Array& params, bool fHelp);
d64eef48 172extern json_spirit::Value getnetworkhashps(const json_spirit::Array& params, bool fHelp);
e3bc5698 173extern json_spirit::Value getmininginfo(const json_spirit::Array& params, bool fHelp);
2a72d459 174extern json_spirit::Value prioritisetransaction(const json_spirit::Array& params, bool fHelp);
e3bc5698
JG
175extern json_spirit::Value getblocktemplate(const json_spirit::Array& params, bool fHelp);
176extern json_spirit::Value submitblock(const json_spirit::Array& params, bool fHelp);
171ca774
GA
177extern json_spirit::Value estimatefee(const json_spirit::Array& params, bool fHelp);
178extern json_spirit::Value estimatepriority(const json_spirit::Array& params, bool fHelp);
e3bc5698
JG
179
180extern json_spirit::Value getnewaddress(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp
181extern json_spirit::Value getaccountaddress(const json_spirit::Array& params, bool fHelp);
e5e9904c 182extern json_spirit::Value getrawchangeaddress(const json_spirit::Array& params, bool fHelp);
e3bc5698
JG
183extern json_spirit::Value setaccount(const json_spirit::Array& params, bool fHelp);
184extern json_spirit::Value getaccount(const json_spirit::Array& params, bool fHelp);
185extern json_spirit::Value getaddressesbyaccount(const json_spirit::Array& params, bool fHelp);
186extern json_spirit::Value sendtoaddress(const json_spirit::Array& params, bool fHelp);
187extern json_spirit::Value signmessage(const json_spirit::Array& params, bool fHelp);
188extern json_spirit::Value verifymessage(const json_spirit::Array& params, bool fHelp);
189extern json_spirit::Value getreceivedbyaddress(const json_spirit::Array& params, bool fHelp);
190extern json_spirit::Value getreceivedbyaccount(const json_spirit::Array& params, bool fHelp);
191extern json_spirit::Value getbalance(const json_spirit::Array& params, bool fHelp);
6027b460 192extern json_spirit::Value getunconfirmedbalance(const json_spirit::Array& params, bool fHelp);
e3bc5698
JG
193extern json_spirit::Value movecmd(const json_spirit::Array& params, bool fHelp);
194extern json_spirit::Value sendfrom(const json_spirit::Array& params, bool fHelp);
195extern json_spirit::Value sendmany(const json_spirit::Array& params, bool fHelp);
196extern json_spirit::Value addmultisigaddress(const json_spirit::Array& params, bool fHelp);
34226be7 197extern json_spirit::Value createmultisig(const json_spirit::Array& params, bool fHelp);
e3bc5698
JG
198extern json_spirit::Value listreceivedbyaddress(const json_spirit::Array& params, bool fHelp);
199extern json_spirit::Value listreceivedbyaccount(const json_spirit::Array& params, bool fHelp);
200extern json_spirit::Value listtransactions(const json_spirit::Array& params, bool fHelp);
22dfd735 201extern json_spirit::Value listaddressgroupings(const json_spirit::Array& params, bool fHelp);
e3bc5698
JG
202extern json_spirit::Value listaccounts(const json_spirit::Array& params, bool fHelp);
203extern json_spirit::Value listsinceblock(const json_spirit::Array& params, bool fHelp);
204extern json_spirit::Value gettransaction(const json_spirit::Array& params, bool fHelp);
205extern json_spirit::Value backupwallet(const json_spirit::Array& params, bool fHelp);
206extern json_spirit::Value keypoolrefill(const json_spirit::Array& params, bool fHelp);
207extern json_spirit::Value walletpassphrase(const json_spirit::Array& params, bool fHelp);
208extern json_spirit::Value walletpassphrasechange(const json_spirit::Array& params, bool fHelp);
209extern json_spirit::Value walletlock(const json_spirit::Array& params, bool fHelp);
210extern json_spirit::Value encryptwallet(const json_spirit::Array& params, bool fHelp);
211extern json_spirit::Value validateaddress(const json_spirit::Array& params, bool fHelp);
c625ae04 212extern json_spirit::Value getinfo(const json_spirit::Array& params, bool fHelp);
a00ebb51 213extern json_spirit::Value getwalletinfo(const json_spirit::Array& params, bool fHelp);
d387b8ec
WL
214extern json_spirit::Value getblockchaininfo(const json_spirit::Array& params, bool fHelp);
215extern json_spirit::Value getnetworkinfo(const json_spirit::Array& params, bool fHelp);
a8b2ce55 216extern json_spirit::Value setmocktime(const json_spirit::Array& params, bool fHelp);
0f5954c4 217extern json_spirit::Value resendwallettransactions(const json_spirit::Array& params, bool fHelp);
6962bb3d 218extern json_spirit::Value zc_benchmark(const json_spirit::Array& params, bool fHelp);
730790f7 219extern json_spirit::Value zc_raw_keygen(const json_spirit::Array& params, bool fHelp);
b7e4abd6 220extern json_spirit::Value zc_raw_joinsplit(const json_spirit::Array& params, bool fHelp);
a8ac403d 221extern json_spirit::Value zc_raw_receive(const json_spirit::Array& params, bool fHelp);
1737627c 222extern json_spirit::Value zc_sample_joinsplit(const json_spirit::Array& params, bool fHelp);
e3bc5698
JG
223
224extern json_spirit::Value getrawtransaction(const json_spirit::Array& params, bool fHelp); // in rcprawtransaction.cpp
225extern json_spirit::Value listunspent(const json_spirit::Array& params, bool fHelp);
fdbb537d
JG
226extern json_spirit::Value lockunspent(const json_spirit::Array& params, bool fHelp);
227extern json_spirit::Value listlockunspent(const json_spirit::Array& params, bool fHelp);
e3bc5698
JG
228extern json_spirit::Value createrawtransaction(const json_spirit::Array& params, bool fHelp);
229extern json_spirit::Value decoderawtransaction(const json_spirit::Array& params, bool fHelp);
be066fad 230extern json_spirit::Value decodescript(const json_spirit::Array& params, bool fHelp);
e3bc5698
JG
231extern json_spirit::Value signrawtransaction(const json_spirit::Array& params, bool fHelp);
232extern json_spirit::Value sendrawtransaction(const json_spirit::Array& params, bool fHelp);
59ed61b3
MC
233extern json_spirit::Value gettxoutproof(const json_spirit::Array& params, bool fHelp);
234extern json_spirit::Value verifytxoutproof(const json_spirit::Array& params, bool fHelp);
e3bc5698 235
c625ae04 236extern json_spirit::Value getblockcount(const json_spirit::Array& params, bool fHelp); // in rpcblockchain.cpp
091aa8da 237extern json_spirit::Value getbestblockhash(const json_spirit::Array& params, bool fHelp);
c625ae04
JG
238extern json_spirit::Value getdifficulty(const json_spirit::Array& params, bool fHelp);
239extern json_spirit::Value settxfee(const json_spirit::Array& params, bool fHelp);
6f2c26a4 240extern json_spirit::Value getmempoolinfo(const json_spirit::Array& params, bool fHelp);
c625ae04
JG
241extern json_spirit::Value getrawmempool(const json_spirit::Array& params, bool fHelp);
242extern json_spirit::Value getblockhash(const json_spirit::Array& params, bool fHelp);
243extern json_spirit::Value getblock(const json_spirit::Array& params, bool fHelp);
beeb5761
PW
244extern json_spirit::Value gettxoutsetinfo(const json_spirit::Array& params, bool fHelp);
245extern json_spirit::Value gettxout(const json_spirit::Array& params, bool fHelp);
a9869d0d 246extern json_spirit::Value paxprice(const json_spirit::Array& params, bool fHelp);
83a7f513 247extern json_spirit::Value paxprices(const json_spirit::Array& params, bool fHelp);
d7d27bb3 248extern json_spirit::Value paxdeposit(const json_spirit::Array& params, bool fHelp);
f5906533 249extern json_spirit::Value verifychain(const json_spirit::Array& params, bool fHelp);
b33bd7a3 250extern json_spirit::Value getchaintips(const json_spirit::Array& params, bool fHelp);
9b0a8d31
PW
251extern json_spirit::Value invalidateblock(const json_spirit::Array& params, bool fHelp);
252extern json_spirit::Value reconsiderblock(const json_spirit::Array& params, bool fHelp);
c625ae04 253
1b114e54
S
254extern json_spirit::Value getblocksubsidy(const json_spirit::Array& params, bool fHelp);
255
c1c45943
S
256extern json_spirit::Value z_exportkey(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp
257extern json_spirit::Value z_importkey(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp
258extern json_spirit::Value z_getnewaddress(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp
e709997f 259extern json_spirit::Value z_listaddresses(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp
92444edc
S
260extern json_spirit::Value z_exportwallet(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp
261extern json_spirit::Value z_importwallet(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp
6c41028f 262extern json_spirit::Value z_listreceivedbyaddress(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp
a0a3334c
S
263extern json_spirit::Value z_getbalance(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp
264extern json_spirit::Value z_gettotalbalance(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp
fc72c078
S
265extern json_spirit::Value z_sendmany(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp
266extern json_spirit::Value z_getoperationstatus(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp
c1eae280 267extern json_spirit::Value z_getoperationresult(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp
34f0001c 268extern json_spirit::Value z_listoperationids(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp
fc72c078 269
c1c45943 270
e2655e0a
JG
271// in rest.cpp
272extern bool HTTPReq_REST(AcceptedConnection *conn,
7c8e4c5c 273 const std::string& strURI,
97ee8665 274 const std::string& strRequest,
7c8e4c5c 275 const std::map<std::string, std::string>& mapHeaders,
e2655e0a
JG
276 bool fRun);
277
84738627 278#endif // BITCOIN_RPCSERVER_H
This page took 0.269738 seconds and 4 git commands to generate.