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

Function waitforblock

src/rpc/blockchain.cpp:262–302  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

260}
261
262static UniValue waitforblock(const JSONRPCRequest& request)
263{
264 if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
265 throw std::runtime_error(
266 "waitforblock <blockhash> (timeout)\n"
267 "\nWaits for a specific new block and returns useful info about it.\n"
268 "\nReturns the current block on timeout or exit.\n"
269 "\nArguments:\n"
270 "1. \"blockhash\" (required, string) Block hash to wait for.\n"
271 "2. timeout (int, optional, default=0) Time in milliseconds to wait for a response. 0 indicates no timeout.\n"
272 "\nResult:\n"
273 "{ (json object)\n"
274 " \"hash\" : { (string) The blockhash\n"
275 " \"height\" : { (int) Block height\n"
276 "}\n"
277 "\nExamples:\n"
278 + HelpExampleCli("waitforblock", "\"0000000000079f8ef3d2c688c244eb7a4570b24c9ed7b4a8c619eb02596f8862\", 1000")
279 + HelpExampleRpc("waitforblock", "\"0000000000079f8ef3d2c688c244eb7a4570b24c9ed7b4a8c619eb02596f8862\", 1000")
280 );
281 int timeout = 0;
282
283 uint256 hash = uint256S(request.params[0].get_str());
284
285 if (!request.params[1].isNull())
286 timeout = request.params[1].get_int();
287
288 CUpdatedBlock block;
289 {
290 std::unique_lock<std::mutex> lock(cs_blockchange);
291 if(timeout)
292 cond_blockchange.wait_for(lock, std::chrono::milliseconds(timeout), [&hash]{return latestblock.hash == hash || !IsRPCRunning();});
293 else
294 cond_blockchange.wait(lock, [&hash]{return latestblock.hash == hash || !IsRPCRunning(); });
295 block = latestblock;
296 }
297
298 UniValue ret(UniValue::VOBJ);
299 ret.pushKV("hash", block.hash.GetHex());
300 ret.pushKV("height", block.height);
301 return ret;
302}
303
304static UniValue waitforblockheight(const JSONRPCRequest& request)
305{

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected