PRCYCoin  2.0.0.7rc1
P2P Digital Currency
rest.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 The Bitcoin developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include "chain.h"
7 #include "primitives/block.h"
9 #include "main.h"
10 #include "httpserver.h"
11 #include "rpc/server.h"
12 #include "streams.h"
13 #include "sync.h"
14 #include "txmempool.h"
15 #include "utilstrencodings.h"
16 #include "version.h"
17 #include <univalue.h>
18 
19 #include <boost/algorithm/string.hpp>
20 #include <boost/dynamic_bitset.hpp>
21 
22 static const size_t MAX_GETUTXOS_OUTPOINTS = 15; //allow a max of 15 outpoints to be queried at once
23 
24 
25 enum RetFormat {
30 };
31 
32 static const struct {
33  enum RetFormat rf;
34  const char *name;
35 } rf_names[] = {
36  {RF_UNDEF, ""},
37  {RF_BINARY, "bin"},
38  {RF_HEX, "hex"},
39  {RF_JSON, "json"},
40 };
41 
42 struct CCoin {
43  uint32_t nTxVer; // Don't call this nVersion, that name has a special meaning inside IMPLEMENT_SERIALIZE
44  uint32_t nHeight;
46 
48 
49  template<typename Stream, typename Operation>
50  inline void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion) {
53  READWRITE(out);
54  }
55 };
56 
57 
58 extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry);
59 
60 extern UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false);
61 
63 
64 extern UniValue mempoolToJSON(bool fVerbose = false);
65 
66 extern void ScriptPubKeyToJSON(const CScript &scriptPubKey, UniValue &out, bool fIncludeHex);
67 
68 extern UniValue blockheaderToJSON(const CBlockIndex *blockindex);
69 
70 static bool RESTERR(HTTPRequest *req, enum HTTPStatusCode status, std::string message) {
71  req->WriteHeader("Content-Type", "text/plain");
72  req->WriteReply(status, message + "\r\n");
73  return false;
74 }
75 
76 static enum RetFormat ParseDataFormat(std::vector<std::string>& params, const std::string& strReq) {
77  boost::split(params, strReq, boost::is_any_of("."));
78  if (params.size() > 1) {
79  for (unsigned int i = 0; i < ARRAYLEN(rf_names); i++)
80  if (params[1] == rf_names[i].name)
81  return rf_names[i].rf;
82  }
83 
84  return rf_names[0].rf;
85 }
86 
87 static std::string AvailableDataFormatsString() {
88  std::string formats = "";
89  for (unsigned int i = 0; i < ARRAYLEN(rf_names); i++)
90  if (strlen(rf_names[i].name) > 0) {
91  formats.append(".");
92  formats.append(rf_names[i].name);
93  formats.append(", ");
94  }
95 
96  if (formats.length() > 0)
97  return formats.substr(0, formats.length() - 2);
98 
99  return formats;
100 }
101 
102 static bool ParseHashStr(const std::string& strReq, uint256& v) {
103  if (!IsHex(strReq) || (strReq.size() != 64))
104  return false;
105 
106  v.SetHex(strReq);
107  return true;
108 }
109 
110 static bool CheckWarmup(HTTPRequest *req) {
111  std::string statusmessage;
112  if (RPCIsInWarmup(&statusmessage))
113  return RESTERR(req, HTTP_SERVICE_UNAVAILABLE, "Service temporarily unavailable: " + statusmessage);
114  return true;
115 }
116 
117 static bool rest_headers(HTTPRequest *req,
118  const std::string &strURIPart) {
119  if (!CheckWarmup(req))
120  return false;
121 
122  std::vector<std::string> params;
123  const RetFormat rf = ParseDataFormat(params, strURIPart);
124  std::vector<std::string> path;
125  boost::split(path, params[0], boost::is_any_of("/"));
126  if (path.size() != 2)
127  return RESTERR(req, HTTP_BAD_REQUEST, "No header count specified. Use /rest/headers/<count>/<hash>.<ext>.");
128 
129  long count = strtol(path[0].c_str(), NULL, 10);
130  if (count < 1 || count > 2000)
131  return RESTERR(req, HTTP_BAD_REQUEST, "Header count out of range: " + path[0]);
132  std::string hashStr = path[1];
133  uint256 hash;
134 
135  if (!ParseHashStr(hashStr, hash))
136  return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr);
137  std::vector<const CBlockIndex *> headers;
138  headers.reserve(count);
139 
140  {
141  LOCK(cs_main);
142  BlockMap::const_iterator it = mapBlockIndex.find(hash);
143  const CBlockIndex *pindex = (it != mapBlockIndex.end()) ? it->second : NULL;
144  while (pindex != NULL && chainActive.Contains(pindex)) {
145  headers.push_back(pindex);
146  if (headers.size() == (unsigned long) count)
147  break;
148  pindex = chainActive.Next(pindex);
149  }
150  }
151 
152  CDataStream ssHeader(SER_NETWORK, PROTOCOL_VERSION);
153  for (const CBlockIndex *pindex : headers) {
154  ssHeader << pindex->GetBlockHeader();
155  }
156 
157  switch (rf) {
158  case RF_BINARY: {
159  std::string binaryHeader = ssHeader.str();
160  req->WriteHeader("Content-Type", "application/octet-stream");
161  req->WriteReply(HTTP_OK, binaryHeader);
162  return true;
163  }
164 
165  case RF_HEX: {
166  std::string strHex = HexStr(ssHeader.begin(), ssHeader.end()) + "\n";
167  req->WriteHeader("Content-Type", "text/plain");
168  req->WriteReply(HTTP_OK, strHex);
169  return true;
170  }
171  case RF_JSON: {
172  UniValue jsonHeaders(UniValue::VARR);
173  for (const CBlockIndex *pindex : headers) {
174  jsonHeaders.push_back(blockheaderToJSON(pindex));
175  }
176  std::string strJSON = jsonHeaders.write() + "\n";
177  req->WriteHeader("Content-Type", "application/json");
178  req->WriteReply(HTTP_OK, strJSON);
179  return true;
180  }
181  default: {
182  return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: .bin, .hex)");
183  }
184  }
185 
186  // not reached
187  return true; // continue to process further HTTP reqs on this cxn
188 }
189 
190 static bool rest_block(HTTPRequest *req,
191  const std::string &strURIPart,
192  bool showTxDetails) {
193  if (!CheckWarmup(req))
194  return false;
195  std::vector<std::string> params;
196  const RetFormat rf = ParseDataFormat(params, strURIPart);
197 
198  std::string hashStr = params[0];
199  uint256 hash;
200  if (!ParseHashStr(hashStr, hash))
201  return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr);
202 
203  CBlock block;
204  CBlockIndex *pblockindex = NULL;
205  {
206  LOCK(cs_main);
207  if (mapBlockIndex.count(hash) == 0)
208  return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");
209 
210  pblockindex = mapBlockIndex[hash];
211  if (!(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0)
212  return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not available (pruned data)");
213 
214  if (!ReadBlockFromDisk(block, pblockindex))
215  return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");
216  }
217 
218  CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION);
219  ssBlock << block;
220 
221  switch (rf) {
222  case RF_BINARY: {
223  std::string binaryBlock = ssBlock.str();
224  req->WriteHeader("Content-Type", "application/octet-stream");
225  req->WriteReply(HTTP_OK, binaryBlock);
226  return true;
227  }
228 
229  case RF_HEX: {
230  std::string strHex = HexStr(ssBlock.begin(), ssBlock.end()) + "\n";
231  req->WriteHeader("Content-Type", "text/plain");
232  req->WriteReply(HTTP_OK, strHex);
233  return true;
234  }
235 
236  case RF_JSON: {
237  UniValue objTx(UniValue::VOBJ);
238  std::string strJSON = objTx.write() + "\n";
239  req->WriteHeader("Content-Type", "application/json");
240  req->WriteReply(HTTP_OK, strJSON);
241  return true;
242  }
243 
244  default: {
245  return RESTERR(req, HTTP_NOT_FOUND,
246  "output format not found (available: " + AvailableDataFormatsString() + ")");
247  }
248  }
249 
250  // not reached
251  return true; // continue to process further HTTP reqs on this cxn
252 }
253 
254 static bool rest_block_extended(HTTPRequest *req, const std::string &strURIPart) {
255  return rest_block(req, strURIPart, true);
256 }
257 
258 static bool rest_block_notxdetails(HTTPRequest *req, const std::string &strURIPart) {
259  return rest_block(req, strURIPart, false);
260 }
261 
262 static bool rest_chaininfo(HTTPRequest *req, const std::string &strURIPart) {
263  if (!CheckWarmup(req))
264  return false;
265  std::vector<std::string> params;
266  const RetFormat rf = ParseDataFormat(params, strURIPart);
267 
268  switch (rf) {
269  case RF_JSON: {
270  UniValue rpcParams(UniValue::VARR);
271  UniValue chainInfoObject = getblockchaininfo(rpcParams, false);
272  std::string strJSON = chainInfoObject.write() + "\n";
273  req->WriteHeader("Content-Type", "application/json");
274  req->WriteReply(HTTP_OK, strJSON);
275  return true;
276  }
277  default: {
278  return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: json)");
279  }
280  }
281 
282  // not reached
283  return true; // continue to process further HTTP reqs on this cxn
284 }
285 
286 static bool rest_mempool_info(HTTPRequest *req, const std::string &strURIPart) {
287  if (!CheckWarmup(req))
288  return false;
289  std::vector<std::string> params;
290  const RetFormat rf = ParseDataFormat(params, strURIPart);
291 
292  switch (rf) {
293  case RF_JSON: {
294  UniValue mempoolInfoObject = mempoolInfoToJSON();
295 
296  std::string strJSON = mempoolInfoObject.write() + "\n";
297  req->WriteHeader("Content-Type", "application/json");
298  req->WriteReply(HTTP_OK, strJSON);
299  return true;
300  }
301  default: {
302  return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: json)");
303  }
304  }
305 
306  // not reached
307  return true; // continue to process further HTTP reqs on this cxn
308 }
309 
310 static bool rest_mempool_contents(HTTPRequest *req, const std::string &strURIPart) {
311  if (!CheckWarmup(req))
312  return false;
313  std::vector<std::string> params;
314  const RetFormat rf = ParseDataFormat(params, strURIPart);
315 
316  switch (rf) {
317  case RF_JSON: {
318  UniValue mempoolObject = mempoolToJSON(true);
319 
320  std::string strJSON = mempoolObject.write() + "\n";
321  req->WriteHeader("Content-Type", "application/json");
322  req->WriteReply(HTTP_OK, strJSON);
323  return true;
324  }
325  default: {
326  return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: json)");
327  }
328  }
329 
330  // not reached
331  return true; // continue to process further HTTP reqs on this cxn
332 }
333 
334 static bool rest_tx(HTTPRequest *req, const std::string &strURIPart) {
335  if (!CheckWarmup(req))
336  return false;
337  std::vector<std::string> params;
338  const RetFormat rf = ParseDataFormat(params, strURIPart);
339 
340  std::string hashStr = params[0];
341  uint256 hash;
342  if (!ParseHashStr(hashStr, hash))
343  return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr);
344 
345  CTransaction tx;
346  uint256 hashBlock = UINT256_ZERO;
347  if (!GetTransaction(hash, tx, hashBlock, true))
348  return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");
349 
350  CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
351  ssTx << tx;
352 
353  switch (rf) {
354  case RF_BINARY: {
355  std::string binaryTx = ssTx.str();
356  req->WriteHeader("Content-Type", "application/octet-stream");
357  req->WriteReply(HTTP_OK, binaryTx);
358  return true;
359  }
360 
361  case RF_HEX: {
362  std::string strHex = HexStr(ssTx.begin(), ssTx.end()) + "\n";
363  req->WriteHeader("Content-Type", "text/plain");
364  req->WriteReply(HTTP_OK, strHex);
365  return true;
366  }
367 
368  case RF_JSON: {
369  UniValue objTx(UniValue::VOBJ);
370  TxToJSON(tx, hashBlock, objTx);
371  std::string strJSON = objTx.write() + "\n";
372  req->WriteHeader("Content-Type", "application/json");
373  req->WriteReply(HTTP_OK, strJSON);
374  return true;
375  }
376 
377  default: {
378  return RESTERR(req, HTTP_NOT_FOUND,
379  "output format not found (available: " + AvailableDataFormatsString() + ")");
380  }
381  }
382 
383  // not reached
384  return true; // continue to process further HTTP reqs on this cxn
385 }
386 
387 
388 static bool rest_getutxos(HTTPRequest *req, const std::string &strURIPart) {
389  if (!CheckWarmup(req))
390  return false;
391  std::vector<std::string> params;
392  enum RetFormat rf = ParseDataFormat(params, strURIPart);
393 
394  std::vector<std::string> uriParts;
395  if (params.size() > 0 && params[0].length() > 1) {
396  std::string strUriParams = params[0].substr(1);
397  boost::split(uriParts, strUriParams, boost::is_any_of("/"));
398  }
399 
400  // throw exception in case of a empty request
401  std::string strRequestMutable = req->ReadBody();
402  if (strRequestMutable.length() == 0 && uriParts.size() == 0)
403  return RESTERR(req, HTTP_INTERNAL_SERVER_ERROR, "Error: empty request");
404 
405  bool fInputParsed = false;
406  bool fCheckMemPool = false;
407  std::vector<COutPoint> vOutPoints;
408 
409  // parse/deserialize input
410  // input-format = output-format, rest/getutxos/bin requires binary input, gives binary output, ...
411 
412  if (uriParts.size() > 0) {
413 
414  //inputs is sent over URI scheme (/rest/getutxos/checkmempool/txid1-n/txid2-n/...)
415  if (uriParts.size() > 0 && uriParts[0] == "checkmempool")
416  fCheckMemPool = true;
417 
418  for (size_t i = (fCheckMemPool) ? 1 : 0; i < uriParts.size(); i++)
419  {
420  uint256 txid;
421  int32_t nOutput;
422  std::string strTxid = uriParts[i].substr(0, uriParts[i].find("-"));
423  std::string strOutput = uriParts[i].substr(uriParts[i].find("-") + 1);
424 
425  if (!ParseInt32(strOutput, &nOutput) || !IsHex(strTxid))
426  return RESTERR(req, HTTP_INTERNAL_SERVER_ERROR, "Parse error");
427 
428  txid.SetHex(strTxid);
429  vOutPoints.push_back(COutPoint(txid, (uint32_t) nOutput));
430  }
431 
432  if (vOutPoints.size() > 0)
433  fInputParsed = true;
434  else
435  return RESTERR(req, HTTP_INTERNAL_SERVER_ERROR, "Error: empty request");
436  }
437 
438  switch (rf) {
439  case RF_HEX: {
440  // convert hex to bin, continue then with bin part
441  std::vector<unsigned char> strRequestV = ParseHex(strRequestMutable);
442  strRequestMutable.assign(strRequestV.begin(), strRequestV.end());
443  }
444 
445  case RF_BINARY: {
446  try {
447  //deserialize only if user sent a request
448  if (strRequestMutable.size() > 0) {
449  if (fInputParsed) //don't allow sending input over URI and HTTP RAW DATA
450  return RESTERR(req, HTTP_INTERNAL_SERVER_ERROR,
451  "Combination of URI scheme inputs and raw post data is not allowed");
452 
453  CDataStream oss(SER_NETWORK, PROTOCOL_VERSION);
454  oss << strRequestMutable;
455  oss >> fCheckMemPool;
456  oss >> vOutPoints;
457  }
458  } catch (const std::ios_base::failure& e) {
459  // abort in case of unreadable binary data
460  return RESTERR(req, HTTP_INTERNAL_SERVER_ERROR, "Parse error");
461  }
462  break;
463  }
464 
465  case RF_JSON: {
466  if (!fInputParsed)
467  return RESTERR(req, HTTP_INTERNAL_SERVER_ERROR, "Error: empty request");
468  break;
469  }
470 
471  default: {
472  return RESTERR(req, HTTP_NOT_FOUND,
473  "output format not found (available: " + AvailableDataFormatsString() + ")");
474  }
475  }
476 
477  // limit max outpoints
478  if (vOutPoints.size() > MAX_GETUTXOS_OUTPOINTS)
479  return RESTERR(req, HTTP_INTERNAL_SERVER_ERROR,
480  strprintf("Error: max outpoints exceeded (max: %d, tried: %d)", MAX_GETUTXOS_OUTPOINTS,
481  vOutPoints.size()));
482 
483 
484  // check spentness and form a bitmap (as well as a JSON capable human-readble string representation)
485  std::vector<unsigned char> bitmap;
486  std::vector<CCoin> outs;
487  std::string bitmapStringRepresentation;
488  boost::dynamic_bitset<unsigned char> hits(vOutPoints.size());
489  {
491 
492  CCoinsView viewDummy;
493  CCoinsViewCache view(&viewDummy);
494 
495  CCoinsViewCache &viewChain = *pcoinsTip;
496  CCoinsViewMemPool viewMempool(&viewChain, mempool);
497 
498  if (fCheckMemPool)
499  view.SetBackend(viewMempool); // switch cache backend to db+mempool in case user likes to query mempool
500 
501  for (size_t i = 0; i < vOutPoints.size(); i++) {
502  CCoins coins;
503  uint256 hash = vOutPoints[i].hash;
504  if (view.GetCoins(hash, coins)) {
505  mempool.pruneSpent(hash, coins);
506  if (coins.IsAvailable(vOutPoints[i].n)) {
507  hits[i] = true;
508  // Safe to index into vout here because IsAvailable checked if it's off the end of the array, or if
509 
510  // n is valid but points to an already spent output (IsNull).
511  CCoin coin;
512  coin.nTxVer = coins.nVersion;
513  coin.nHeight = coins.nHeight;
514  coin.out = coins.vout.at(vOutPoints[i].n);
515  assert(!coin.out.IsNull());
516  outs.push_back(coin);
517  }
518  }
519 
520  bitmapStringRepresentation.append(
521  hits[i] ? "1" : "0"); // form a binary string representation (human-readable for json output)
522  }
523  }
524  boost::to_block_range(hits, std::back_inserter(bitmap));
525  switch (rf) {
526  case RF_BINARY: {
527  // serialize data
528  // use exact same output as mentioned in Bip64
529  CDataStream ssGetUTXOResponse(SER_NETWORK, PROTOCOL_VERSION);
530  ssGetUTXOResponse << chainActive.Height() << chainActive.Tip()->GetBlockHash() << bitmap << outs;
531  std::string ssGetUTXOResponseString = ssGetUTXOResponse.str();
532 
533  req->WriteHeader("Content-Type", "application/octet-stream");
534  req->WriteReply(HTTP_OK, ssGetUTXOResponseString);
535  return true;
536  }
537 
538  case RF_HEX: {
539  CDataStream ssGetUTXOResponse(SER_NETWORK, PROTOCOL_VERSION);
540  ssGetUTXOResponse << chainActive.Height() << chainActive.Tip()->GetBlockHash() << bitmap << outs;
541  std::string strHex = HexStr(ssGetUTXOResponse.begin(), ssGetUTXOResponse.end()) + "\n";
542 
543  req->WriteHeader("Content-Type", "text/plain");
544  req->WriteReply(HTTP_OK, strHex);
545  return true;
546  }
547 
548  case RF_JSON: {
549  UniValue objGetUTXOResponse(UniValue::VOBJ);
550 
551  // pack in some essentials
552  // use more or less the same output as mentioned in Bip64
553  objGetUTXOResponse.push_back(Pair("chainHeight", chainActive.Height()));
554  objGetUTXOResponse.push_back(Pair("chaintipHash", chainActive.Tip()->GetBlockHash().GetHex()));
555  objGetUTXOResponse.push_back(Pair("bitmap", bitmapStringRepresentation));
556 
557  UniValue utxos(UniValue::VARR);
558  for ( const CCoin &coin : outs) {
559  UniValue utxo(UniValue::VOBJ);
560  utxo.push_back(Pair("txvers", (int32_t) coin.nTxVer));
561  utxo.push_back(Pair("height", (int32_t) coin.nHeight));
562  utxo.push_back(Pair("value", ValueFromAmount(coin.out.nValue)));
563 
564  // include the script in a json output
566  ScriptPubKeyToJSON(coin.out.scriptPubKey, o, true);
567  utxo.push_back(Pair("scriptPubKey", o));
568  utxos.push_back(utxo);
569  }
570  objGetUTXOResponse.push_back(Pair("utxos", utxos));
571 
572  // return json string
573  std::string strJSON = objGetUTXOResponse.write() + "\n";
574  req->WriteHeader("Content-Type", "application/json");
575  req->WriteReply(HTTP_OK, strJSON);
576  return true;
577  }
578  default: {
579  return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: " + AvailableDataFormatsString() + ")");
580  }
581  }
582 
583  // not reached
584  return true; // continue to process further HTTP reqs on this cxn
585 }
586 
587 static const struct {
588  const char *prefix;
589  bool (*handler)(HTTPRequest* req, const std::string& strReq);
590 } uri_prefixes[] = {
591  {"/rest/tx/", rest_tx},
592  {"/rest/block/notxdetails/", rest_block_notxdetails},
593  {"/rest/block/", rest_block_extended},
594  {"/rest/chaininfo", rest_chaininfo},
595  {"/rest/mempool/info", rest_mempool_info},
596  {"/rest/mempool/contents", rest_mempool_contents},
597  {"/rest/headers/", rest_headers},
598  {"/rest/getutxos", rest_getutxos},
599 };
600 
601 bool StartREST()
602 {
603  for (unsigned int i = 0; i < ARRAYLEN(uri_prefixes); i++)
604  RegisterHTTPHandler(uri_prefixes[i].prefix, false, uri_prefixes[i].handler);
605  return true;
606 }
607 
609 {
610 }
611 
612 void StopREST() {
613  for (unsigned int i = 0; i < ARRAYLEN(uri_prefixes); i++)
614  UnregisterHTTPHandler(uri_prefixes[i].prefix, false);
615 }
ARRAYLEN
#define ARRAYLEN(array)
Definition: utilstrencodings.h:21
block.h
LOCK2
#define LOCK2(cs1, cs2)
Definition: sync.h:183
UINT256_ZERO
const uint256 UINT256_ZERO
constant uint256 instances
Definition: uint256.h:129
CTxMemPool::pruneSpent
void pruneSpent(const uint256 &hash, CCoins &coins)
Definition: txmempool.cpp:376
HTTP_SERVICE_UNAVAILABLE
@ HTTP_SERVICE_UNAVAILABLE
Definition: protocol.h:27
UniValue::VOBJ
@ VOBJ
Definition: univalue.h:21
transaction.h
UnregisterHTTPHandler
void UnregisterHTTPHandler(const std::string &prefix, bool exactMatch)
Unregister handler for prefix.
Definition: httpserver.cpp:701
RetFormat
RetFormat
Definition: rest.cpp:25
BLOCK_HAVE_DATA
@ BLOCK_HAVE_DATA
Definition: chain.h:148
ParseHex
std::vector< unsigned char > ParseHex(const char *psz)
Definition: utilstrencodings.cpp:77
streams.h
base_uint::GetHex
std::string GetHex() const
Definition: arith_uint256.cpp:155
CBlockIndex::nTx
unsigned int nTx
Number of transactions in this block.
Definition: chain.h:197
ValueFromAmount
UniValue ValueFromAmount(const CAmount &amount)
Definition: server.cpp:118
sync.h
chainActive
CChain chainActive
The currently-connected chain of blocks.
Definition: main.cpp:70
mempoolToJSON
UniValue mempoolToJSON(bool fVerbose=false)
Definition: blockchain.cpp:380
CCoin::ADD_SERIALIZE_METHODS
ADD_SERIALIZE_METHODS
Definition: rest.cpp:47
HTTPStatusCode
HTTPStatusCode
HTTP status codes.
Definition: protocol.h:19
HTTP_BAD_REQUEST
@ HTTP_BAD_REQUEST
Definition: protocol.h:21
CCoins::IsAvailable
bool IsAvailable(unsigned int nPos) const
check whether a particular output is still available
Definition: coins.h:275
ParseHashStr
uint256 ParseHashStr(const std::string &, const std::string &strName)
Definition: core_read.cpp:103
CCoins::nHeight
int nHeight
at which height this transaction was included in the active block chain
Definition: coins.h:88
CBlockIndex::nStatus
unsigned int nStatus
Verification status of this block. See enum BlockStatus.
Definition: chain.h:205
blockToJSON
UniValue blockToJSON(const CBlock &block, const CBlockIndex *blockindex, bool txDetails=false)
Definition: blockchain.cpp:95
HTTPRequest::WriteHeader
void WriteHeader(const std::string &hdr, const std::string &value)
Write output header.
Definition: httpserver.cpp:616
SER_NETWORK
@ SER_NETWORK
Definition: serialize.h:159
version.h
UniValue
Definition: univalue.h:19
CTransaction
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:269
txmempool.h
CCoinsView
Abstract view on the open txout dataset.
Definition: coins.h:346
prefix
const char * prefix
Definition: rest.cpp:588
cs_main
RecursiveMutex cs_main
Global state.
Definition: main.cpp:65
CBlockIndex::GetBlockHeader
CBlockHeader GetBlockHeader() const
Definition: chain.h:340
CTxOut::IsNull
bool IsNull() const
Definition: transaction.h:209
CCoins::vout
std::vector< CTxOut > vout
unspent transaction outputs; spent outputs are .IsNull(); spent outputs at the end of the array are d...
Definition: coins.h:85
CCoin::out
CTxOut out
Definition: rest.cpp:45
CTxMemPool::cs
RecursiveMutex cs
sum of all mempool tx' byte sizes
Definition: txmempool.h:135
IsHex
bool IsHex(const std::string &str)
Definition: utilstrencodings.cpp:68
getblockchaininfo
UniValue getblockchaininfo(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:767
HTTPRequest
In-flight HTTP request.
Definition: httpserver.h:57
CTxOut
An output of a transaction.
Definition: transaction.h:164
TxToJSON
void TxToJSON(const CTransaction &tx, const uint256 hashBlock, UniValue &entry)
Definition: rawtransaction.cpp:66
GetTransaction
bool GetTransaction(const uint256 &hash, CTransaction &tx, uint256 &hashBlock, bool fAllowSlow, CBlockIndex *blockIndex)
Return transaction in tx, and if it was found inside a block, its hash is placed in hashBlock.
Definition: main.cpp:2010
RF_UNDEF
@ RF_UNDEF
Definition: rest.cpp:26
HTTPRequest::ReadBody
std::string ReadBody()
Read request body.
Definition: httpserver.cpp:596
univalue.h
HexStr
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
Definition: utilstrencodings.h:85
pcoinsTip
CCoinsViewCache * pcoinsTip
Global variable that points to the active CCoinsView (protected by cs_main)
Definition: main.cpp:1130
mempool
CTxMemPool mempool(::minRelayTxFee)
RF_JSON
@ RF_JSON
Definition: rest.cpp:29
uint256
256-bit unsigned big integer.
Definition: uint256.h:38
base_uint::SetHex
void SetHex(const char *psz)
Definition: arith_uint256.cpp:164
CCoin::nTxVer
uint32_t nTxVer
Definition: rest.cpp:43
StopREST
void StopREST()
Stop HTTP REST subsystem.
Definition: rest.cpp:612
CScript
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:363
chain.h
CBlockIndex::GetBlockHash
uint256 GetBlockHash() const
Definition: chain.h:359
CChain::Height
int Height() const
Return the maximal height in the chain.
Definition: chain.h:641
RF_HEX
@ RF_HEX
Definition: rest.cpp:28
name
const char * name
Definition: rest.cpp:34
CCoins::nVersion
int nVersion
version of the CTransaction; accesses to this value should probably check for nHeight as well,...
Definition: coins.h:92
CBlock
Definition: block.h:142
strprintf
#define strprintf
Definition: tinyformat.h:1056
blockheaderToJSON
UniValue blockheaderToJSON(const CBlockIndex *blockindex)
Definition: blockchain.cpp:67
HTTP_OK
@ HTTP_OK
Definition: protocol.h:20
READWRITE
#define READWRITE(obj)
Definition: serialize.h:164
CCoinsViewCache
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:414
main.h
LOCK
#define LOCK(cs)
Definition: sync.h:182
ReadBlockFromDisk
bool ReadBlockFromDisk(CBlock &block, const CDiskBlockPos &pos)
Definition: main.cpp:2101
CCoin::nHeight
uint32_t nHeight
Definition: rest.cpp:44
HTTP_NOT_FOUND
@ HTTP_NOT_FOUND
Definition: protocol.h:24
CCoinsViewMemPool
CCoinsView that brings transactions from a memorypool into view.
Definition: txmempool.h:202
mempoolInfoToJSON
UniValue mempoolInfoToJSON()
Definition: blockchain.cpp:959
CChain::Contains
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
Definition: chain.h:626
CCoin::SerializationOp
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: rest.cpp:50
CDataStream
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:34
RF_BINARY
@ RF_BINARY
Definition: rest.cpp:27
CCoins
Definition: coins.h:77
ParseInt32
bool ParseInt32(const std::string &str, int32_t *out)
Convert string to signed 32-bit integer with strict parse error feedback.
Definition: utilstrencodings.cpp:482
COutPoint
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:36
utilstrencodings.h
handler
bool(* handler)(HTTPRequest *req, const std::string &strReq)
Definition: rest.cpp:589
CChain::Tip
CBlockIndex * Tip(bool fProofOfStake=false) const
Returns the index entry for the tip of this chain, or NULL if none.
Definition: chain.h:596
httpserver.h
RPCIsInWarmup
bool RPCIsInWarmup(std::string *outStatus)
Definition: server.cpp:502
UniValue::VARR
@ VARR
Definition: univalue.h:21
StartREST
bool StartREST()
Start HTTP REST subsystem.
Definition: rest.cpp:601
server.h
CBlockIndex
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:162
RegisterHTTPHandler
void RegisterHTTPHandler(const std::string &prefix, bool exactMatch, const HTTPRequestHandler &handler)
Register handler for prefix.
Definition: httpserver.cpp:695
HTTPRequest::WriteReply
void WriteReply(int nStatus, const std::string &strReply="")
Write HTTP reply.
Definition: httpserver.cpp:628
CCoin
Definition: rest.cpp:42
rf
enum RetFormat rf
Definition: rest.cpp:33
ScriptPubKeyToJSON
void ScriptPubKeyToJSON(const CScript &scriptPubKey, UniValue &out, bool fIncludeHex)
Definition: rawtransaction.cpp:34
CChain::Next
CBlockIndex * Next(const CBlockIndex *pindex) const
Find the successor of a block in this chain, or NULL if the given index is not found or is the tip.
Definition: chain.h:632
InterruptREST
void InterruptREST()
Interrupt RPC REST subsystem.
Definition: rest.cpp:608
UniValue::write
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
Definition: univalue_write.cpp:31
mapBlockIndex
BlockMap mapBlockIndex
Definition: main.cpp:67
HTTP_INTERNAL_SERVER_ERROR
@ HTTP_INTERNAL_SERVER_ERROR
Definition: protocol.h:26