Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

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