| 350 | static int getNextRequestId() { return request_id_counter_++; } |
| 351 | |
| 352 | nlohmann::json sendJsonRpc(const std::string &method, |
| 353 | const nlohmann::json ¶ms) const { |
| 354 | CURL *curl; |
| 355 | CURLcode res; |
| 356 | std::string readBuffer; |
| 357 | |
| 358 | curl = curl_easy_init(); |
| 359 | if (curl) { |
| 360 | struct curl_slist *headers = NULL; |
| 361 | headers = curl_slist_append(headers, "Content-Type: application/json"); |
| 362 | |
| 363 | nlohmann::json request = {{"jsonrpc", "2.0"}, |
| 364 | {"method", method}, |
| 365 | {"params", params}, |
| 366 | {"id", getNextRequestId()}}; |
| 367 | |
| 368 | std::string request_str = request.dump(); |
| 369 | |
| 370 | curl_easy_setopt(curl, CURLOPT_URL, rpc_url_.c_str()); |
| 371 | curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); |
| 372 | curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request_str.c_str()); |
| 373 | curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); |
| 374 | curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); |
| 375 | res = curl_easy_perform(curl); |
| 376 | curl_easy_cleanup(curl); |
| 377 | curl_slist_free_all(headers); |
| 378 | |
| 379 | if (res != CURLE_OK) { |
| 380 | throw std::runtime_error("curl_easy_perform() failed: " + |
| 381 | std::string(curl_easy_strerror(res))); |
| 382 | } |
| 383 | |
| 384 | auto response_json = nlohmann::json::parse(readBuffer); |
| 385 | if (response_json.contains("error")) { |
| 386 | throw std::runtime_error("RPC error: " + response_json["error"].dump()); |
| 387 | } |
| 388 | return response_json; |
| 389 | } |
| 390 | throw std::runtime_error("curl_easy_init() failed"); |
| 391 | } |
| 392 | |
| 393 | // Helper to call the abiEncode.ts script |
| 394 | std::string abiEncode(const std::string &functionName, const std::string &abi, |
nothing calls this directly
no outgoing calls
no test coverage detected