Electroneum
cryptonote::rpc::FullMessage Class Reference

#include <message.h>

Public Member Functions

 ~FullMessage ()
 
 FullMessage (FullMessage &&rhs) noexcept
 
 FullMessage (const std::string &json_string, bool request=false)
 
std::string getJson ()
 
std::string getRequestType () const
 
rapidjson::ValuegetMessage ()
 
rapidjson::Value getMessageCopy ()
 
rapidjson::ValuegetID ()
 
void setID (rapidjson::Value &id)
 
cryptonote::rpc::error getError ()
 

Static Public Member Functions

static FullMessage requestMessage (const std::string &request, Message *message)
 
static FullMessage requestMessage (const std::string &request, Message *message, rapidjson::Value &id)
 
static FullMessage responseMessage (Message *message)
 
static FullMessage responseMessage (Message *message, rapidjson::Value &id)
 
static FullMessagetimeoutMessage ()
 

Detailed Description

Definition at line 81 of file message.h.

Constructor & Destructor Documentation

◆ ~FullMessage()

cryptonote::rpc::FullMessage::~FullMessage ( )
inline

Definition at line 84 of file message.h.

84 { }

◆ FullMessage() [1/2]

cryptonote::rpc::FullMessage::FullMessage ( FullMessage &&  rhs)
inlinenoexcept

Definition at line 86 of file message.h.

86 : doc(std::move(rhs.doc)) { }
const T & move(const T &t)
Definition: gtest-port.h:1317

◆ FullMessage() [2/2]

cryptonote::rpc::FullMessage::FullMessage ( const std::string &  json_string,
bool  request = false 
)

Definition at line 111 of file message.cpp.

112 {
113  doc.Parse(json_string.c_str());
114  if (doc.HasParseError() || !doc.IsObject())
115  {
117  }
118 
119  OBJECT_HAS_MEMBER_OR_THROW(doc, "jsonrpc")
120 
121  if (request)
122  {
123  OBJECT_HAS_MEMBER_OR_THROW(doc, method_field)
124  OBJECT_HAS_MEMBER_OR_THROW(doc, params_field)
125  }
126  else
127  {
128  if (!doc.HasMember(result_field) && !doc.HasMember(error_field))
129  {
130  throw cryptonote::json::MISSING_KEY("error/result");
131  }
132  }
133 }
#define OBJECT_HAS_MEMBER_OR_THROW(val, key)
Definition: json_object.h:38
else if(0==res)

Member Function Documentation

◆ getError()

cryptonote::rpc::error cryptonote::rpc::FullMessage::getError ( )

Definition at line 201 of file message.cpp.

202 {
204  err.use = false;
205  if (doc.HasMember(error_field))
206  {
207  GET_FROM_JSON_OBJECT(doc, err, error);
208  err.use = true;
209  }
210 
211  return err;
212 }
#define GET_FROM_JSON_OBJECT(source, dst, key)
Definition: json_object.h:52
error
Tracks LMDB error codes.
Definition: error.h:44

◆ getID()

rapidjson::Value & cryptonote::rpc::FullMessage::getID ( )

Definition at line 182 of file message.cpp.

183 {
184  OBJECT_HAS_MEMBER_OR_THROW(doc, id_field)
185  return doc[id_field];
186 }
#define OBJECT_HAS_MEMBER_OR_THROW(val, key)
Definition: json_object.h:38
Here is the caller graph for this function:

◆ getJson()

std::string cryptonote::rpc::FullMessage::getJson ( )

Definition at line 135 of file message.cpp.

136 {
137 
138  if (!doc.HasMember(id_field))
139  {
140  doc.AddMember(id_field, rapidjson::Value("unused"), doc.GetAllocator());
141  }
142 
144 
145  rapidjson::Writer<rapidjson::StringBuffer> writer(buf);
146 
147  doc.Accept(writer);
148 
149  return std::string(buf.GetString(), buf.GetSize());
150 }
::std::string string
Definition: gtest-port.h:1097
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:2116
GenericStringBuffer< UTF8< char >, CrtAllocator > StringBuffer
Definition: fwd.h:59
const char * buf
Definition: slow_memmem.cpp:74
Here is the caller graph for this function:

◆ getMessage()

rapidjson::Value & cryptonote::rpc::FullMessage::getMessage ( )

Definition at line 158 of file message.cpp.

159 {
160  if (doc.HasMember(params_field))
161  {
162  return doc[params_field];
163  }
164  else if (doc.HasMember(result_field))
165  {
166  return doc[result_field];
167  }
168 
169  //else
170  OBJECT_HAS_MEMBER_OR_THROW(doc, error_field)
171  return doc[error_field];
172 
173 }
#define OBJECT_HAS_MEMBER_OR_THROW(val, key)
Definition: json_object.h:38
Here is the caller graph for this function:

◆ getMessageCopy()

rapidjson::Value cryptonote::rpc::FullMessage::getMessageCopy ( )

Definition at line 175 of file message.cpp.

176 {
177  rapidjson::Value& val = getMessage();
178 
179  return rapidjson::Value(val, doc.GetAllocator());
180 }
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:2116
rapidjson::Value & getMessage()
Definition: message.cpp:158
Here is the call graph for this function:

◆ getRequestType()

std::string cryptonote::rpc::FullMessage::getRequestType ( ) const

Definition at line 152 of file message.cpp.

153 {
154  OBJECT_HAS_MEMBER_OR_THROW(doc, method_field)
155  return doc[method_field].GetString();
156 }
#define OBJECT_HAS_MEMBER_OR_THROW(val, key)
Definition: json_object.h:38
Here is the caller graph for this function:

◆ requestMessage() [1/2]

FullMessage cryptonote::rpc::FullMessage::requestMessage ( const std::string &  request,
Message message 
)
static

Definition at line 214 of file message.cpp.

215 {
216  return FullMessage(request, message);
217 }
std::string message("Message requiring signing")
FullMessage(FullMessage &&rhs) noexcept
Definition: message.h:86
Here is the call graph for this function:
Here is the caller graph for this function:

◆ requestMessage() [2/2]

FullMessage cryptonote::rpc::FullMessage::requestMessage ( const std::string &  request,
Message message,
rapidjson::Value id 
)
static

Definition at line 219 of file message.cpp.

220 {
221  auto mes = requestMessage(request, message);
222  mes.setID(id);
223  return mes;
224 }
static FullMessage requestMessage(const std::string &request, Message *message)
Definition: message.cpp:214
std::string message("Message requiring signing")
Here is the call graph for this function:

◆ responseMessage() [1/2]

FullMessage cryptonote::rpc::FullMessage::responseMessage ( Message message)
static

Definition at line 226 of file message.cpp.

227 {
228  return FullMessage(message);
229 }
std::string message("Message requiring signing")
FullMessage(FullMessage &&rhs) noexcept
Definition: message.h:86
Here is the call graph for this function:
Here is the caller graph for this function:

◆ responseMessage() [2/2]

FullMessage cryptonote::rpc::FullMessage::responseMessage ( Message message,
rapidjson::Value id 
)
static

Definition at line 231 of file message.cpp.

232 {
233  auto mes = responseMessage(message);
234  mes.setID(id);
235  return mes;
236 }
std::string message("Message requiring signing")
static FullMessage responseMessage(Message *message)
Definition: message.cpp:226
Here is the call graph for this function:

◆ setID()

void cryptonote::rpc::FullMessage::setID ( rapidjson::Value id)

Definition at line 188 of file message.cpp.

189 {
190  auto itr = doc.FindMember(id_field);
191  if (itr != doc.MemberEnd())
192  {
193  itr->value = id;
194  }
195  else
196  {
197  doc.AddMember(id_field, id, doc.GetAllocator());
198  }
199 }

◆ timeoutMessage()

FullMessage * cryptonote::rpc::FullMessage::timeoutMessage ( )
static

Definition at line 238 of file message.cpp.

239 {
240  auto *full_message = new FullMessage();
241 
242  auto& doc = full_message->doc;
243  auto& al = full_message->doc.GetAllocator();
244 
245  doc.SetObject();
246 
247  // required by JSON-RPC 2.0 spec
248  doc.AddMember("jsonrpc", "2.0", al);
249 
251 
252  err.error_str = "RPC request timed out.";
253  INSERT_INTO_JSON_OBJECT(doc, doc, err, err);
254 
255  return full_message;
256 }
#define INSERT_INTO_JSON_OBJECT(jsonVal, doc, key, source)
Definition: json_object.h:47
FullMessage(FullMessage &&rhs) noexcept
Definition: message.h:86

The documentation for this class was generated from the following files: