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

Function waitfornewblock

src/rpc/blockchain.cpp:224–260  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

222}
223
224static UniValue waitfornewblock(const JSONRPCRequest& request)
225{
226 if (request.fHelp || request.params.size() > 1)
227 throw std::runtime_error(
228 "waitfornewblock (timeout)\n"
229 "\nWaits for a specific new block and returns useful info about it.\n"
230 "\nReturns the current block on timeout or exit.\n"
231 "\nArguments:\n"
232 "1. timeout (int, optional, default=0) Time in milliseconds to wait for a response. 0 indicates no timeout.\n"
233 "\nResult:\n"
234 "{ (json object)\n"
235 " \"hash\" : { (string) The blockhash\n"
236 " \"height\" : { (int) Block height\n"
237 "}\n"
238 "\nExamples:\n"
239 + HelpExampleCli("waitfornewblock", "1000")
240 + HelpExampleRpc("waitfornewblock", "1000")
241 );
242 int timeout = 0;
243 if (!request.params[0].isNull())
244 timeout = request.params[0].get_int();
245
246 CUpdatedBlock block;
247 {
248 std::unique_lock<std::mutex> lock(cs_blockchange);
249 block = latestblock;
250 if(timeout)
251 cond_blockchange.wait_for(lock, std::chrono::milliseconds(timeout), [&block]{return latestblock.height != block.height || latestblock.hash != block.hash || !IsRPCRunning(); });
252 else
253 cond_blockchange.wait(lock, [&block]{return latestblock.height != block.height || latestblock.hash != block.hash || !IsRPCRunning(); });
254 block = latestblock;
255 }
256 UniValue ret(UniValue::VOBJ);
257 ret.pushKV("hash", block.hash.GetHex());
258 ret.pushKV("height", block.height);
259 return ret;
260}
261
262static UniValue waitforblock(const JSONRPCRequest& request)
263{

Callers

nothing calls this directly

Calls 9

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 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