Advertisement
Guest User

monitortx

a guest
May 25th, 2011
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.04 KB | None | 0 0
  1. diff --cc src/db.h
  2. index 9826194,a8bb073..0000000
  3. --- a/src/db.h
  4. +++ b/src/db.h
  5. @@@ -447,18 -437,34 +447,36 @@@ public
  6. }
  7.  
  8. template<typename T>
  9. - bool WriteSetting(const string& strKey, const T& value)
  10. + bool WriteSetting(const std::string& strKey, const T& value)
  11. {
  12. nWalletDBUpdated++;
  13. - return Write(make_pair(string("setting"), strKey), value);
  14. + return Write(std::make_pair(std::string("setting"), strKey), value);
  15. }
  16. - bool ReadAccount(const string& strAccount, CAccount& account);
  17. - bool WriteAccount(const string& strAccount, const CAccount& account);
  18. +
  19. + bool ReadAccount(const std::string& strAccount, CAccount& account);
  20. + bool WriteAccount(const std::string& strAccount, const CAccount& account);
  21. ++
  22. bool WriteAccountingEntry(const CAccountingEntry& acentry);
  23. - int64 GetAccountCreditDebit(const string& strAccount);
  24. - void ListAccountCreditDebit(const string& strAccount, list<CAccountingEntry>& acentries);
  25. + int64 GetAccountCreditDebit(const std::string& strAccount);
  26. + void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& acentries);
  27.  
  28. - bool ReadMonitorURLs(const string& what, set<string>& urls)
  29. ++ bool ReadMonitorURLs(const std::string& what, std::set<std::string>& urls)
  30. + {
  31. - return Read(make_pair(string("monitor"), what), urls);
  32. ++ return Read(make_pair(std::string("monitor"), what), urls);
  33. + }
  34. +
  35. - bool WriteMonitorURLs(const string& what, const set<string>& urls)
  36. ++ bool WriteMonitorURLs(const std::string& what, const std::set<std::string>& urls)
  37. + {
  38. + nWalletDBUpdated++;
  39. - return Write(make_pair(string("monitor"), what), urls);
  40. ++ return Write(make_pair(std::string("monitor"), what), urls);
  41. + }
  42. +
  43. - bool EraseMonitorURLs(const string& what)
  44. ++ bool EraseMonitorURLs(const std::string& what)
  45. + {
  46. + nWalletDBUpdated++;
  47. - return Erase(make_pair(string("monitor"), what));
  48. ++ return Erase(make_pair(std::string("monitor"), what));
  49. + }
  50. +
  51. bool LoadWallet();
  52. protected:
  53. void ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool);
  54. diff --git a/src/main.h b/src/main.h
  55. index 8635a6e..24f3b7f 100644
  56. --- a/src/main.h
  57. +++ b/src/main.h
  58. @@ -64,8 +64,8 @@ extern double dHashesPerSec;
  59. extern int64 nHPSTimerStart;
  60.  
  61. extern CCriticalSection cs_mapMonitored;
  62. -extern set<string> setMonitorTx; // set of urls listening for new transactions
  63. -extern set<string> setMonitorBlocks; // set of urls listening for new blocks
  64. +extern std::set<std::string> setMonitorTx; // set of urls listening for new transactions
  65. +extern std::set<std::string> setMonitorBlocks; // set of urls listening for new blocks
  66.  
  67. // Settings
  68. extern int fGenerateBitcoins;
  69. @@ -412,7 +412,7 @@ public:
  70. printf("%s\n", ToString().c_str());
  71. }
  72.  
  73. - string Address() const;
  74. + std::string Address() const;
  75. };
  76.  
  77.  
  78. diff --git a/src/rpcmonitor.cpp b/src/rpcmonitor.cpp
  79. index 05b21b2..1e2c2fa 100644
  80. --- a/src/rpcmonitor.cpp
  81. +++ b/src/rpcmonitor.cpp
  82. @@ -22,13 +22,13 @@ typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> SSLStream;
  83. using namespace boost::asio;
  84. using namespace json_spirit;
  85.  
  86. -extern string HTTPPost(const string& host, const string& path, const string& strMsg,
  87. - const map<string,string>& mapRequestHeaders);
  88. -extern string JSONRPCReply(const Value& result, const Value& error, const Value& id);
  89. -extern string JSONRPCRequest(const string& strMethod, const Array& params, const Value& id);
  90. -extern int ReadHTTP(std::basic_istream<char>& stream, map<string, string>& mapHeadersRet, string& strMessageRet);
  91. +extern std::string HTTPPost(const std::string& host, const std::string& path, const std::string& strMsg,
  92. + const std::map<std::string,std::string>& mapRequestHeaders);
  93. +extern std::string JSONRPCReply(const Value& result, const Value& error, const Value& id);
  94. +extern std::string JSONRPCRequest(const std::string& strMethod, const Array& params, const Value& id);
  95. +extern int ReadHTTP(std::basic_istream<char>& stream, std::map<std::string, std::string>& mapHeadersRet, std::string& strMessageRet);
  96. extern double GetDifficulty(const CBlockIndex* blockindex = pindexBest);
  97. -extern void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDepth, bool fLong, Array& ret);
  98. +extern void ListTransactions(const CWalletTx& wtx, const std::string& strAccount, int nMinDepth, bool fLong, Array& ret);
  99.  
  100.  
  101. void ThreadHTTPPOST2(void* parg);
  102. @@ -36,7 +36,7 @@ void ThreadHTTPPOST2(void* parg);
  103. class CPOSTRequest
  104. {
  105. public:
  106. - CPOSTRequest(const string &_url, const string& _body) : url(_url), body(_body)
  107. + CPOSTRequest(const std::string &_url, const std::string& _body) : url(_url), body(_body)
  108. {
  109. }
  110.  
  111. @@ -54,23 +54,23 @@ public:
  112. printf("URL PARSING FAILED: %s\n", url.c_str());
  113. return true;
  114. }
  115. - string protocol = urlparts[1];
  116. - string host = urlparts[2];
  117. - string s_port = urlparts[3]; // Note: includes colon, e.g. ":8080"
  118. + std::string protocol = urlparts[1];
  119. + std::string host = urlparts[2];
  120. + std::string s_port = urlparts[3]; // Note: includes colon, e.g. ":8080"
  121. bool fSSL = (protocol == "https" ? true : false);
  122. int port = (fSSL ? 443 : 80);
  123. if (s_port.size() > 1) { port = atoi(s_port.c_str()+1); }
  124. - string path = urlparts[4];
  125. - map<string, string> headers;
  126. + std::string path = urlparts[4];
  127. + std::map<std::string, std::string> headers;
  128.  
  129. #ifdef USE_SSL
  130. - asio::io_service io_service;
  131. - ssl::context context(io_service, ssl::context::sslv23);
  132. + boost::asio::io_service io_service;
  133. + ssl::context context = context(io_service, ssl::context::sslv23);
  134. context.set_options(ssl::context::no_sslv2);
  135. SSLStream sslStream(io_service, context);
  136. SSLIOStreamDevice d(sslStream, fSSL);
  137. iostreams::stream<SSLIOStreamDevice> stream(d);
  138. - if (!d.connect(host, lexical_cast<string>(port)))
  139. + if (!d.connect(host, lexical_cast<std::string>(port)))
  140. {
  141. printf("POST: Couldn't connect to %s:%d", host.c_str(), port);
  142. return false;
  143. @@ -81,12 +81,12 @@ public:
  144. printf("Cannot POST to SSL server, bitcoin compiled without full openssl libraries.");
  145. return false;
  146. }
  147. - ip::tcp::iostream stream(host, lexical_cast<string>(port));
  148. + ip::tcp::iostream stream(host, boost::lexical_cast<std::string>(port));
  149. #endif
  150.  
  151. stream << HTTPPost(host, path, body, headers) << std::flush;
  152. - map<string, string> mapResponseHeaders;
  153. - string strReply;
  154. + std::map<std::string, std::string> mapResponseHeaders;
  155. + std::string strReply;
  156. int status = ReadHTTP(stream, mapResponseHeaders, strReply);
  157. // printf(" HTTP response %d: %s\n", status, strReply.c_str());
  158.  
  159. @@ -94,11 +94,11 @@ public:
  160. }
  161.  
  162. protected:
  163. - string url;
  164. - string body;
  165. + std::string url;
  166. + std::string body;
  167. };
  168.  
  169. -static vector<shared_ptr<CPOSTRequest> > vPOSTQueue;
  170. +static std::vector<boost::shared_ptr<CPOSTRequest> > vPOSTQueue;
  171. static CCriticalSection cs_vPOSTQueue;
  172.  
  173.  
  174. @@ -113,7 +113,7 @@ Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex)
  175. result.push_back(Pair("nonce", (boost::uint64_t)block.nNonce));
  176. result.push_back(Pair("difficulty", GetDifficulty(blockindex)));
  177. Array txhashes;
  178. - foreach (const CTransaction&tx, block.vtx)
  179. + BOOST_FOREACH(const CTransaction&tx, block.vtx)
  180. txhashes.push_back(tx.GetHash().GetHex());
  181. result.push_back(Pair("tx", txhashes));
  182.  
  183. @@ -129,14 +129,14 @@ void monitorBlock(const CBlock& block, const CBlockIndex* pblockindex)
  184. Array params; // JSON-RPC requests are always "params" : [ ... ]
  185. params.push_back(blockToJSON(block, pblockindex));
  186.  
  187. - string postBody = JSONRPCRequest("monitorblock", params, Value());
  188. + std::string postBody = JSONRPCRequest("monitorblock", params, Value());
  189.  
  190. CRITICAL_BLOCK(cs_mapMonitored)
  191. CRITICAL_BLOCK(cs_vPOSTQueue)
  192. {
  193. - foreach(const string& url, setMonitorBlocks)
  194. + BOOST_FOREACH(const std::string& url, setMonitorBlocks)
  195. {
  196. - shared_ptr<CPOSTRequest> postRequest(new CPOSTRequest(url, postBody));
  197. + boost::shared_ptr<CPOSTRequest> postRequest(new CPOSTRequest(url, postBody));
  198. vPOSTQueue.push_back(postRequest);
  199. }
  200. }
  201. @@ -149,14 +149,14 @@ void monitorTx(const CWalletTx& wtx)
  202. if (params.empty())
  203. return; // Not our transaction
  204.  
  205. - string postBody = JSONRPCRequest("monitortx", params, Value());
  206. + std::string postBody = JSONRPCRequest("monitortx", params, Value());
  207.  
  208. CRITICAL_BLOCK(cs_mapMonitored)
  209. CRITICAL_BLOCK(cs_vPOSTQueue)
  210. {
  211. - foreach(const string& url, setMonitorTx)
  212. + BOOST_FOREACH(const std::string& url, setMonitorTx)
  213. {
  214. - shared_ptr<CPOSTRequest> postRequest(new CPOSTRequest(url, postBody));
  215. + boost::shared_ptr<CPOSTRequest> postRequest(new CPOSTRequest(url, postBody));
  216. vPOSTQueue.push_back(postRequest);
  217. }
  218. }
  219. @@ -165,21 +165,21 @@ void monitorTx(const CWalletTx& wtx)
  220. Value listmonitored(const Array& params, bool fHelp)
  221. {
  222. if (fHelp || params.size() != 0)
  223. - throw runtime_error(
  224. + throw std::runtime_error(
  225. "listmonitored\n"
  226. "Returns list of urls that receive notification when new blocks are accepted.");
  227.  
  228. Array ret;
  229. CRITICAL_BLOCK(cs_mapMonitored)
  230. {
  231. - foreach(const string& url, setMonitorBlocks)
  232. + BOOST_FOREACH(const std::string& url, setMonitorBlocks)
  233. {
  234. Object item;
  235. item.push_back(Pair("category", "block"));
  236. item.push_back(Pair("url", url));
  237. ret.push_back(item);
  238. }
  239. - foreach(const string& url, setMonitorTx)
  240. + BOOST_FOREACH(const std::string& url, setMonitorTx)
  241. {
  242. Object item;
  243. item.push_back(Pair("category", "tx"));
  244. @@ -193,11 +193,11 @@ Value listmonitored(const Array& params, bool fHelp)
  245. Value monitortx(const Array& params, bool fHelp)
  246. {
  247. if (fHelp || params.size() < 1 || params.size() > 3)
  248. - throw runtime_error(
  249. + throw std::runtime_error(
  250. "monitortx <url> [monitor=true]\n"
  251. "POST transaction information to <url> as wallet transactions are sent/received.\n"
  252. "[monitor] true will start monitoring, false will stop.");
  253. - string url = params[0].get_str();
  254. + std::string url = params[0].get_str();
  255. bool fMonitor = true;
  256. if (params.size() > 1)
  257. fMonitor = params[1].get_bool();
  258. @@ -219,11 +219,11 @@ Value monitortx(const Array& params, bool fHelp)
  259. Value monitorblocks(const Array& params, bool fHelp)
  260. {
  261. if (fHelp || params.size() < 1 || params.size() > 3)
  262. - throw runtime_error(
  263. + throw std::runtime_error(
  264. "monitorblocks <url> [monitor=true]\n"
  265. "POST block information to <url> as blocks are added to the block chain.\n"
  266. "[monitor] true will start monitoring, false will stop.");
  267. - string url = params[0].get_str();
  268. + std::string url = params[0].get_str();
  269. bool fMonitor = true;
  270. if (params.size() > 1)
  271. fMonitor = params[1].get_bool();
  272. @@ -270,13 +270,13 @@ void ThreadHTTPPOST2(void* parg)
  273. if (fShutdown)
  274. return;
  275.  
  276. - vector<shared_ptr<CPOSTRequest> > work;
  277. + std::vector<boost::shared_ptr<CPOSTRequest> > work;
  278. CRITICAL_BLOCK(cs_vPOSTQueue)
  279. {
  280. work = vPOSTQueue;
  281. vPOSTQueue.clear();
  282. }
  283. - foreach (shared_ptr<CPOSTRequest> r, work)
  284. + BOOST_FOREACH (boost::shared_ptr<CPOSTRequest> r, work)
  285. r->POST();
  286.  
  287. if (vPOSTQueue.empty())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement