Merge pull request #6599
[bitcoinplatinum.git] / src / rpcserver.h
blob3a71fd510f0690aac97d3dabefe9da3393e439c5
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
9 #include "amount.h"
10 #include "rpcprotocol.h"
11 #include "uint256.h"
13 #include <list>
14 #include <map>
15 #include <stdint.h>
16 #include <string>
18 #include <boost/function.hpp>
20 #include "univalue/univalue.h"
22 class CRPCCommand;
24 namespace RPCServer
26 void OnStarted(boost::function<void ()> slot);
27 void OnStopped(boost::function<void ()> slot);
28 void OnPreCommand(boost::function<void (const CRPCCommand&)> slot);
29 void OnPostCommand(boost::function<void (const CRPCCommand&)> slot);
32 class CBlockIndex;
33 class CNetAddr;
35 class AcceptedConnection
37 public:
38 virtual ~AcceptedConnection() {}
40 virtual std::iostream& stream() = 0;
41 virtual std::string peer_address_to_string() const = 0;
42 virtual void close() = 0;
45 /** Start RPC threads */
46 void StartRPCThreads();
47 /**
48 * Alternative to StartRPCThreads for the GUI, when no server is
49 * used. The RPC thread in this case is only used to handle timeouts.
50 * If real RPC threads have already been started this is a no-op.
52 void StartDummyRPCThread();
53 /** Stop RPC threads */
54 void StopRPCThreads();
55 /** Query whether RPC is running */
56 bool IsRPCRunning();
58 /**
59 * Set the RPC warmup status. When this is done, all RPC calls will error out
60 * immediately with RPC_IN_WARMUP.
62 void SetRPCWarmupStatus(const std::string& newStatus);
63 /* Mark warmup as done. RPC calls will be processed from now on. */
64 void SetRPCWarmupFinished();
66 /* returns the current warmup state. */
67 bool RPCIsInWarmup(std::string *statusOut);
69 /**
70 * Type-check arguments; throws JSONRPCError if wrong type given. Does not check that
71 * the right number of arguments are passed, just that any passed are the correct type.
72 * Use like: RPCTypeCheck(params, boost::assign::list_of(str_type)(int_type)(obj_type));
74 void RPCTypeCheck(const UniValue& params,
75 const std::list<UniValue::VType>& typesExpected, bool fAllowNull=false);
78 Check for expected keys/value types in an Object.
79 Use like: RPCTypeCheckObj(object, boost::assign::map_list_of("name", str_type)("value", int_type));
81 void RPCTypeCheckObj(const UniValue& o,
82 const std::map<std::string, UniValue::VType>& typesExpected, bool fAllowNull=false);
84 /**
85 * Run func nSeconds from now. Uses boost deadline timers.
86 * Overrides previous timer <name> (if any).
88 void RPCRunLater(const std::string& name, boost::function<void(void)> func, int64_t nSeconds);
90 //! Convert boost::asio address to CNetAddr
91 extern CNetAddr BoostAsioToCNetAddr(boost::asio::ip::address address);
93 typedef UniValue(*rpcfn_type)(const UniValue& params, bool fHelp);
95 class CRPCCommand
97 public:
98 std::string category;
99 std::string name;
100 rpcfn_type actor;
101 bool okSafeMode;
105 * Bitcoin RPC command dispatcher.
107 class CRPCTable
109 private:
110 std::map<std::string, const CRPCCommand*> mapCommands;
111 public:
112 CRPCTable();
113 const CRPCCommand* operator[](const std::string& name) const;
114 std::string help(const std::string& name) const;
117 * Execute a method.
118 * @param method Method to execute
119 * @param params UniValue Array of arguments (JSON objects)
120 * @returns Result of the call.
121 * @throws an exception (UniValue) when an error happens.
123 UniValue execute(const std::string &method, const UniValue &params) const;
126 extern const CRPCTable tableRPC;
129 * Utilities: convert hex-encoded Values
130 * (throws error if not hex).
132 extern uint256 ParseHashV(const UniValue& v, std::string strName);
133 extern uint256 ParseHashO(const UniValue& o, std::string strKey);
134 extern std::vector<unsigned char> ParseHexV(const UniValue& v, std::string strName);
135 extern std::vector<unsigned char> ParseHexO(const UniValue& o, std::string strKey);
137 extern void InitRPCMining();
138 extern void ShutdownRPCMining();
140 extern int64_t nWalletUnlockTime;
141 extern CAmount AmountFromValue(const UniValue& value);
142 extern UniValue ValueFromAmount(const CAmount& amount);
143 extern double GetDifficulty(const CBlockIndex* blockindex = NULL);
144 extern std::string HelpRequiringPassphrase();
145 extern std::string HelpExampleCli(const std::string& methodname, const std::string& args);
146 extern std::string HelpExampleRpc(const std::string& methodname, const std::string& args);
148 extern void EnsureWalletIsUnlocked();
150 extern UniValue getconnectioncount(const UniValue& params, bool fHelp); // in rpcnet.cpp
151 extern UniValue getpeerinfo(const UniValue& params, bool fHelp);
152 extern UniValue ping(const UniValue& params, bool fHelp);
153 extern UniValue addnode(const UniValue& params, bool fHelp);
154 extern UniValue disconnectnode(const UniValue& params, bool fHelp);
155 extern UniValue getaddednodeinfo(const UniValue& params, bool fHelp);
156 extern UniValue getnettotals(const UniValue& params, bool fHelp);
157 extern UniValue setban(const UniValue& params, bool fHelp);
158 extern UniValue listbanned(const UniValue& params, bool fHelp);
159 extern UniValue clearbanned(const UniValue& params, bool fHelp);
161 extern UniValue dumpprivkey(const UniValue& params, bool fHelp); // in rpcdump.cpp
162 extern UniValue importprivkey(const UniValue& params, bool fHelp);
163 extern UniValue importaddress(const UniValue& params, bool fHelp);
164 extern UniValue importpubkey(const UniValue& params, bool fHelp);
165 extern UniValue dumpwallet(const UniValue& params, bool fHelp);
166 extern UniValue importwallet(const UniValue& params, bool fHelp);
168 extern UniValue getgenerate(const UniValue& params, bool fHelp); // in rpcmining.cpp
169 extern UniValue setgenerate(const UniValue& params, bool fHelp);
170 extern UniValue generate(const UniValue& params, bool fHelp);
171 extern UniValue getnetworkhashps(const UniValue& params, bool fHelp);
172 extern UniValue getmininginfo(const UniValue& params, bool fHelp);
173 extern UniValue prioritisetransaction(const UniValue& params, bool fHelp);
174 extern UniValue getblocktemplate(const UniValue& params, bool fHelp);
175 extern UniValue submitblock(const UniValue& params, bool fHelp);
176 extern UniValue estimatefee(const UniValue& params, bool fHelp);
177 extern UniValue estimatepriority(const UniValue& params, bool fHelp);
179 extern UniValue getnewaddress(const UniValue& params, bool fHelp); // in rpcwallet.cpp
180 extern UniValue getaccountaddress(const UniValue& params, bool fHelp);
181 extern UniValue getrawchangeaddress(const UniValue& params, bool fHelp);
182 extern UniValue setaccount(const UniValue& params, bool fHelp);
183 extern UniValue getaccount(const UniValue& params, bool fHelp);
184 extern UniValue getaddressesbyaccount(const UniValue& params, bool fHelp);
185 extern UniValue sendtoaddress(const UniValue& params, bool fHelp);
186 extern UniValue signmessage(const UniValue& params, bool fHelp);
187 extern UniValue verifymessage(const UniValue& params, bool fHelp);
188 extern UniValue getreceivedbyaddress(const UniValue& params, bool fHelp);
189 extern UniValue getreceivedbyaccount(const UniValue& params, bool fHelp);
190 extern UniValue getbalance(const UniValue& params, bool fHelp);
191 extern UniValue getunconfirmedbalance(const UniValue& params, bool fHelp);
192 extern UniValue movecmd(const UniValue& params, bool fHelp);
193 extern UniValue sendfrom(const UniValue& params, bool fHelp);
194 extern UniValue sendmany(const UniValue& params, bool fHelp);
195 extern UniValue addmultisigaddress(const UniValue& params, bool fHelp);
196 extern UniValue createmultisig(const UniValue& params, bool fHelp);
197 extern UniValue listreceivedbyaddress(const UniValue& params, bool fHelp);
198 extern UniValue listreceivedbyaccount(const UniValue& params, bool fHelp);
199 extern UniValue listtransactions(const UniValue& params, bool fHelp);
200 extern UniValue listaddressgroupings(const UniValue& params, bool fHelp);
201 extern UniValue listaccounts(const UniValue& params, bool fHelp);
202 extern UniValue listsinceblock(const UniValue& params, bool fHelp);
203 extern UniValue gettransaction(const UniValue& params, bool fHelp);
204 extern UniValue backupwallet(const UniValue& params, bool fHelp);
205 extern UniValue keypoolrefill(const UniValue& params, bool fHelp);
206 extern UniValue walletpassphrase(const UniValue& params, bool fHelp);
207 extern UniValue walletpassphrasechange(const UniValue& params, bool fHelp);
208 extern UniValue walletlock(const UniValue& params, bool fHelp);
209 extern UniValue encryptwallet(const UniValue& params, bool fHelp);
210 extern UniValue validateaddress(const UniValue& params, bool fHelp);
211 extern UniValue getinfo(const UniValue& params, bool fHelp);
212 extern UniValue getwalletinfo(const UniValue& params, bool fHelp);
213 extern UniValue getblockchaininfo(const UniValue& params, bool fHelp);
214 extern UniValue getnetworkinfo(const UniValue& params, bool fHelp);
215 extern UniValue setmocktime(const UniValue& params, bool fHelp);
216 extern UniValue resendwallettransactions(const UniValue& params, bool fHelp);
218 extern UniValue getrawtransaction(const UniValue& params, bool fHelp); // in rcprawtransaction.cpp
219 extern UniValue listunspent(const UniValue& params, bool fHelp);
220 extern UniValue lockunspent(const UniValue& params, bool fHelp);
221 extern UniValue listlockunspent(const UniValue& params, bool fHelp);
222 extern UniValue createrawtransaction(const UniValue& params, bool fHelp);
223 extern UniValue decoderawtransaction(const UniValue& params, bool fHelp);
224 extern UniValue decodescript(const UniValue& params, bool fHelp);
225 extern UniValue fundrawtransaction(const UniValue& params, bool fHelp);
226 extern UniValue signrawtransaction(const UniValue& params, bool fHelp);
227 extern UniValue sendrawtransaction(const UniValue& params, bool fHelp);
228 extern UniValue gettxoutproof(const UniValue& params, bool fHelp);
229 extern UniValue verifytxoutproof(const UniValue& params, bool fHelp);
231 extern UniValue getblockcount(const UniValue& params, bool fHelp); // in rpcblockchain.cpp
232 extern UniValue getbestblockhash(const UniValue& params, bool fHelp);
233 extern UniValue getdifficulty(const UniValue& params, bool fHelp);
234 extern UniValue settxfee(const UniValue& params, bool fHelp);
235 extern UniValue getmempoolinfo(const UniValue& params, bool fHelp);
236 extern UniValue getrawmempool(const UniValue& params, bool fHelp);
237 extern UniValue getblockhash(const UniValue& params, bool fHelp);
238 extern UniValue getblockheader(const UniValue& params, bool fHelp);
239 extern UniValue getblock(const UniValue& params, bool fHelp);
240 extern UniValue gettxoutsetinfo(const UniValue& params, bool fHelp);
241 extern UniValue gettxout(const UniValue& params, bool fHelp);
242 extern UniValue verifychain(const UniValue& params, bool fHelp);
243 extern UniValue getchaintips(const UniValue& params, bool fHelp);
244 extern UniValue invalidateblock(const UniValue& params, bool fHelp);
245 extern UniValue reconsiderblock(const UniValue& params, bool fHelp);
247 // in rest.cpp
248 extern bool HTTPReq_REST(AcceptedConnection *conn,
249 const std::string& strURI,
250 const std::string& strRequest,
251 const std::map<std::string, std::string>& mapHeaders,
252 bool fRun);
254 #endif // BITCOIN_RPCSERVER_H