]>
Commit | Line | Data |
---|---|---|
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 | 23 | class AsyncRPCQueue; |
4401b2d7 EL |
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 | ||
51ed9ec9 | 34 | class CBlockIndex; |
21bf3d25 | 35 | class CNetAddr; |
480d44bd | 36 | |
ed5769f5 JG |
37 | class AcceptedConnection |
38 | { | |
39 | public: | |
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 | 48 | void 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 | */ | |
54 | void StartDummyRPCThread(); | |
72fb3d29 | 55 | /** Stop RPC threads */ |
21eb5ada | 56 | void StopRPCThreads(); |
72fb3d29 | 57 | /** Query whether RPC is running */ |
ff6a7af1 | 58 | bool IsRPCRunning(); |
460c51fd | 59 | |
fc72c078 S |
60 | /** Get the async queue*/ |
61 | std::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 | */ | |
68 | void SetRPCWarmupStatus(const std::string& newStatus); | |
69 | /* Mark warmup as done. RPC calls will be processed from now on. */ | |
70 | void SetRPCWarmupFinished(); | |
71 | ||
78bdc810 JS |
72 | /* returns the current warmup state. */ |
73 | bool 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 | 80 | void 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 | 86 | void 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 | 93 | void RPCRunLater(const std::string& name, boost::function<void(void)> func, int64_t nSeconds); |
92f2c1fe | 94 | |
21bf3d25 WL |
95 | //! Convert boost::asio address to CNetAddr |
96 | extern CNetAddr BoostAsioToCNetAddr(boost::asio::ip::address address); | |
97 | ||
e46704dd PW |
98 | typedef json_spirit::Value(*rpcfn_type)(const json_spirit::Array& params, bool fHelp); |
99 | ||
100 | class CRPCCommand | |
101 | { | |
102 | public: | |
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 |
112 | class CRPCTable |
113 | { | |
114 | private: | |
115 | std::map<std::string, const CRPCCommand*> mapCommands; | |
116 | public: | |
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 ¶ms) const; | |
e46704dd PW |
129 | }; |
130 | ||
131 | extern const CRPCTable tableRPC; | |
d98bf10f | 132 | |
77920402 MF |
133 | /** |
134 | * Utilities: convert hex-encoded Values | |
135 | * (throws error if not hex). | |
136 | */ | |
463c9710 PT |
137 | extern uint256 ParseHashV(const json_spirit::Value& v, std::string strName); |
138 | extern uint256 ParseHashO(const json_spirit::Object& o, std::string strKey); | |
139 | extern std::vector<unsigned char> ParseHexV(const json_spirit::Value& v, std::string strName); | |
140 | extern std::vector<unsigned char> ParseHexO(const json_spirit::Object& o, std::string strKey); | |
141 | ||
d98bf10f WL |
142 | extern void InitRPCMining(); |
143 | extern void ShutdownRPCMining(); | |
e46704dd | 144 | |
51ed9ec9 | 145 | extern int64_t nWalletUnlockTime; |
a372168e MF |
146 | extern CAmount AmountFromValue(const json_spirit::Value& value); |
147 | extern json_spirit::Value ValueFromAmount(const CAmount& amount); | |
c625ae04 | 148 | extern double GetDifficulty(const CBlockIndex* blockindex = NULL); |
695a7a88 | 149 | extern double GetNetworkDifficulty(const CBlockIndex* blockindex = NULL); |
c625ae04 | 150 | extern std::string HelpRequiringPassphrase(); |
a6099ef3 | 151 | extern std::string HelpExampleCli(std::string methodname, std::string args); |
152 | extern std::string HelpExampleRpc(std::string methodname, std::string args); | |
153 | ||
c625ae04 | 154 | extern void EnsureWalletIsUnlocked(); |
e3bc5698 JG |
155 | |
156 | extern json_spirit::Value getconnectioncount(const json_spirit::Array& params, bool fHelp); // in rpcnet.cpp | |
157 | extern json_spirit::Value getpeerinfo(const json_spirit::Array& params, bool fHelp); | |
971bb3e9 | 158 | extern json_spirit::Value ping(const json_spirit::Array& params, bool fHelp); |
72a348fd | 159 | extern json_spirit::Value addnode(const json_spirit::Array& params, bool fHelp); |
67a11bd6 | 160 | extern json_spirit::Value getaddednodeinfo(const json_spirit::Array& params, bool fHelp); |
ce14345a | 161 | extern json_spirit::Value getnettotals(const json_spirit::Array& params, bool fHelp); |
4e534aa9 | 162 | |
e3bc5698 JG |
163 | extern json_spirit::Value dumpprivkey(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp |
164 | extern json_spirit::Value importprivkey(const json_spirit::Array& params, bool fHelp); | |
c8988460 | 165 | extern json_spirit::Value importaddress(const json_spirit::Array& params, bool fHelp); |
4e534aa9 PW |
166 | extern json_spirit::Value dumpwallet(const json_spirit::Array& params, bool fHelp); |
167 | extern json_spirit::Value importwallet(const json_spirit::Array& params, bool fHelp); | |
e3bc5698 JG |
168 | |
169 | extern json_spirit::Value getgenerate(const json_spirit::Array& params, bool fHelp); // in rpcmining.cpp | |
170 | extern json_spirit::Value setgenerate(const json_spirit::Array& params, bool fHelp); | |
6b04508e | 171 | extern json_spirit::Value generate(const json_spirit::Array& params, bool fHelp); |
d64eef48 | 172 | extern json_spirit::Value getnetworkhashps(const json_spirit::Array& params, bool fHelp); |
e3bc5698 | 173 | extern json_spirit::Value getmininginfo(const json_spirit::Array& params, bool fHelp); |
2a72d459 | 174 | extern json_spirit::Value prioritisetransaction(const json_spirit::Array& params, bool fHelp); |
e3bc5698 JG |
175 | extern json_spirit::Value getblocktemplate(const json_spirit::Array& params, bool fHelp); |
176 | extern json_spirit::Value submitblock(const json_spirit::Array& params, bool fHelp); | |
171ca774 GA |
177 | extern json_spirit::Value estimatefee(const json_spirit::Array& params, bool fHelp); |
178 | extern json_spirit::Value estimatepriority(const json_spirit::Array& params, bool fHelp); | |
e3bc5698 JG |
179 | |
180 | extern json_spirit::Value getnewaddress(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp | |
181 | extern json_spirit::Value getaccountaddress(const json_spirit::Array& params, bool fHelp); | |
e5e9904c | 182 | extern json_spirit::Value getrawchangeaddress(const json_spirit::Array& params, bool fHelp); |
e3bc5698 JG |
183 | extern json_spirit::Value setaccount(const json_spirit::Array& params, bool fHelp); |
184 | extern json_spirit::Value getaccount(const json_spirit::Array& params, bool fHelp); | |
185 | extern json_spirit::Value getaddressesbyaccount(const json_spirit::Array& params, bool fHelp); | |
186 | extern json_spirit::Value sendtoaddress(const json_spirit::Array& params, bool fHelp); | |
187 | extern json_spirit::Value signmessage(const json_spirit::Array& params, bool fHelp); | |
188 | extern json_spirit::Value verifymessage(const json_spirit::Array& params, bool fHelp); | |
189 | extern json_spirit::Value getreceivedbyaddress(const json_spirit::Array& params, bool fHelp); | |
190 | extern json_spirit::Value getreceivedbyaccount(const json_spirit::Array& params, bool fHelp); | |
191 | extern json_spirit::Value getbalance(const json_spirit::Array& params, bool fHelp); | |
6027b460 | 192 | extern json_spirit::Value getunconfirmedbalance(const json_spirit::Array& params, bool fHelp); |
e3bc5698 JG |
193 | extern json_spirit::Value movecmd(const json_spirit::Array& params, bool fHelp); |
194 | extern json_spirit::Value sendfrom(const json_spirit::Array& params, bool fHelp); | |
195 | extern json_spirit::Value sendmany(const json_spirit::Array& params, bool fHelp); | |
196 | extern json_spirit::Value addmultisigaddress(const json_spirit::Array& params, bool fHelp); | |
34226be7 | 197 | extern json_spirit::Value createmultisig(const json_spirit::Array& params, bool fHelp); |
e3bc5698 JG |
198 | extern json_spirit::Value listreceivedbyaddress(const json_spirit::Array& params, bool fHelp); |
199 | extern json_spirit::Value listreceivedbyaccount(const json_spirit::Array& params, bool fHelp); | |
200 | extern json_spirit::Value listtransactions(const json_spirit::Array& params, bool fHelp); | |
22dfd735 | 201 | extern json_spirit::Value listaddressgroupings(const json_spirit::Array& params, bool fHelp); |
e3bc5698 JG |
202 | extern json_spirit::Value listaccounts(const json_spirit::Array& params, bool fHelp); |
203 | extern json_spirit::Value listsinceblock(const json_spirit::Array& params, bool fHelp); | |
204 | extern json_spirit::Value gettransaction(const json_spirit::Array& params, bool fHelp); | |
205 | extern json_spirit::Value backupwallet(const json_spirit::Array& params, bool fHelp); | |
206 | extern json_spirit::Value keypoolrefill(const json_spirit::Array& params, bool fHelp); | |
207 | extern json_spirit::Value walletpassphrase(const json_spirit::Array& params, bool fHelp); | |
208 | extern json_spirit::Value walletpassphrasechange(const json_spirit::Array& params, bool fHelp); | |
209 | extern json_spirit::Value walletlock(const json_spirit::Array& params, bool fHelp); | |
210 | extern json_spirit::Value encryptwallet(const json_spirit::Array& params, bool fHelp); | |
211 | extern json_spirit::Value validateaddress(const json_spirit::Array& params, bool fHelp); | |
c625ae04 | 212 | extern json_spirit::Value getinfo(const json_spirit::Array& params, bool fHelp); |
a00ebb51 | 213 | extern json_spirit::Value getwalletinfo(const json_spirit::Array& params, bool fHelp); |
d387b8ec WL |
214 | extern json_spirit::Value getblockchaininfo(const json_spirit::Array& params, bool fHelp); |
215 | extern json_spirit::Value getnetworkinfo(const json_spirit::Array& params, bool fHelp); | |
a8b2ce55 | 216 | extern json_spirit::Value setmocktime(const json_spirit::Array& params, bool fHelp); |
0f5954c4 | 217 | extern json_spirit::Value resendwallettransactions(const json_spirit::Array& params, bool fHelp); |
6962bb3d | 218 | extern json_spirit::Value zc_benchmark(const json_spirit::Array& params, bool fHelp); |
730790f7 | 219 | extern json_spirit::Value zc_raw_keygen(const json_spirit::Array& params, bool fHelp); |
b7e4abd6 | 220 | extern json_spirit::Value zc_raw_joinsplit(const json_spirit::Array& params, bool fHelp); |
a8ac403d | 221 | extern json_spirit::Value zc_raw_receive(const json_spirit::Array& params, bool fHelp); |
1737627c | 222 | extern json_spirit::Value zc_sample_joinsplit(const json_spirit::Array& params, bool fHelp); |
e3bc5698 JG |
223 | |
224 | extern json_spirit::Value getrawtransaction(const json_spirit::Array& params, bool fHelp); // in rcprawtransaction.cpp | |
225 | extern json_spirit::Value listunspent(const json_spirit::Array& params, bool fHelp); | |
fdbb537d JG |
226 | extern json_spirit::Value lockunspent(const json_spirit::Array& params, bool fHelp); |
227 | extern json_spirit::Value listlockunspent(const json_spirit::Array& params, bool fHelp); | |
e3bc5698 JG |
228 | extern json_spirit::Value createrawtransaction(const json_spirit::Array& params, bool fHelp); |
229 | extern json_spirit::Value decoderawtransaction(const json_spirit::Array& params, bool fHelp); | |
be066fad | 230 | extern json_spirit::Value decodescript(const json_spirit::Array& params, bool fHelp); |
e3bc5698 JG |
231 | extern json_spirit::Value signrawtransaction(const json_spirit::Array& params, bool fHelp); |
232 | extern json_spirit::Value sendrawtransaction(const json_spirit::Array& params, bool fHelp); | |
59ed61b3 MC |
233 | extern json_spirit::Value gettxoutproof(const json_spirit::Array& params, bool fHelp); |
234 | extern json_spirit::Value verifytxoutproof(const json_spirit::Array& params, bool fHelp); | |
e3bc5698 | 235 | |
c625ae04 | 236 | extern json_spirit::Value getblockcount(const json_spirit::Array& params, bool fHelp); // in rpcblockchain.cpp |
091aa8da | 237 | extern json_spirit::Value getbestblockhash(const json_spirit::Array& params, bool fHelp); |
c625ae04 JG |
238 | extern json_spirit::Value getdifficulty(const json_spirit::Array& params, bool fHelp); |
239 | extern json_spirit::Value settxfee(const json_spirit::Array& params, bool fHelp); | |
6f2c26a4 | 240 | extern json_spirit::Value getmempoolinfo(const json_spirit::Array& params, bool fHelp); |
c625ae04 JG |
241 | extern json_spirit::Value getrawmempool(const json_spirit::Array& params, bool fHelp); |
242 | extern json_spirit::Value getblockhash(const json_spirit::Array& params, bool fHelp); | |
243 | extern json_spirit::Value getblock(const json_spirit::Array& params, bool fHelp); | |
beeb5761 PW |
244 | extern json_spirit::Value gettxoutsetinfo(const json_spirit::Array& params, bool fHelp); |
245 | extern json_spirit::Value gettxout(const json_spirit::Array& params, bool fHelp); | |
a9869d0d | 246 | extern json_spirit::Value paxprice(const json_spirit::Array& params, bool fHelp); |
83a7f513 | 247 | extern json_spirit::Value paxprices(const json_spirit::Array& params, bool fHelp); |
d7d27bb3 | 248 | extern json_spirit::Value paxdeposit(const json_spirit::Array& params, bool fHelp); |
f5906533 | 249 | extern json_spirit::Value verifychain(const json_spirit::Array& params, bool fHelp); |
b33bd7a3 | 250 | extern json_spirit::Value getchaintips(const json_spirit::Array& params, bool fHelp); |
9b0a8d31 PW |
251 | extern json_spirit::Value invalidateblock(const json_spirit::Array& params, bool fHelp); |
252 | extern json_spirit::Value reconsiderblock(const json_spirit::Array& params, bool fHelp); | |
c625ae04 | 253 | |
1b114e54 S |
254 | extern json_spirit::Value getblocksubsidy(const json_spirit::Array& params, bool fHelp); |
255 | ||
c1c45943 S |
256 | extern json_spirit::Value z_exportkey(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp |
257 | extern json_spirit::Value z_importkey(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp | |
258 | extern json_spirit::Value z_getnewaddress(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp | |
e709997f | 259 | extern json_spirit::Value z_listaddresses(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp |
92444edc S |
260 | extern json_spirit::Value z_exportwallet(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp |
261 | extern json_spirit::Value z_importwallet(const json_spirit::Array& params, bool fHelp); // in rpcdump.cpp | |
6c41028f | 262 | extern json_spirit::Value z_listreceivedbyaddress(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp |
a0a3334c S |
263 | extern json_spirit::Value z_getbalance(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp |
264 | extern json_spirit::Value z_gettotalbalance(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp | |
fc72c078 S |
265 | extern json_spirit::Value z_sendmany(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp |
266 | extern json_spirit::Value z_getoperationstatus(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp | |
c1eae280 | 267 | extern json_spirit::Value z_getoperationresult(const json_spirit::Array& params, bool fHelp); // in rpcwallet.cpp |
34f0001c | 268 | extern 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 |
272 | extern 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 |