MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / waitforblockheight

Function waitforblockheight

src/rpc/blockchain.cpp:304–344  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

302}
303
304static UniValue waitforblockheight(const JSONRPCRequest& request)
305{
306 if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
307 throw std::runtime_error(
308 "waitforblockheight <height> (timeout)\n"
309 "\nWaits for (at least) block height and returns the height and hash\n"
310 "of the current tip.\n"
311 "\nReturns the current block on timeout or exit.\n"
312 "\nArguments:\n"
313 "1. height (required, int) Block height to wait for (int)\n"
314 "2. timeout (int, optional, default=0) Time in milliseconds to wait for a response. 0 indicates no timeout.\n"
315 "\nResult:\n"
316 "{ (json object)\n"
317 " \"hash\" : { (string) The blockhash\n"
318 " \"height\" : { (int) Block height\n"
319 "}\n"
320 "\nExamples:\n"
321 + HelpExampleCli("waitforblockheight", "\"100\", 1000")
322 + HelpExampleRpc("waitforblockheight", "\"100\", 1000")
323 );
324 int timeout = 0;
325
326 int height = request.params[0].get_int();
327
328 if (!request.params[1].isNull())
329 timeout = request.params[1].get_int();
330
331 CUpdatedBlock block;
332 {
333 std::unique_lock<std::mutex> lock(cs_blockchange);
334 if(timeout)
335 cond_blockchange.wait_for(lock, std::chrono::milliseconds(timeout), [&height]{return latestblock.height >= height || !IsRPCRunning();});
336 else
337 cond_blockchange.wait(lock, [&height]{return latestblock.height >= height || !IsRPCRunning(); });
338 block = latestblock;
339 }
340 UniValue ret(UniValue::VOBJ);
341 ret.pushKV("hash", block.hash.GetHex());
342 ret.pushKV("height", block.height);
343 return ret;
344}
345
346static UniValue syncwithvalidationinterfacequeue(const JSONRPCRequest& request)
347{

Callers

nothing calls this directly

Calls 9

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
IsRPCRunningFunction · 0.85
get_intMethod · 0.80
isNullMethod · 0.80
waitMethod · 0.80
sizeMethod · 0.45
pushKVMethod · 0.45
GetHexMethod · 0.45

Tested by

no test coverage detected