| 429 | } |
| 430 | |
| 431 | static RPCHelpMan waitforblockheight() |
| 432 | { |
| 433 | return RPCHelpMan{"waitforblockheight", |
| 434 | "\nWaits for (at least) block height and returns the height and hash\n" |
| 435 | "of the current tip.\n" |
| 436 | "\nReturns the current block on timeout or exit.\n", |
| 437 | { |
| 438 | {"height", RPCArg::Type::NUM, RPCArg::Optional::NO, "Block height to wait for."}, |
| 439 | {"timeout", RPCArg::Type::NUM, RPCArg::Default{0}, "Time in milliseconds to wait for a response. 0 indicates no timeout."}, |
| 440 | }, |
| 441 | RPCResult{ |
| 442 | RPCResult::Type::OBJ, "", "", |
| 443 | { |
| 444 | {RPCResult::Type::STR_HEX, "hash", "The blockhash"}, |
| 445 | {RPCResult::Type::NUM, "height", "Block height"}, |
| 446 | }}, |
| 447 | RPCExamples{ |
| 448 | HelpExampleCli("waitforblockheight", "100 1000") |
| 449 | + HelpExampleRpc("waitforblockheight", "100, 1000") |
| 450 | }, |
| 451 | [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue |
| 452 | { |
| 453 | int timeout = 0; |
| 454 | |
| 455 | int height = request.params[0].get_int(); |
| 456 | |
| 457 | if (!request.params[1].isNull()) |
| 458 | timeout = request.params[1].get_int(); |
| 459 | |
| 460 | CUpdatedBlock block; |
| 461 | { |
| 462 | WAIT_LOCK(cs_blockchange, lock); |
| 463 | if(timeout) |
| 464 | cond_blockchange.wait_for(lock, std::chrono::milliseconds(timeout), [&height]() EXCLUSIVE_LOCKS_REQUIRED(cs_blockchange) {return latestblock.height >= height || !IsRPCRunning();}); |
| 465 | else |
| 466 | cond_blockchange.wait(lock, [&height]() EXCLUSIVE_LOCKS_REQUIRED(cs_blockchange) {return latestblock.height >= height || !IsRPCRunning(); }); |
| 467 | block = latestblock; |
| 468 | } |
| 469 | UniValue ret(UniValue::VOBJ); |
| 470 | ret.pushKV("hash", block.hash.GetHex()); |
| 471 | ret.pushKV("height", block.height); |
| 472 | return ret; |
| 473 | }, |
| 474 | }; |
| 475 | } |
| 476 | |
| 477 | static RPCHelpMan syncwithvalidationinterfacequeue() |
| 478 | { |
nothing calls this directly
no test coverage detected