Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

server.h
Go to the documentation of this file.
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 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 <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 class CRPCCommand;
21 
22 namespace RPCServer
23 {
24  void OnStarted(std::function<void ()> slot);
25  void OnStopped(std::function<void ()> slot);
26 }
27 
30 struct UniValueType {
31  explicit UniValueType(UniValue::VType _type) : typeAny(false), type(_type) {}
33  bool typeAny;
35 };
36 
38 {
39 public:
41  std::string strMethod;
43  bool fHelp;
44  std::string URI;
45  std::string authUser;
46 
48  void parse(const UniValue& valRequest);
49 };
50 
52 bool IsRPCRunning();
53 
58 void SetRPCWarmupStatus(const std::string& newStatus);
59 /* Mark warmup as done. RPC calls will be processed from now on. */
61 
62 /* returns the current warmup state. */
63 bool RPCIsInWarmup(std::string *outStatus);
64 
69 void RPCTypeCheck(const UniValue& params,
70  const std::list<UniValue::VType>& typesExpected, bool fAllowNull=false);
71 
75 void RPCTypeCheckArgument(const UniValue& value, UniValue::VType typeExpected);
76 
77 /*
78  Check for expected keys/value types in an Object.
79 */
80 void RPCTypeCheckObj(const UniValue& o,
81  const std::map<std::string, UniValueType>& typesExpected,
82  bool fAllowNull = false,
83  bool fStrict = false);
84 
90 {
91 public:
92  virtual ~RPCTimerBase() {}
93 };
94 
99 {
100 public:
101  virtual ~RPCTimerInterface() {}
103  virtual const char *Name() = 0;
110  virtual RPCTimerBase* NewTimer(std::function<void(void)>& func, int64_t millis) = 0;
111 };
112 
119 
124 void RPCRunLater(const std::string& name, std::function<void(void)> func, int64_t nSeconds);
125 
126 typedef UniValue(*rpcfn_type)(const JSONRPCRequest& jsonRequest);
127 
129 {
130 public:
131  std::string category;
132  std::string name;
134  std::vector<std::string> argNames;
135 };
136 
141 {
142 private:
143  std::map<std::string, const CRPCCommand*> mapCommands;
144 public:
145  CRPCTable();
146  const CRPCCommand* operator[](const std::string& name) const;
147  std::string help(const std::string& name, const std::string& strSubCommand, const JSONRPCRequest& helpreq) const;
148 
155  UniValue execute(const JSONRPCRequest &request) const;
156 
161  std::vector<std::string> listCommands() const;
162 
168  bool appendCommand(const std::string& name, const CRPCCommand* pcmd);
169 };
170 
171 bool IsDeprecatedRPCEnabled(const std::string& method);
172 
173 extern CRPCTable tableRPC;
174 
179 extern uint256 ParseHashV(const UniValue& v, std::string strName);
180 extern uint256 ParseHashO(const UniValue& o, std::string strKey);
181 extern std::vector<unsigned char> ParseHexV(const UniValue& v, std::string strName);
182 extern std::vector<unsigned char> ParseHexO(const UniValue& o, std::string strKey);
183 
184 extern int32_t ParseInt32V(const UniValue& v, const std::string &strName);
185 extern int64_t ParseInt64V(const UniValue& v, const std::string &strName);
186 extern double ParseDoubleV(const UniValue& v, const std::string &strName);
187 extern bool ParseBoolV(const UniValue& v, const std::string &strName);
188 
189 extern CAmount AmountFromValue(const UniValue& value);
190 extern std::string HelpExampleCli(const std::string& methodname, const std::string& args);
191 extern std::string HelpExampleRpc(const std::string& methodname, const std::string& args);
192 
193 bool StartRPC();
194 void InterruptRPC();
195 void StopRPC();
196 std::string JSONRPCExecBatch(const JSONRPCRequest& jreq, const UniValue& vReq);
197 
198 #endif // BITCOIN_RPCSERVER_H
UniValueType(UniValue::VType _type)
Definition: server.h:31
bool StartRPC()
Definition: server.cpp:367
RPC timer "driver".
Definition: server.h:98
std::string category
Definition: server.h:131
bool ParseBoolV(const UniValue &v, const std::string &strName)
Definition: server.cpp:179
bool IsRPCRunning()
Query whether RPC is running.
Definition: server.cpp:390
Dash RPC command dispatcher.
Definition: server.h:140
uint256 ParseHashV(const UniValue &v, std::string strName)
Utilities: convert hex-encoded Values (throws error if not hex).
Definition: server.cpp:121
rpcfn_type actor
Definition: server.h:133
std::vector< unsigned char > ParseHexO(const UniValue &o, std::string strKey)
Definition: server.cpp:147
bool typeAny
Definition: server.h:33
void SetRPCWarmupFinished()
Definition: server.cpp:401
void OnStopped(std::function< void()> slot)
Definition: server.cpp:49
false true true true
Definition: bls_dkg.cpp:176
void RPCSetTimerInterface(RPCTimerInterface *iface)
Set the factory function for timers.
Definition: server.cpp:596
bool appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
Definition: server.cpp:353
std::vector< std::string > argNames
Definition: server.h:134
std::string help(const std::string &name, const std::string &strSubCommand, const JSONRPCRequest &helpreq) const
Note: This interface may still be subject to change.
Definition: server.cpp:203
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition: server.cpp:583
UniValue::VType type
Definition: server.h:34
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:536
const CRPCCommand * operator[](const std::string &name) const
Definition: server.cpp:345
std::string strMethod
Definition: server.h:41
CAmount AmountFromValue(const UniValue &value)
Definition: server.cpp:109
false
Definition: bls_dkg.cpp:168
CRPCTable tableRPC
Definition: server.cpp:616
void RPCTypeCheck(const UniValue &params, const std::list< UniValue::VType > &typesExpected, bool fAllowNull=false)
Type-check arguments; throws JSONRPCError if wrong type given.
Definition: server.cpp:54
std::string name
Definition: server.h:132
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
Definition: server.cpp:578
void RPCTypeCheckArgument(const UniValue &value, UniValue::VType typeExpected)
Type-check one argument; throws JSONRPCError if wrong type given.
Definition: server.cpp:72
std::vector< unsigned char > ParseHexV(const UniValue &v, std::string strName)
Definition: server.cpp:138
virtual RPCTimerBase * NewTimer(std::function< void(void)> &func, int64_t millis)=0
Factory function for timers.
UniValue params
Definition: server.h:42
const char * name
Definition: rest.cpp:36
bool IsDeprecatedRPCEnabled(const std::string &method)
Definition: server.cpp:447
UniValue id
Definition: server.h:40
virtual ~RPCTimerInterface()
Definition: server.h:101
virtual ~RPCTimerBase()
Definition: server.h:92
std::map< std::string, const CRPCCommand * > mapCommands
Definition: server.h:143
int64_t ParseInt64V(const UniValue &v, const std::string &strName)
Definition: server.cpp:161
bool fHelp
Definition: server.h:43
256-bit opaque blob.
Definition: uint256.h:123
void parse(const UniValue &valRequest)
Definition: server.cpp:416
void RPCTypeCheckObj(const UniValue &o, const std::map< std::string, UniValueType > &typesExpected, bool fAllowNull=false, bool fStrict=false)
Definition: server.cpp:79
void RPCUnsetTimerInterface(RPCTimerInterface *iface)
Unset factory function for timers.
Definition: server.cpp:601
UniValueType()
Definition: server.h:32
JSONRPCRequest()
Definition: server.h:47
uint256 ParseHashO(const UniValue &o, std::string strKey)
Definition: server.cpp:134
void StopRPC()
Definition: server.cpp:382
std::string URI
Definition: server.h:44
void InterruptRPC()
Definition: server.cpp:375
std::string authUser
Definition: server.h:45
Opaque base class for timers returned by NewTimerFunc.
Definition: server.h:89
const UniValue NullUniValue
Definition: univalue.cpp:15
double ParseDoubleV(const UniValue &v, const std::string &strName)
Definition: server.cpp:170
void RPCRunLater(const std::string &name, std::function< void(void)> func, int64_t nSeconds)
Run func nSeconds from now.
Definition: server.cpp:607
virtual const char * Name()=0
Implementation name.
void OnStarted(std::function< void()> slot)
Definition: server.cpp:44
int32_t ParseInt32V(const UniValue &v, const std::string &strName)
Definition: server.cpp:152
void SetRPCWarmupStatus(const std::string &newStatus)
Set the RPC warmup status.
Definition: server.cpp:395
std::string JSONRPCExecBatch(const JSONRPCRequest &jreq, const UniValue &vReq)
Definition: server.cpp:477
std::vector< std::string > listCommands() const
Returns a list of registered commands.
Definition: server.cpp:567
void RPCSetTimerInterfaceIfUnset(RPCTimerInterface *iface)
Set the factory function for timer, but only, if unset.
Definition: server.cpp:590
UniValue(* rpcfn_type)(const JSONRPCRequest &jsonRequest)
Definition: server.h:126
CRPCTable()
Definition: server.cpp:333
Wrapper for UniValue::VType, which includes typeAny: Used to denote don&#39;t care type.
Definition: server.h:30
bool RPCIsInWarmup(std::string *outStatus)
Definition: server.cpp:408
Released under the MIT license