Advertisement
Guest User

isinitialized bitcoin RPC patch

a guest
Feb 14th, 2011
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.37 KB | None | 0 0
  1. diff --git a/init.cpp b/init.cpp
  2. index 04bdd68..52cf7a1 100644
  3. --- a/init.cpp
  4. +++ b/init.cpp
  5. @@ -115,6 +115,7 @@ bool AppInit(int argc, char* argv[])
  6.      } catch (...) {
  7.          PrintException(NULL, "AppInit()");
  8.      }
  9. +    fInitializationCompleted = true;
  10.      if (!fRet)
  11.          Shutdown(NULL);
  12.      return fRet;
  13. @@ -122,6 +123,9 @@ bool AppInit(int argc, char* argv[])
  14.  
  15.  bool AppInit2(int argc, char* argv[])
  16.  {
  17. +    if (GetBoolArg("-server") || fDaemon)
  18. +        CreateThread(ThreadRPCServer, NULL);
  19. +
  20.  #ifdef _MSC_VER
  21.      // Turn off microsoft heap dump noise
  22.      _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
  23. @@ -443,9 +447,6 @@ bool AppInit2(int argc, char* argv[])
  24.      if (!CreateThread(StartNode, NULL))
  25.          wxMessageBox("Error: CreateThread(StartNode) failed", "Bitcoin");
  26.  
  27. -    if (GetBoolArg("-server") || fDaemon)
  28. -        CreateThread(ThreadRPCServer, NULL);
  29. -
  30.  #if defined(__WXMSW__) && defined(GUI)
  31.      if (fFirstRun)
  32.          SetStartOnSystemStartup(true);
  33. diff --git a/rpc.cpp b/rpc.cpp
  34. index 69b09bc..72fc9a8 100644
  35. --- a/rpc.cpp
  36. +++ b/rpc.cpp
  37. @@ -28,6 +28,8 @@ void ThreadRPCServer2(void* parg);
  38.  typedef Value(*rpcfn_type)(const Array& params, bool fHelp);
  39.  extern map<string, rpcfn_type> mapCallTable;
  40.  
  41. +bool fInitializationCompleted = false;
  42. +
  43.  
  44.  Object JSONRPCError(int code, const string& message)
  45.  {
  46. @@ -146,7 +148,6 @@ Value help(const Array& params, bool fHelp)
  47.      return strRet;
  48.  }
  49.  
  50. -
  51.  Value stop(const Array& params, bool fHelp)
  52.  {
  53.      if (fHelp || params.size() != 0)
  54. @@ -277,18 +278,22 @@ Value getinfo(const Array& params, bool fHelp)
  55.  
  56.      Object obj;
  57.      obj.push_back(Pair("version",       (int)VERSION));
  58. -    obj.push_back(Pair("balance",       (double)GetBalance() / (double)COIN));
  59. -    obj.push_back(Pair("blocks",        (int)nBestHeight));
  60. -    obj.push_back(Pair("connections",   (int)vNodes.size()));
  61. -    obj.push_back(Pair("proxy",         (fUseProxy ? addrProxy.ToStringIPPort() : string())));
  62. -    obj.push_back(Pair("generate",      (bool)fGenerateBitcoins));
  63. -    obj.push_back(Pair("genproclimit",  (int)(fLimitProcessors ? nLimitProcessors : -1)));
  64. -    obj.push_back(Pair("difficulty",    (double)GetDifficulty()));
  65. -    obj.push_back(Pair("hashespersec",  gethashespersec(params, false)));
  66. -    obj.push_back(Pair("testnet",       fTestNet));
  67. -    obj.push_back(Pair("keypoololdest", (boost::int64_t)GetOldestKeyPoolTime()));
  68. -    obj.push_back(Pair("paytxfee",      (double)nTransactionFee / (double)COIN));
  69. -    obj.push_back(Pair("errors",        GetWarnings("statusbar")));
  70. +    obj.push_back(Pair("isinitialized", (bool)fInitializationCompleted));
  71. +    if (fInitializationCompleted)
  72. +    {
  73. +        obj.push_back(Pair("balance",       (double)GetBalance() / (double)COIN));
  74. +        obj.push_back(Pair("blocks",        (int)nBestHeight));
  75. +        obj.push_back(Pair("connections",   (int)vNodes.size()));
  76. +        obj.push_back(Pair("proxy",         (fUseProxy ? addrProxy.ToStringIPPort() : string())));
  77. +        obj.push_back(Pair("generate",      (bool)fGenerateBitcoins));
  78. +        obj.push_back(Pair("genproclimit",  (int)(fLimitProcessors ? nLimitProcessors : -1)));
  79. +        obj.push_back(Pair("difficulty",    (double)GetDifficulty()));
  80. +        obj.push_back(Pair("hashespersec",  gethashespersec(params, false)));
  81. +        obj.push_back(Pair("testnet",       fTestNet));
  82. +        obj.push_back(Pair("keypoololdest", (boost::int64_t)GetOldestKeyPoolTime()));
  83. +        obj.push_back(Pair("paytxfee",      (double)nTransactionFee / (double)COIN));
  84. +        obj.push_back(Pair("errors",        GetWarnings("statusbar")));
  85. +    }
  86.      return obj;
  87.  }
  88.  
  89. @@ -1806,6 +1811,8 @@ void ThreadRPCServer2(void* parg)
  90.              if (valMethod.type() != str_type)
  91.                  throw JSONRPCError(-32600, "Method must be a string");
  92.              string strMethod = valMethod.get_str();
  93. +            if (!fInitializationCompleted && strMethod != "help" && strMethod != "getinfo")
  94. +                throw JSONRPCError(-42000, "Still initializing");
  95.              if (strMethod != "getwork")
  96.                  printf("ThreadRPCServer method=%s\n", strMethod.c_str());
  97.  
  98. diff --git a/rpc.h b/rpc.h
  99. index 48a7b8a..85c3ef3 100644
  100. --- a/rpc.h
  101. +++ b/rpc.h
  102. @@ -4,3 +4,4 @@
  103.  
  104.  void ThreadRPCServer(void* parg);
  105.  int CommandLineRPC(int argc, char *argv[]);
  106. +extern bool fInitializationCompleted;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement