]> Git Repo - VerusCoin.git/blob - src/rpcserver.h
Rpc and tx create
[VerusCoin.git] / src / rpcserver.h
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.
5
6 #ifndef BITCOIN_RPCSERVER_H
7 #define BITCOIN_RPCSERVER_H
8
9 #include "amount.h"
10 #include "rpcprotocol.h"
11 #include "uint256.h"
12
13 #include <list>
14 #include <map>
15 #include <stdint.h>
16 #include <string>
17 #include <memory>
18
19 #include <boost/function.hpp>
20
21 #include <univalue.h>
22
23 class AsyncRPCQueue;
24 class CRPCCommand;
25
26 namespace 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
34 class CBlockIndex;
35 class CNetAddr;
36
37 class JSONRequest
38 {
39 public:
40     UniValue id;
41     std::string strMethod;
42     UniValue params;
43
44     JSONRequest() { id = NullUniValue; }
45     void parse(const UniValue& valRequest);
46 };
47
48 /** Query whether RPC is running */
49 bool IsRPCRunning();
50
51 /** Get the async queue*/
52 std::shared_ptr<AsyncRPCQueue> getAsyncRPCQueue();
53
54
55 /**
56  * Set the RPC warmup status.  When this is done, all RPC calls will error out
57  * immediately with RPC_IN_WARMUP.
58  */
59 void SetRPCWarmupStatus(const std::string& newStatus);
60 /* Mark warmup as done.  RPC calls will be processed from now on.  */
61 void SetRPCWarmupFinished();
62
63 /* returns the current warmup state.  */
64 bool RPCIsInWarmup(std::string *statusOut);
65
66 /**
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));
70  */
71 void RPCTypeCheck(const UniValue& params,
72                   const std::list<UniValue::VType>& typesExpected, bool fAllowNull=false);
73
74 /*
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));
77 */
78 void RPCTypeCheckObj(const UniValue& o,
79                   const std::map<std::string, UniValue::VType>& typesExpected, bool fAllowNull=false);
80
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.
84  */
85 class RPCTimerBase
86 {
87 public:
88     virtual ~RPCTimerBase() {}
89 };
90
91 /**
92  * RPC timer "driver".
93  */
94 class RPCTimerInterface
95 {
96 public:
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.
105      */
106     virtual RPCTimerBase* NewTimer(boost::function<void(void)>& func, int64_t millis) = 0;
107 };
108
109 /** Register factory function for timers */
110 void RPCRegisterTimerInterface(RPCTimerInterface *iface);
111 /** Unregister factory function for timers */
112 void RPCUnregisterTimerInterface(RPCTimerInterface *iface);
113
114 /**
115  * Run func nSeconds from now.
116  * Overrides previous timer <name> (if any).
117  */
118 void RPCRunLater(const std::string& name, boost::function<void(void)> func, int64_t nSeconds);
119
120 typedef UniValue(*rpcfn_type)(const UniValue& params, bool fHelp);
121
122 class CRPCCommand
123 {
124 public:
125     std::string category;
126     std::string name;
127     rpcfn_type actor;
128     bool okSafeMode;
129 };
130
131 /**
132  * Bitcoin RPC command dispatcher.
133  */
134 class CRPCTable
135 {
136 private:
137     std::map<std::string, const CRPCCommand*> mapCommands;
138 public:
139     CRPCTable();
140     const CRPCCommand* operator[](const std::string& name) const;
141     std::string help(const std::string& name) const;
142
143     /**
144      * Execute a method.
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.
149      */
150     UniValue execute(const std::string &method, const UniValue &params) const;
151 };
152
153 extern const CRPCTable tableRPC;
154
155 /**
156  * Utilities: convert hex-encoded Values
157  * (throws error if not hex).
158  */
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);
163
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);
172
173 extern void EnsureWalletIsUnlocked();
174
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);
191
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);
197
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);
210 extern UniValue coinsupply(const UniValue& params, bool fHelp);
211 extern UniValue tokencreate(const UniValue& params, bool fHelp);
212 extern UniValue tokentransfer(const UniValue& params, bool fHelp);
213 extern UniValue tokenbid(const UniValue& params, bool fHelp);
214 extern UniValue tokencancelbid(const UniValue& params, bool fHelp);
215 extern UniValue tokenfillbid(const UniValue& params, bool fHelp);
216
217 extern UniValue getnewaddress(const UniValue& params, bool fHelp); // in rpcwallet.cpp
218 //extern UniValue getnewaddress64(const UniValue& params, bool fHelp); // in rpcwallet.cpp
219 extern UniValue getaccountaddress(const UniValue& params, bool fHelp);
220 extern UniValue getrawchangeaddress(const UniValue& params, bool fHelp);
221 extern UniValue setaccount(const UniValue& params, bool fHelp);
222 extern UniValue getaccount(const UniValue& params, bool fHelp);
223 extern UniValue getaddressesbyaccount(const UniValue& params, bool fHelp);
224 extern UniValue sendtoaddress(const UniValue& params, bool fHelp);
225 extern UniValue signmessage(const UniValue& params, bool fHelp);
226 extern UniValue verifymessage(const UniValue& params, bool fHelp);
227 extern UniValue getreceivedbyaddress(const UniValue& params, bool fHelp);
228 extern UniValue getreceivedbyaccount(const UniValue& params, bool fHelp);
229 extern UniValue getbalance(const UniValue& params, bool fHelp);
230 extern UniValue getbalance64(const UniValue& params, bool fHelp);
231 extern UniValue getunconfirmedbalance(const UniValue& params, bool fHelp);
232 extern UniValue movecmd(const UniValue& params, bool fHelp);
233 extern UniValue sendfrom(const UniValue& params, bool fHelp);
234 extern UniValue sendmany(const UniValue& params, bool fHelp);
235 extern UniValue addmultisigaddress(const UniValue& params, bool fHelp);
236 extern UniValue createmultisig(const UniValue& params, bool fHelp);
237 extern UniValue listreceivedbyaddress(const UniValue& params, bool fHelp);
238 extern UniValue listreceivedbyaccount(const UniValue& params, bool fHelp);
239 extern UniValue listtransactions(const UniValue& params, bool fHelp);
240 extern UniValue listaddressgroupings(const UniValue& params, bool fHelp);
241 extern UniValue listaccounts(const UniValue& params, bool fHelp);
242 extern UniValue listsinceblock(const UniValue& params, bool fHelp);
243 extern UniValue gettransaction(const UniValue& params, bool fHelp);
244 extern UniValue backupwallet(const UniValue& params, bool fHelp);
245 extern UniValue keypoolrefill(const UniValue& params, bool fHelp);
246 extern UniValue walletpassphrase(const UniValue& params, bool fHelp);
247 extern UniValue walletpassphrasechange(const UniValue& params, bool fHelp);
248 extern UniValue walletlock(const UniValue& params, bool fHelp);
249 extern UniValue encryptwallet(const UniValue& params, bool fHelp);
250 extern UniValue validateaddress(const UniValue& params, bool fHelp);
251 extern UniValue getinfo(const UniValue& params, bool fHelp);
252 extern UniValue getwalletinfo(const UniValue& params, bool fHelp);
253 extern UniValue getblockchaininfo(const UniValue& params, bool fHelp);
254 extern UniValue getnetworkinfo(const UniValue& params, bool fHelp);
255 extern UniValue getdeprecationinfo(const UniValue& params, bool fHelp);
256 extern UniValue setmocktime(const UniValue& params, bool fHelp);
257 extern UniValue resendwallettransactions(const UniValue& params, bool fHelp);
258 extern UniValue zc_benchmark(const UniValue& params, bool fHelp);
259 extern UniValue zc_raw_keygen(const UniValue& params, bool fHelp);
260 extern UniValue zc_raw_joinsplit(const UniValue& params, bool fHelp);
261 extern UniValue zc_raw_receive(const UniValue& params, bool fHelp);
262 extern UniValue zc_sample_joinsplit(const UniValue& params, bool fHelp);
263
264 extern UniValue jumblr_deposit(const UniValue& params, bool fHelp);
265 extern UniValue jumblr_secret(const UniValue& params, bool fHelp);
266 extern UniValue jumblr_pause(const UniValue& params, bool fHelp);
267 extern UniValue jumblr_resume(const UniValue& params, bool fHelp);
268
269 extern UniValue getrawtransaction(const UniValue& params, bool fHelp); // in rcprawtransaction.cpp
270 extern UniValue listunspent(const UniValue& params, bool fHelp);
271 extern UniValue lockunspent(const UniValue& params, bool fHelp);
272 extern UniValue listlockunspent(const UniValue& params, bool fHelp);
273 extern UniValue createrawtransaction(const UniValue& params, bool fHelp);
274 extern UniValue decoderawtransaction(const UniValue& params, bool fHelp);
275 extern UniValue decodescript(const UniValue& params, bool fHelp);
276 extern UniValue fundrawtransaction(const UniValue& params, bool fHelp);
277 extern UniValue signrawtransaction(const UniValue& params, bool fHelp);
278 extern UniValue sendrawtransaction(const UniValue& params, bool fHelp);
279 extern UniValue gettxoutproof(const UniValue& params, bool fHelp);
280 extern UniValue verifytxoutproof(const UniValue& params, bool fHelp);
281
282 extern UniValue getblockcount(const UniValue& params, bool fHelp); // in rpcblockchain.cpp
283 extern UniValue getbestblockhash(const UniValue& params, bool fHelp);
284 extern UniValue getdifficulty(const UniValue& params, bool fHelp);
285 extern UniValue settxfee(const UniValue& params, bool fHelp);
286 extern UniValue getmempoolinfo(const UniValue& params, bool fHelp);
287 extern UniValue getrawmempool(const UniValue& params, bool fHelp);
288 extern UniValue getblockhashes(const UniValue& params, bool fHelp);
289 extern UniValue getblockdeltas(const UniValue& params, bool fHelp);
290 extern UniValue getblockhash(const UniValue& params, bool fHelp);
291 extern UniValue getblockheader(const UniValue& params, bool fHelp);
292 extern UniValue getblock(const UniValue& params, bool fHelp);
293 extern UniValue gettxoutsetinfo(const UniValue& params, bool fHelp);
294 extern UniValue gettxout(const UniValue& params, bool fHelp);
295 extern UniValue verifychain(const UniValue& params, bool fHelp);
296 extern UniValue getchaintips(const UniValue& params, bool fHelp);
297 extern UniValue invalidateblock(const UniValue& params, bool fHelp);
298 extern UniValue reconsiderblock(const UniValue& params, bool fHelp);
299 extern UniValue getspentinfo(const UniValue& params, bool fHelp);
300
301 extern UniValue getblocksubsidy(const UniValue& params, bool fHelp);
302
303 extern UniValue z_exportkey(const UniValue& params, bool fHelp); // in rpcdump.cpp
304 extern UniValue z_importkey(const UniValue& params, bool fHelp); // in rpcdump.cpp
305 extern UniValue z_exportviewingkey(const UniValue& params, bool fHelp); // in rpcdump.cpp
306 extern UniValue z_importviewingkey(const UniValue& params, bool fHelp); // in rpcdump.cpp
307 extern UniValue z_getnewaddress(const UniValue& params, bool fHelp); // in rpcwallet.cpp
308 extern UniValue z_listaddresses(const UniValue& params, bool fHelp); // in rpcwallet.cpp
309 extern UniValue z_exportwallet(const UniValue& params, bool fHelp); // in rpcdump.cpp
310 extern UniValue z_importwallet(const UniValue& params, bool fHelp); // in rpcdump.cpp
311 extern UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp); // in rpcwallet.cpp
312 extern UniValue z_getbalance(const UniValue& params, bool fHelp); // in rpcwallet.cpp
313 extern UniValue z_gettotalbalance(const UniValue& params, bool fHelp); // in rpcwallet.cpp
314 extern UniValue z_mergetoaddress(const UniValue& params, bool fHelp); // in rpcwallet.cpp
315 extern UniValue z_sendmany(const UniValue& params, bool fHelp); // in rpcwallet.cpp
316 extern UniValue z_shieldcoinbase(const UniValue& params, bool fHelp); // in rpcwallet.cpp
317 extern UniValue z_getoperationstatus(const UniValue& params, bool fHelp); // in rpcwallet.cpp
318 extern UniValue z_getoperationresult(const UniValue& params, bool fHelp); // in rpcwallet.cpp
319 extern UniValue z_listoperationids(const UniValue& params, bool fHelp); // in rpcwallet.cpp
320 extern UniValue z_validateaddress(const UniValue& params, bool fHelp); // in rpcmisc.cpp
321 extern UniValue z_getpaymentdisclosure(const UniValue& params, bool fHelp); // in rpcdisclosure.cpp
322 extern UniValue z_validatepaymentdisclosure(const UniValue &params, bool fHelp); // in rpcdisclosure.cpp
323
324 extern UniValue MoMoMdata(const UniValue& params, bool fHelp);
325 extern UniValue calc_MoM(const UniValue& params, bool fHelp);
326 extern UniValue height_MoM(const UniValue& params, bool fHelp);
327 extern UniValue assetchainproof(const UniValue& params, bool fHelp);
328 extern UniValue crosschainproof(const UniValue& params, bool fHelp);
329 extern UniValue migrate_converttoexport(const UniValue& params, bool fHelp);
330 extern UniValue migrate_createimporttransaction(const UniValue& params, bool fHelp);
331 extern UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp);
332
333 extern UniValue notaries(const UniValue& params, bool fHelp);
334 extern UniValue minerids(const UniValue& params, bool fHelp);
335 extern UniValue kvsearch(const UniValue& params, bool fHelp);
336 extern UniValue kvupdate(const UniValue& params, bool fHelp);
337 extern UniValue paxprice(const UniValue& params, bool fHelp);
338 extern UniValue paxpending(const UniValue& params, bool fHelp);
339 extern UniValue paxprices(const UniValue& params, bool fHelp);
340 extern UniValue paxdeposit(const UniValue& params, bool fHelp);
341 extern UniValue paxwithdraw(const UniValue& params, bool fHelp);
342
343 bool StartRPC();
344 void InterruptRPC();
345 void StopRPC();
346 std::string JSONRPCExecBatch(const UniValue& vReq);
347
348 #endif // BITCOIN_RPCSERVER_H
This page took 0.043368 seconds and 4 git commands to generate.