| 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"}); |
| 56 | |
| 57 | common::JsonValue jid(nullptr); |
| 58 | try { |
| 59 | size_t sep = request.body.find(char(0)); |
| 60 | if (sep == std::string::npos) |
| 61 | throw std::runtime_error("binary request contains no 0-character separator"); |
| 62 | json_rpc::Request binary_req(request.body.substr(0, sep)); |
| 63 | jid = binary_req.get_id().get(); |
| 64 | |
| 65 | common::MemoryInputStream body_stream(request.body.data() + sep + 1, request.body.size() - sep - 1); |
| 66 | |
| 67 | auto it = m_binaryrpc_handlers.find(binary_req.get_method()); |
| 68 | if (it == m_binaryrpc_handlers.end()) { |
| 69 | m_log(logging::INFO) << "binaryrpc request method not found - " << binary_req.get_method(); |
| 70 | throw json_rpc::Error(json_rpc::METHOD_NOT_FOUND, "Method not found " + binary_req.get_method()); |
| 71 | } |
| 72 | std::string response_body; |
| 73 | if (!it->second(this, who, body_stream, std::move(binary_req), response_body)) |
| 74 | return false; |
| 75 | response.set_body(std::move(response_body)); |
| 76 | } catch (const json_rpc::Error &err) { |
| 77 | response.set_body(json_rpc::create_binary_response_error_body(err, jid)); |
| 78 | } catch (const std::exception &e) { |
| 79 | json_rpc::Error json_err(json_rpc::INTERNAL_ERROR, common::what(e)); |
| 80 | response.set_body(json_rpc::create_binary_response_error_body(json_err, jid)); |
| 81 | } |
| 82 | response.r.status = 200; |
| 83 | return true; |
| 84 | } |
| 85 | |
| 86 | bool Node::on_getblocktemplate(http::Client *who, http::RequestBody &&raw_request, json_rpc::Request &&raw_js_request, |
| 87 | api::cnd::GetBlockTemplate::Request &&req, api::cnd::GetBlockTemplate::Response &res) { |