aboutsummaryrefslogtreecommitdiff
path: root/src/init.cpp
diff options
context:
space:
mode:
authorCory Fields <cory-nospam-@coryfields.com>2016-09-01 21:55:21 -0400
committerCory Fields <cory-nospam-@coryfields.com>2016-09-07 12:46:01 -0400
commitd6a5dc4a2eaa0d7348804254ca09e75fc3a858ab (patch)
treedd60ab61035edb6e519f9f69b4d80d48de079ff2 /src/init.cpp
parent5b2ea29cf4fd298346437bb16a54407f8c1f9dca (diff)
downloadbitcoin-d6a5dc4a2eaa0d7348804254ca09e75fc3a858ab.tar.xz
add waitfornewblock/waitforblock/waitforblockheight rpcs and use them for tests
waitfornewblock waits until a new block is received, or the timeout expires, then returns the current block height/hash. waitforblock waits for a specific blockhash, or until the timeout expires, then returns the current block height/hash. If the target blockhash is the current tip, it will return immediately. waitforblockheight waits until the tip has reached a certain height or higher, then returns the current height and hash. waitforblockheight is used to avoid polling in the rpc tests.
Diffstat (limited to 'src/init.cpp')
-rw-r--r--src/init.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 27843fa882..64e161b9b2 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -280,9 +280,15 @@ bool static Bind(const CService &addr, unsigned int flags) {
}
return true;
}
+void OnRPCStarted()
+{
+ uiInterface.NotifyBlockTip.connect(&RPCNotifyBlockChange);
+}
void OnRPCStopped()
{
+ uiInterface.NotifyBlockTip.disconnect(&RPCNotifyBlockChange);
+ RPCNotifyBlockChange(false, nullptr);
cvBlockChange.notify_all();
LogPrint("rpc", "RPC stopped.\n");
}
@@ -666,6 +672,7 @@ bool InitSanityCheck(void)
bool AppInitServers(boost::thread_group& threadGroup)
{
+ RPCServer::OnStarted(&OnRPCStarted);
RPCServer::OnStopped(&OnRPCStopped);
RPCServer::OnPreCommand(&OnRPCPreCommand);
if (!InitHTTPServer())
@@ -1357,6 +1364,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
{
LOCK(cs_main);
CBlockIndex* tip = chainActive.Tip();
+ RPCNotifyBlockChange(true, tip);
if (tip && tip->nTime > GetAdjustedTime() + 2 * 60 * 60) {
strLoadError = _("The block database contains a block which appears to be from the future. "
"This may be due to your computer's date and time being set incorrectly. "