| 341 | } |
| 342 | |
| 343 | static RPCHelpMan waitfornewblock() |
| 344 | { |
| 345 | return RPCHelpMan{"waitfornewblock", |
| 346 | "\nWaits for a specific new block and returns useful info about it.\n" |
| 347 | "\nReturns the current block on timeout or exit.\n", |
| 348 | { |
| 349 | {"timeout", RPCArg::Type::NUM, RPCArg::Default{0}, "Time in milliseconds to wait for a response. 0 indicates no timeout."}, |
| 350 | }, |
| 351 | RPCResult{ |
| 352 | RPCResult::Type::OBJ, "", "", |
| 353 | { |
| 354 | {RPCResult::Type::STR_HEX, "hash", "The blockhash"}, |
| 355 | {RPCResult::Type::NUM, "height", "Block height"}, |
| 356 | }}, |
| 357 | RPCExamples{ |
| 358 | HelpExampleCli("waitfornewblock", "1000") |
| 359 | + HelpExampleRpc("waitfornewblock", "1000") |
| 360 | }, |
| 361 | [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue |
| 362 | { |
| 363 | int timeout = 0; |
| 364 | if (!request.params[0].isNull()) |
| 365 | timeout = request.params[0].get_int(); |
| 366 | |
| 367 | CUpdatedBlock block; |
| 368 | { |
| 369 | WAIT_LOCK(cs_blockchange, lock); |
| 370 | block = latestblock; |
| 371 | if(timeout) |
| 372 | cond_blockchange.wait_for(lock, std::chrono::milliseconds(timeout), [&block]() EXCLUSIVE_LOCKS_REQUIRED(cs_blockchange) {return latestblock.height != block.height || latestblock.hash != block.hash || !IsRPCRunning(); }); |
| 373 | else |
| 374 | cond_blockchange.wait(lock, [&block]() EXCLUSIVE_LOCKS_REQUIRED(cs_blockchange) {return latestblock.height != block.height || latestblock.hash != block.hash || !IsRPCRunning(); }); |
| 375 | block = latestblock; |
| 376 | } |
| 377 | UniValue ret(UniValue::VOBJ); |
| 378 | ret.pushKV("hash", block.hash.GetHex()); |
| 379 | ret.pushKV("height", block.height); |
| 380 | return ret; |
| 381 | }, |
| 382 | }; |
| 383 | } |
| 384 | |
| 385 | static RPCHelpMan waitforblock() |
| 386 | { |
nothing calls this directly
no test coverage detected