1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 #ifndef BITCOIN_RPCSERVER_H
7 #define BITCOIN_RPCSERVER_H
10 #include "rpcprotocol.h"
19 #include <boost/function.hpp>
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);
41 std::string strMethod;
44 JSONRequest() { id = NullUniValue; }
45 void parse(const UniValue& valRequest);
48 /** Query whether RPC is running */
51 /** Get the async queue*/
52 std::shared_ptr<AsyncRPCQueue> getAsyncRPCQueue();
56 * Set the RPC warmup status. When this is done, all RPC calls will error out
57 * immediately with RPC_IN_WARMUP.
59 void SetRPCWarmupStatus(const std::string& newStatus);
60 /* Mark warmup as done. RPC calls will be processed from now on. */
61 void SetRPCWarmupFinished();
63 /* returns the current warmup state. */
64 bool RPCIsInWarmup(std::string *statusOut);
67 * Type-check arguments; throws JSONRPCError if wrong type given. Does not check that
68 * the right number of arguments are passed, just that any passed are the correct type.
69 * Use like: RPCTypeCheck(params, boost::assign::list_of(str_type)(int_type)(obj_type));
71 void RPCTypeCheck(const UniValue& params,
72 const std::list<UniValue::VType>& typesExpected, bool fAllowNull=false);
75 Check for expected keys/value types in an Object.
76 Use like: RPCTypeCheckObj(object, boost::assign::map_list_of("name", str_type)("value", int_type));
78 void RPCTypeCheckObj(const UniValue& o,
79 const std::map<std::string, UniValue::VType>& typesExpected, bool fAllowNull=false);
81 /** Opaque base class for timers returned by NewTimerFunc.
82 * This provides no methods at the moment, but makes sure that delete
83 * cleans up the whole state.
88 virtual ~RPCTimerBase() {}
94 class RPCTimerInterface
97 virtual ~RPCTimerInterface() {}
98 /** Implementation name */
99 virtual const char *Name() = 0;
100 /** Factory function for timers.
101 * RPC will call the function to create a timer that will call func in *millis* milliseconds.
102 * @note As the RPC mechanism is backend-neutral, it can use different implementations of timers.
103 * This is needed to cope with the case in which there is no HTTP server, but
104 * only GUI RPC console, and to break the dependency of rpcserver on httprpc.
106 virtual RPCTimerBase* NewTimer(boost::function<void(void)>& func, int64_t millis) = 0;
109 /** Register factory function for timers */
110 void RPCRegisterTimerInterface(RPCTimerInterface *iface);
111 /** Unregister factory function for timers */
112 void RPCUnregisterTimerInterface(RPCTimerInterface *iface);
115 * Run func nSeconds from now.
116 * Overrides previous timer <name> (if any).
118 void RPCRunLater(const std::string& name, boost::function<void(void)> func, int64_t nSeconds);
120 typedef UniValue(*rpcfn_type)(const UniValue& params, bool fHelp);
125 std::string category;
132 * Bitcoin RPC command dispatcher.
137 std::map<std::string, const CRPCCommand*> mapCommands;
140 const CRPCCommand* operator[](const std::string& name) const;
141 std::string help(const std::string& name) const;
145 * @param method Method to execute
146 * @param params UniValue Array of arguments (JSON objects)
147 * @returns Result of the call.
148 * @throws an exception (UniValue) when an error happens.
150 UniValue execute(const std::string &method, const UniValue ¶ms) const;
153 extern const CRPCTable tableRPC;
156 * Utilities: convert hex-encoded Values
157 * (throws error if not hex).
159 extern uint256 ParseHashV(const UniValue& v, std::string strName);
160 extern uint256 ParseHashO(const UniValue& o, std::string strKey);
161 extern std::vector<unsigned char> ParseHexV(const UniValue& v, std::string strName);
162 extern std::vector<unsigned char> ParseHexO(const UniValue& o, std::string strKey);
164 extern int64_t nWalletUnlockTime;
165 extern CAmount AmountFromValue(const UniValue& value);
166 extern UniValue ValueFromAmount(const CAmount& amount);
167 extern double GetDifficulty(const CBlockIndex* blockindex = NULL);
168 extern double GetNetworkDifficulty(const CBlockIndex* blockindex = NULL);
169 extern std::string HelpRequiringPassphrase();
170 extern std::string HelpExampleCli(const std::string& methodname, const std::string& args);
171 extern std::string HelpExampleRpc(const std::string& methodname, const std::string& args);
173 extern void EnsureWalletIsUnlocked();
175 extern UniValue getconnectioncount(const UniValue& params, bool fHelp); // in rpcnet.cpp
176 extern UniValue getaddressmempool(const UniValue& params, bool fHelp);
177 extern UniValue getaddressutxos(const UniValue& params, bool fHelp);
178 extern UniValue getaddressdeltas(const UniValue& params, bool fHelp);
179 extern UniValue getaddresstxids(const UniValue& params, bool fHelp);
180 extern UniValue getsnapshot(const UniValue& params, bool fHelp);
181 extern UniValue getaddressbalance(const UniValue& params, bool fHelp);
182 extern UniValue getpeerinfo(const UniValue& params, bool fHelp);
183 extern UniValue ping(const UniValue& params, bool fHelp);
184 extern UniValue addnode(const UniValue& params, bool fHelp);
185 extern UniValue disconnectnode(const UniValue& params, bool fHelp);
186 extern UniValue getaddednodeinfo(const UniValue& params, bool fHelp);
187 extern UniValue getnettotals(const UniValue& params, bool fHelp);
188 extern UniValue setban(const UniValue& params, bool fHelp);
189 extern UniValue listbanned(const UniValue& params, bool fHelp);
190 extern UniValue clearbanned(const UniValue& params, bool fHelp);
192 extern UniValue dumpprivkey(const UniValue& params, bool fHelp); // in rpcdump.cpp
193 extern UniValue importprivkey(const UniValue& params, bool fHelp);
194 extern UniValue importaddress(const UniValue& params, bool fHelp);
195 extern UniValue dumpwallet(const UniValue& params, bool fHelp);
196 extern UniValue importwallet(const UniValue& params, bool fHelp);
198 extern UniValue getgenerate(const UniValue& params, bool fHelp); // in rpcmining.cpp
199 extern UniValue setgenerate(const UniValue& params, bool fHelp);
200 extern UniValue generate(const UniValue& params, bool fHelp);
201 extern UniValue getlocalsolps(const UniValue& params, bool fHelp);
202 extern UniValue getnetworksolps(const UniValue& params, bool fHelp);
203 extern UniValue getnetworkhashps(const UniValue& params, bool fHelp);
204 extern UniValue getmininginfo(const UniValue& params, bool fHelp);
205 extern UniValue prioritisetransaction(const UniValue& params, bool fHelp);
206 extern UniValue getblocktemplate(const UniValue& params, bool fHelp);
207 extern UniValue submitblock(const UniValue& params, bool fHelp);
208 extern UniValue estimatefee(const UniValue& params, bool fHelp);
209 extern UniValue estimatepriority(const UniValue& params, bool fHelp);
211 extern UniValue getnewaddress(const UniValue& params, bool fHelp); // in rpcwallet.cpp
212 extern UniValue getaccountaddress(const UniValue& params, bool fHelp);
213 extern UniValue getrawchangeaddress(const UniValue& params, bool fHelp);
214 extern UniValue setaccount(const UniValue& params, bool fHelp);
215 extern UniValue getaccount(const UniValue& params, bool fHelp);
216 extern UniValue getaddressesbyaccount(const UniValue& params, bool fHelp);
217 extern UniValue sendtoaddress(const UniValue& params, bool fHelp);
218 extern UniValue signmessage(const UniValue& params, bool fHelp);
219 extern UniValue verifymessage(const UniValue& params, bool fHelp);
220 extern UniValue getreceivedbyaddress(const UniValue& params, bool fHelp);
221 extern UniValue getreceivedbyaccount(const UniValue& params, bool fHelp);
222 extern UniValue getbalance(const UniValue& params, bool fHelp);
223 extern UniValue getunconfirmedbalance(const UniValue& params, bool fHelp);
224 extern UniValue movecmd(const UniValue& params, bool fHelp);
225 extern UniValue sendfrom(const UniValue& params, bool fHelp);
226 extern UniValue sendmany(const UniValue& params, bool fHelp);
227 extern UniValue addmultisigaddress(const UniValue& params, bool fHelp);
228 extern UniValue createmultisig(const UniValue& params, bool fHelp);
229 extern UniValue listreceivedbyaddress(const UniValue& params, bool fHelp);
230 extern UniValue listreceivedbyaccount(const UniValue& params, bool fHelp);
231 extern UniValue listtransactions(const UniValue& params, bool fHelp);
232 extern UniValue listaddressgroupings(const UniValue& params, bool fHelp);
233 extern UniValue listaccounts(const UniValue& params, bool fHelp);
234 extern UniValue listsinceblock(const UniValue& params, bool fHelp);
235 extern UniValue gettransaction(const UniValue& params, bool fHelp);
236 extern UniValue backupwallet(const UniValue& params, bool fHelp);
237 extern UniValue keypoolrefill(const UniValue& params, bool fHelp);
238 extern UniValue walletpassphrase(const UniValue& params, bool fHelp);
239 extern UniValue walletpassphrasechange(const UniValue& params, bool fHelp);
240 extern UniValue walletlock(const UniValue& params, bool fHelp);
241 extern UniValue encryptwallet(const UniValue& params, bool fHelp);
242 extern UniValue validateaddress(const UniValue& params, bool fHelp);
243 extern UniValue getinfo(const UniValue& params, bool fHelp);
244 extern UniValue getwalletinfo(const UniValue& params, bool fHelp);
245 extern UniValue getblockchaininfo(const UniValue& params, bool fHelp);
246 extern UniValue getnetworkinfo(const UniValue& params, bool fHelp);
247 extern UniValue getdeprecationinfo(const UniValue& params, bool fHelp);
248 extern UniValue setmocktime(const UniValue& params, bool fHelp);
249 extern UniValue resendwallettransactions(const UniValue& params, bool fHelp);
250 extern UniValue zc_benchmark(const UniValue& params, bool fHelp);
251 extern UniValue zc_raw_keygen(const UniValue& params, bool fHelp);
252 extern UniValue zc_raw_joinsplit(const UniValue& params, bool fHelp);
253 extern UniValue zc_raw_receive(const UniValue& params, bool fHelp);
254 extern UniValue zc_sample_joinsplit(const UniValue& params, bool fHelp);
256 extern UniValue jumblr_deposit(const UniValue& params, bool fHelp);
257 extern UniValue jumblr_secret(const UniValue& params, bool fHelp);
258 extern UniValue jumblr_pause(const UniValue& params, bool fHelp);
259 extern UniValue jumblr_resume(const UniValue& params, bool fHelp);
261 extern UniValue getrawtransaction(const UniValue& params, bool fHelp); // in rcprawtransaction.cpp
262 extern UniValue listunspent(const UniValue& params, bool fHelp);
263 extern UniValue lockunspent(const UniValue& params, bool fHelp);
264 extern UniValue listlockunspent(const UniValue& params, bool fHelp);
265 extern UniValue createrawtransaction(const UniValue& params, bool fHelp);
266 extern UniValue decoderawtransaction(const UniValue& params, bool fHelp);
267 extern UniValue decodescript(const UniValue& params, bool fHelp);
268 extern UniValue fundrawtransaction(const UniValue& params, bool fHelp);
269 extern UniValue signrawtransaction(const UniValue& params, bool fHelp);
270 extern UniValue sendrawtransaction(const UniValue& params, bool fHelp);
271 extern UniValue gettxoutproof(const UniValue& params, bool fHelp);
272 extern UniValue verifytxoutproof(const UniValue& params, bool fHelp);
274 extern UniValue getblockcount(const UniValue& params, bool fHelp); // in rpcblockchain.cpp
275 extern UniValue getbestblockhash(const UniValue& params, bool fHelp);
276 extern UniValue getdifficulty(const UniValue& params, bool fHelp);
277 extern UniValue settxfee(const UniValue& params, bool fHelp);
278 extern UniValue getmempoolinfo(const UniValue& params, bool fHelp);
279 extern UniValue getrawmempool(const UniValue& params, bool fHelp);
280 extern UniValue getblockhashes(const UniValue& params, bool fHelp);
281 extern UniValue getblockdeltas(const UniValue& params, bool fHelp);
282 extern UniValue getblockhash(const UniValue& params, bool fHelp);
283 extern UniValue getblockheader(const UniValue& params, bool fHelp);
284 extern UniValue getblock(const UniValue& params, bool fHelp);
285 extern UniValue gettxoutsetinfo(const UniValue& params, bool fHelp);
286 extern UniValue gettxout(const UniValue& params, bool fHelp);
287 extern UniValue verifychain(const UniValue& params, bool fHelp);
288 extern UniValue getchaintips(const UniValue& params, bool fHelp);
289 extern UniValue invalidateblock(const UniValue& params, bool fHelp);
290 extern UniValue reconsiderblock(const UniValue& params, bool fHelp);
291 extern UniValue getspentinfo(const UniValue& params, bool fHelp);
293 extern UniValue getblocksubsidy(const UniValue& params, bool fHelp);
295 extern UniValue z_exportkey(const UniValue& params, bool fHelp); // in rpcdump.cpp
296 extern UniValue z_importkey(const UniValue& params, bool fHelp); // in rpcdump.cpp
297 extern UniValue z_exportviewingkey(const UniValue& params, bool fHelp); // in rpcdump.cpp
298 extern UniValue z_importviewingkey(const UniValue& params, bool fHelp); // in rpcdump.cpp
299 extern UniValue z_getnewaddress(const UniValue& params, bool fHelp); // in rpcwallet.cpp
300 extern UniValue z_listaddresses(const UniValue& params, bool fHelp); // in rpcwallet.cpp
301 extern UniValue z_exportwallet(const UniValue& params, bool fHelp); // in rpcdump.cpp
302 extern UniValue z_importwallet(const UniValue& params, bool fHelp); // in rpcdump.cpp
303 extern UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp); // in rpcwallet.cpp
304 extern UniValue z_getbalance(const UniValue& params, bool fHelp); // in rpcwallet.cpp
305 extern UniValue z_gettotalbalance(const UniValue& params, bool fHelp); // in rpcwallet.cpp
306 extern UniValue z_mergetoaddress(const UniValue& params, bool fHelp); // in rpcwallet.cpp
307 extern UniValue z_sendmany(const UniValue& params, bool fHelp); // in rpcwallet.cpp
308 extern UniValue z_shieldcoinbase(const UniValue& params, bool fHelp); // in rpcwallet.cpp
309 extern UniValue z_getoperationstatus(const UniValue& params, bool fHelp); // in rpcwallet.cpp
310 extern UniValue z_getoperationresult(const UniValue& params, bool fHelp); // in rpcwallet.cpp
311 extern UniValue z_listoperationids(const UniValue& params, bool fHelp); // in rpcwallet.cpp
312 extern UniValue z_validateaddress(const UniValue& params, bool fHelp); // in rpcmisc.cpp
313 extern UniValue z_getpaymentdisclosure(const UniValue& params, bool fHelp); // in rpcdisclosure.cpp
314 extern UniValue z_validatepaymentdisclosure(const UniValue ¶ms, bool fHelp); // in rpcdisclosure.cpp
316 extern UniValue allMoMs(const UniValue& params, bool fHelp);
317 extern UniValue MoMoMdata(const UniValue& params, bool fHelp);
318 extern UniValue calc_MoM(const UniValue& params, bool fHelp);
319 extern UniValue height_MoM(const UniValue& params, bool fHelp);
320 extern UniValue txMoMproof(const UniValue& params, bool fHelp);
321 extern UniValue notaries(const UniValue& params, bool fHelp);
322 extern UniValue minerids(const UniValue& params, bool fHelp);
323 extern UniValue kvsearch(const UniValue& params, bool fHelp);
324 extern UniValue kvupdate(const UniValue& params, bool fHelp);
325 extern UniValue paxprice(const UniValue& params, bool fHelp);
326 extern UniValue paxpending(const UniValue& params, bool fHelp);
327 extern UniValue paxprices(const UniValue& params, bool fHelp);
328 extern UniValue paxdeposit(const UniValue& params, bool fHelp);
329 extern UniValue paxwithdraw(const UniValue& params, bool fHelp);
334 std::string JSONRPCExecBatch(const UniValue& vReq);
336 #endif // BITCOIN_RPCSERVER_H