Skip to content

Commit 357c266

Browse files
Refactory send request
1 parent db8ae0a commit 357c266

4 files changed

Lines changed: 170 additions & 514 deletions

File tree

src/cpp/common/py_monero_common.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ PyMoneroPathRequest::PyMoneroPathRequest(const std::string& method, const boost:
166166
PyMoneroPathRequest::PyMoneroPathRequest(const std::string& method, const std::shared_ptr<PyMoneroRequestParams>& params):
167167
m_params(params) {
168168
m_method = method;
169+
if (params == nullptr) m_params = std::make_shared<PyMoneroRequestEmptyParams>();
169170
}
170171

171172
PyMoneroBinaryRequest::PyMoneroBinaryRequest(const std::string& method, const boost::optional<py::object>& params) {
@@ -212,6 +213,7 @@ PyMoneroJsonRequest::PyMoneroJsonRequest(const std::string& method, const std::s
212213
m_id("0"),
213214
m_params(params) {
214215
m_method = method;
216+
if (params == nullptr) m_params = boost::none;
215217
}
216218

217219

src/cpp/common/py_monero_common.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,14 @@ class PyMoneroRpcConnection : public monero::monero_rpc_connection {
281281
bool is_connected() const;
282282
bool check_connection(const boost::optional<int>& timeout_ms = boost::none);
283283

284+
inline const boost::property_tree::ptree send_json_request(const std::string& path, const std::shared_ptr<PyMoneroJsonRequestParams>& params = nullptr) {
285+
PyMoneroJsonRequest request(path, params);
286+
auto response = send_json_request(request);
287+
288+
if (response->m_result == boost::none) throw std::runtime_error("Invalid Monero JSONRPC response");
289+
return response->m_result.get();
290+
}
291+
284292
inline const std::shared_ptr<PyMoneroJsonResponse> send_json_request(const PyMoneroJsonRequest &request, std::chrono::milliseconds timeout = std::chrono::seconds(15)) {
285293
PyMoneroJsonResponse response;
286294

@@ -290,6 +298,14 @@ class PyMoneroRpcConnection : public monero::monero_rpc_connection {
290298
return std::make_shared<PyMoneroJsonResponse>(response);
291299
}
292300

301+
inline const boost::property_tree::ptree send_path_request(const std::string& path, const std::shared_ptr<PyMoneroRequestParams>& params = nullptr) {
302+
PyMoneroPathRequest request(path, params);
303+
auto response = send_path_request(request);
304+
305+
if (response->m_response == boost::none) throw std::runtime_error("Invalid Monero path response");
306+
return response->m_response.get();
307+
}
308+
293309
inline const std::shared_ptr<PyMoneroPathResponse> send_path_request(const PyMoneroPathRequest &request, std::chrono::milliseconds timeout = std::chrono::seconds(15)) {
294310
PyMoneroPathResponse response;
295311

0 commit comments

Comments
 (0)