Raven Core  3.0.0
P2P Digital Currency
server.h
Go to the documentation of this file.
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 The Bitcoin Core developers
3 // Copyright (c) 2017-2019 The Raven Core developers
4 // Distributed under the MIT software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #ifndef RAVEN_RPCSERVER_H
8 #define RAVEN_RPCSERVER_H
9 
10 #include "amount.h"
11 #include "rpc/protocol.h"
12 #include "uint256.h"
13 
14 #include <list>
15 #include <map>
16 #include <stdint.h>
17 #include <string>
18 
19 #include <univalue.h>
20 
21 static const unsigned int DEFAULT_RPC_SERIALIZE_VERSION = 1;
22 
23 class CRPCCommand;
24 
25 namespace RPCServer
26 {
27  void OnStarted(std::function<void ()> slot);
28  void OnStopped(std::function<void ()> slot);
29 }
30 
33 struct UniValueType {
34  explicit UniValueType(UniValue::VType _type) : typeAny(false), type(_type) {}
35  UniValueType() : typeAny(true) {}
36  bool typeAny;
38 };
39 
41 {
42 public:
44  std::string strMethod;
46  bool fHelp;
47  std::string URI;
48  std::string authUser;
49 
50  JSONRPCRequest() : id(NullUniValue), params(NullUniValue), fHelp(false) {}
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<UniValue::VType>& typesExpected, bool fAllowNull=false);
74 
78 void RPCTypeCheckArgument(const UniValue& value, UniValue::VType 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(void)>& func, int64_t millis) = 0;
114 };
115 
122 
127 void RPCRunLater(const std::string& name, std::function<void(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 
172  bool appendCommand(const std::string& name, const CRPCCommand* pcmd);
173 };
174 
175 bool IsDeprecatedRPCEnabled(const std::string& method);
176 
177 extern CRPCTable tableRPC;
178 
183 extern uint256 ParseHashV(const UniValue& v, std::string strName);
184 extern uint256 ParseHashO(const UniValue& o, std::string strKey);
185 extern std::vector<unsigned char> ParseHexV(const UniValue& v, std::string strName);
186 extern std::vector<unsigned char> ParseHexO(const UniValue& o, std::string strKey);
187 
188 extern CAmount AmountFromValue(const UniValue& value);
189 extern std::string HelpExampleCli(const std::string& methodname, const std::string& args);
190 extern std::string HelpExampleRpc(const std::string& methodname, const std::string& args);
191 
192 bool StartRPC();
193 void InterruptRPC();
194 void StopRPC();
195 std::string JSONRPCExecBatch(const JSONRPCRequest& jreq, const UniValue& vReq);
196 
197 // Retrieves any serialization flags requested in command line argument
199 
200 #endif // RAVEN_RPCSERVER_H
UniValueType(UniValue::VType _type)
Definition: server.h:34
bool StartRPC()
Definition: server.cpp:313
RPC timer "driver".
Definition: server.h:101
std::string category
Definition: server.h:134
bool IsRPCRunning()
Query whether RPC is running.
Definition: server.cpp:336
Raven 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:125
rpcfn_type actor
Definition: server.h:136
std::vector< unsigned char > ParseHexO(const UniValue &o, std::string strKey)
Definition: server.cpp:151
bool typeAny
Definition: server.h:36
void SetRPCWarmupFinished()
Definition: server.cpp:347
void OnStopped(std::function< void()> slot)
Definition: server.cpp:53
void RPCSetTimerInterface(RPCTimerInterface *iface)
Set the factory function for timers.
Definition: server.cpp:539
std::vector< std::string > argNames
Definition: server.h:137
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition: server.cpp:527
UniValue::VType type
Definition: server.h:37
int64_t CAmount
Amount in corbies (Can be negative)
Definition: amount.h:13
std::string strMethod
Definition: server.h:44
CAmount AmountFromValue(const UniValue &value)
Definition: server.cpp:113
CRPCTable tableRPC
Definition: server.cpp:567
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:58
std::string name
Definition: server.h:135
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
Definition: server.cpp:522
void RPCTypeCheckArgument(const UniValue &value, UniValue::VType typeExpected)
Type-check one argument; throws JSONRPCError if wrong type given.
Definition: server.cpp:76
std::vector< unsigned char > ParseHexV(const UniValue &v, std::string strName)
Definition: server.cpp:142
UniValue params
Definition: server.h:45
bool IsDeprecatedRPCEnabled(const std::string &method)
Definition: server.cpp:391
UniValue id
Definition: server.h:43
int RPCSerializationFlags()
Definition: server.cpp:559
virtual ~RPCTimerInterface()
Definition: server.h:104
virtual ~RPCTimerBase()
Definition: server.h:95
std::map< std::string, const CRPCCommand * > mapCommands
Definition: server.h:146
UniValue help(const JSONRPCRequest &jsonRequest)
Definition: server.cpp:216
bool fHelp
Definition: server.h:46
256-bit opaque blob.
Definition: uint256.h:123
void RPCTypeCheckObj(const UniValue &o, const std::map< std::string, UniValueType > &typesExpected, bool fAllowNull=false, bool fStrict=false)
Definition: server.cpp:83
void RPCUnsetTimerInterface(RPCTimerInterface *iface)
Unset factory function for timers.
Definition: server.cpp:544
UniValueType()
Definition: server.h:35
JSONRPCRequest()
Definition: server.h:50
uint256 ParseHashO(const UniValue &o, std::string strKey)
Definition: server.cpp:138
void StopRPC()
Definition: server.cpp:328
std::string URI
Definition: server.h:47
void InterruptRPC()
Definition: server.cpp:321
std::string authUser
Definition: server.h:48
Opaque base class for timers returned by NewTimerFunc.
Definition: server.h:92
const UniValue NullUniValue
Definition: univalue.cpp:15
void RPCRunLater(const std::string &name, std::function< void(void)> func, int64_t nSeconds)
Run func nSeconds from now.
Definition: server.cpp:550
void OnStarted(std::function< void()> slot)
Definition: server.cpp:48
void SetRPCWarmupStatus(const std::string &newStatus)
Set the RPC warmup status.
Definition: server.cpp:341
std::string JSONRPCExecBatch(const JSONRPCRequest &jreq, const UniValue &vReq)
Definition: server.cpp:421
void RPCSetTimerInterfaceIfUnset(RPCTimerInterface *iface)
Set the factory function for timer, but only, if unset.
Definition: server.cpp:533
UniValue(* rpcfn_type)(const JSONRPCRequest &jsonRequest)
Definition: server.h:129
Wrapper for UniValue::VType, which includes typeAny: Used to denote don&#39;t care type.
Definition: server.h:33
bool RPCIsInWarmup(std::string *outStatus)
Definition: server.cpp:354