| 18 | using namespace cn; |
| 19 | |
| 20 | bool Node::on_json_rpc(http::Client *who, http::RequestBody &&request, http::ResponseBody &response) { |
| 21 | response.r.headers.push_back({"Content-Type", "application/json; charset=utf-8"}); |
| 22 | |
| 23 | common::JsonValue jid(nullptr); |
| 24 | bool nas = false; |
| 25 | |
| 26 | try { |
| 27 | json_rpc::Request json_req(request.body); |
| 28 | jid = json_req.get_id().get(); |
| 29 | nas = json_req.get_numbers_as_strings(); |
| 30 | |
| 31 | auto it = m_jsonrpc_handlers.find(json_req.get_method()); |
| 32 | if (it == m_jsonrpc_handlers.end()) { |
| 33 | m_log(logging::INFO) << "jsonrpc request method not found - " << json_req.get_method(); |
| 34 | if (WalletNode::m_jsonrpc_handlers.count(json_req.get_method()) != 0) |
| 35 | throw json_rpc::Error(json_rpc::METHOD_NOT_FOUND, |
| 36 | "Method not found " + json_req.get_method() + |
| 37 | " (attempt to call walletd method on " CRYPTONOTE_NAME "d)"); |
| 38 | throw json_rpc::Error(json_rpc::METHOD_NOT_FOUND, "Method not found " + json_req.get_method()); |
| 39 | } |
| 40 | std::string response_body; |
| 41 | if (!it->second(this, who, std::move(request), std::move(json_req), response_body)) |
| 42 | return false; |
| 43 | response.set_body(std::move(response_body)); |
| 44 | } catch (const json_rpc::Error &err) { |
| 45 | response.set_body(json_rpc::create_error_response_body(err, jid, nas)); |
| 46 | } catch (const std::exception &e) { |
| 47 | json_rpc::Error json_err(json_rpc::INTERNAL_ERROR, common::what(e)); |
| 48 | response.set_body(json_rpc::create_error_response_body(json_err, jid, nas)); |
| 49 | } |
| 50 | response.r.status = 200; |
| 51 | return true; |
| 52 | } |
| 53 | |
| 54 | bool Node::on_binary_rpc(http::Client *who, http::RequestBody &&request, http::ResponseBody &response) { |
| 55 | response.r.headers.push_back({"Content-Type", "application/octet-stream"}); |
nothing calls this directly
no test coverage detected