BSHA3  0.17.99
P2P Blockchain, based on Bitcoin
server.h
Go to the documentation of this file.
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2018 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_RPC_SERVER_H
7 #define BITCOIN_RPC_SERVER_H
8 
9 #include <amount.h>
10 #include <rpc/protocol.h>
11 #include <uint256.h>
12 
13 #include <list>
14 #include <map>
15 #include <stdint.h>
16 #include <string>
17 
18 #include <univalue.h>
19 
20 static const unsigned int DEFAULT_RPC_SERIALIZE_VERSION = 1;
21 
22 class CRPCCommand;
23 
24 namespace RPCServer
25 {
26  void OnStarted(std::function<void ()> slot);
27  void OnStopped(std::function<void ()> slot);
28 }
29 
32 struct UniValueType {
33  UniValueType(UniValue::VType _type) : typeAny(false), type(_type) {}
34  UniValueType() : typeAny(true) {}
35  bool typeAny;
37 };
38 
40 {
41 public:
43  std::string strMethod;
45  bool fHelp;
46  std::string URI;
47  std::string authUser;
48  std::string peerAddr;
49 
51  void parse(const UniValue& valRequest);
52 };
53 
55 bool IsRPCRunning();
56 
61 void SetRPCWarmupStatus(const std::string& newStatus);
62 /* Mark warmup as done. RPC calls will be processed from now on. */
64 
65 /* returns the current warmup state. */
66 bool RPCIsInWarmup(std::string *outStatus);
67 
72 void RPCTypeCheck(const UniValue& params,
73  const std::list<UniValueType>& typesExpected, bool fAllowNull=false);
74 
78 void RPCTypeCheckArgument(const UniValue& value, const UniValueType& typeExpected);
79 
80 /*
81  Check for expected keys/value types in an Object.
82 */
83 void RPCTypeCheckObj(const UniValue& o,
84  const std::map<std::string, UniValueType>& typesExpected,
85  bool fAllowNull = false,
86  bool fStrict = false);
87 
93 {
94 public:
95  virtual ~RPCTimerBase() {}
96 };
97 
102 {
103 public:
104  virtual ~RPCTimerInterface() {}
106  virtual const char *Name() = 0;
113  virtual RPCTimerBase* NewTimer(std::function<void()>& func, int64_t millis) = 0;
114 };
115 
122 
127 void RPCRunLater(const std::string& name, std::function<void()> func, int64_t nSeconds);
128 
129 typedef UniValue(*rpcfn_type)(const JSONRPCRequest& jsonRequest);
130 
132 {
133 public:
134  std::string category;
135  std::string name;
137  std::vector<std::string> argNames;
138 };
139 
144 {
145 private:
146  std::map<std::string, const CRPCCommand*> mapCommands;
147 public:
148  CRPCTable();
149  const CRPCCommand* operator[](const std::string& name) const;
150  std::string help(const std::string& name, const JSONRPCRequest& helpreq) const;
151 
158  UniValue execute(const JSONRPCRequest &request) const;
159 
164  std::vector<std::string> listCommands() const;
165 
166 
181  bool appendCommand(const std::string& name, const CRPCCommand* pcmd);
182 };
183 
184 bool IsDeprecatedRPCEnabled(const std::string& method);
185 
186 extern CRPCTable tableRPC;
187 
192 extern uint256 ParseHashV(const UniValue& v, std::string strName);
193 extern uint256 ParseHashO(const UniValue& o, std::string strKey);
194 extern std::vector<unsigned char> ParseHexV(const UniValue& v, std::string strName);
195 extern std::vector<unsigned char> ParseHexO(const UniValue& o, std::string strKey);
196 
197 extern CAmount AmountFromValue(const UniValue& value);
198 extern std::string HelpExampleCli(const std::string& methodname, const std::string& args);
199 extern std::string HelpExampleRpc(const std::string& methodname, const std::string& args);
200 
201 void StartRPC();
202 void InterruptRPC();
203 void StopRPC();
204 std::string JSONRPCExecBatch(const JSONRPCRequest& jreq, const UniValue& vReq);
205 
206 // Retrieves any serialization flags requested in command line argument
208 
209 #endif // BITCOIN_RPC_SERVER_H
UniValueType(UniValue::VType _type)
Definition: server.h:33
RPC timer "driver".
Definition: server.h:101
std::string help(const std::string &name, const JSONRPCRequest &helpreq) const
Note: This interface may still be subject to change.
Definition: server.cpp:148
std::string category
Definition: server.h:134
bool IsRPCRunning()
Query whether RPC is running.
Definition: server.cpp:321
Bitcoin RPC command dispatcher.
Definition: server.h:143
uint256 ParseHashV(const UniValue &v, std::string strName)
Utilities: convert hex-encoded Values (throws error if not hex).
Definition: server.cpp:117
rpcfn_type actor
Definition: server.h:136
std::vector< unsigned char > ParseHexO(const UniValue &o, std::string strKey)
Definition: server.cpp:139
bool typeAny
Definition: server.h:35
void SetRPCWarmupFinished()
Definition: server.cpp:332
void OnStopped(std::function< void()> slot)
Definition: server.cpp:46
void RPCTypeCheckArgument(const UniValue &value, const UniValueType &typeExpected)
Type-check one argument; throws JSONRPCError if wrong type given.
Definition: server.cpp:68
void RPCSetTimerInterface(RPCTimerInterface *iface)
Set the factory function for timers.
Definition: server.cpp:528
bool appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
Definition: server.cpp:285
std::vector< std::string > argNames
Definition: server.h:137
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition: server.cpp:516
UniValue::VType type
Definition: server.h:36
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
UniValue execute(const JSONRPCRequest &request) const
Execute a method.
Definition: server.cpp:469
const CRPCCommand * operator[](const std::string &name) const
Definition: server.cpp:277
std::string strMethod
Definition: server.h:43
CAmount AmountFromValue(const UniValue &value)
Definition: server.cpp:105
CRPCTable tableRPC
Definition: server.cpp:556
std::string name
Definition: server.h:135
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
Definition: server.cpp:511
std::string peerAddr
Definition: server.h:48
std::vector< unsigned char > ParseHexV(const UniValue &v, std::string strName)
Definition: server.cpp:130
UniValue params
Definition: server.h:44
const char * name
Definition: rest.cpp:37
bool IsDeprecatedRPCEnabled(const std::string &method)
Definition: server.cpp:380
UniValue id
Definition: server.h:42
int RPCSerializationFlags()
Definition: server.cpp:548
virtual ~RPCTimerInterface()
Definition: server.h:104
virtual ~RPCTimerBase()
Definition: server.h:95
std::map< std::string, const CRPCCommand * > mapCommands
Definition: server.h:146
void RPCRunLater(const std::string &name, std::function< void()> func, int64_t nSeconds)
Run func nSeconds from now.
Definition: server.cpp:539
virtual RPCTimerBase * NewTimer(std::function< void()> &func, int64_t millis)=0
Factory function for timers.
bool fHelp
Definition: server.h:45
256-bit opaque blob.
Definition: uint256.h:122
void parse(const UniValue &valRequest)
Definition: server.cpp:347
void RPCTypeCheckObj(const UniValue &o, const std::map< std::string, UniValueType > &typesExpected, bool fAllowNull=false, bool fStrict=false)
Definition: server.cpp:75
void RPCUnsetTimerInterface(RPCTimerInterface *iface)
Unset factory function for timers.
Definition: server.cpp:533
UniValueType()
Definition: server.h:34
JSONRPCRequest()
Definition: server.h:50
uint256 ParseHashO(const UniValue &o, std::string strKey)
Definition: server.cpp:126
void StopRPC()
Definition: server.cpp:313
std::string URI
Definition: server.h:46
void StartRPC()
Definition: server.cpp:299
void InterruptRPC()
Definition: server.cpp:306
std::string authUser
Definition: server.h:47
Opaque base class for timers returned by NewTimerFunc.
Definition: server.h:92
void RPCTypeCheck(const UniValue &params, const std::list< UniValueType > &typesExpected, bool fAllowNull=false)
Type-check arguments; throws JSONRPCError if wrong type given.
Definition: server.cpp:51
const UniValue NullUniValue
Definition: univalue.cpp:13
virtual const char * Name()=0
Implementation name.
void OnStarted(std::function< void()> slot)
Definition: server.cpp:41
void SetRPCWarmupStatus(const std::string &newStatus)
Set the RPC warmup status.
Definition: server.cpp:326
std::string JSONRPCExecBatch(const JSONRPCRequest &jreq, const UniValue &vReq)
Definition: server.cpp:410
std::vector< std::string > listCommands() const
Returns a list of registered commands.
Definition: server.cpp:500
void RPCSetTimerInterfaceIfUnset(RPCTimerInterface *iface)
Set the factory function for timer, but only, if unset.
Definition: server.cpp:522
UniValue(* rpcfn_type)(const JSONRPCRequest &jsonRequest)
Definition: server.h:129
CRPCTable()
Definition: server.cpp:265
Wrapper for UniValue::VType, which includes typeAny: Used to denote don&#39;t care type.
Definition: server.h:32
bool RPCIsInWarmup(std::string *outStatus)
Definition: server.cpp:339