Bitcoin Core  27.1.0
P2P Digital Currency
rest.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2022 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 #if defined(HAVE_CONFIG_H)
8 #endif
9 
10 #include <rest.h>
11 
12 #include <blockfilter.h>
13 #include <chain.h>
14 #include <chainparams.h>
15 #include <core_io.h>
16 #include <httpserver.h>
17 #include <index/blockfilterindex.h>
18 #include <index/txindex.h>
19 #include <node/blockstorage.h>
20 #include <node/context.h>
21 #include <primitives/block.h>
22 #include <primitives/transaction.h>
23 #include <rpc/blockchain.h>
24 #include <rpc/mempool.h>
25 #include <rpc/protocol.h>
26 #include <rpc/server.h>
27 #include <rpc/server_util.h>
28 #include <streams.h>
29 #include <sync.h>
30 #include <txmempool.h>
31 #include <util/any.h>
32 #include <util/check.h>
33 #include <util/strencodings.h>
34 #include <validation.h>
35 
36 #include <any>
37 #include <string>
38 
39 #include <univalue.h>
40 
42 using node::NodeContext;
43 
44 static const size_t MAX_GETUTXOS_OUTPOINTS = 15; //allow a max of 15 outpoints to be queried at once
45 static constexpr unsigned int MAX_REST_HEADERS_RESULTS = 2000;
46 
47 static const struct {
49  const char* name;
50 } rf_names[] = {
53  {RESTResponseFormat::HEX, "hex"},
54  {RESTResponseFormat::JSON, "json"},
55 };
56 
57 struct CCoin {
58  uint32_t nHeight;
60 
61  CCoin() : nHeight(0) {}
62  explicit CCoin(Coin&& in) : nHeight(in.nHeight), out(std::move(in.out)) {}
63 
65  {
66  uint32_t nTxVerDummy = 0;
67  READWRITE(nTxVerDummy, obj.nHeight, obj.out);
68  }
69 };
70 
71 static bool RESTERR(HTTPRequest* req, enum HTTPStatusCode status, std::string message)
72 {
73  req->WriteHeader("Content-Type", "text/plain");
74  req->WriteReply(status, message + "\r\n");
75  return false;
76 }
77 
85 static NodeContext* GetNodeContext(const std::any& context, HTTPRequest* req)
86 {
87  auto node_context = util::AnyPtr<NodeContext>(context);
88  if (!node_context) {
90  strprintf("%s:%d (%s)\n"
91  "Internal bug detected: Node context not found!\n"
92  "You may report this issue here: %s\n",
93  __FILE__, __LINE__, __func__, PACKAGE_BUGREPORT));
94  return nullptr;
95  }
96  return node_context;
97 }
98 
106 static CTxMemPool* GetMemPool(const std::any& context, HTTPRequest* req)
107 {
108  auto node_context = util::AnyPtr<NodeContext>(context);
109  if (!node_context || !node_context->mempool) {
110  RESTERR(req, HTTP_NOT_FOUND, "Mempool disabled or instance not found");
111  return nullptr;
112  }
113  return node_context->mempool.get();
114 }
115 
123 static ChainstateManager* GetChainman(const std::any& context, HTTPRequest* req)
124 {
125  auto node_context = util::AnyPtr<NodeContext>(context);
126  if (!node_context || !node_context->chainman) {
128  strprintf("%s:%d (%s)\n"
129  "Internal bug detected: Chainman disabled or instance not found!\n"
130  "You may report this issue here: %s\n",
131  __FILE__, __LINE__, __func__, PACKAGE_BUGREPORT));
132  return nullptr;
133  }
134  return node_context->chainman.get();
135 }
136 
137 RESTResponseFormat ParseDataFormat(std::string& param, const std::string& strReq)
138 {
139  // Remove query string (if any, separated with '?') as it should not interfere with
140  // parsing param and data format
141  param = strReq.substr(0, strReq.rfind('?'));
142  const std::string::size_type pos_format{param.rfind('.')};
143 
144  // No format string is found
145  if (pos_format == std::string::npos) {
146  return rf_names[0].rf;
147  }
148 
149  // Match format string to available formats
150  const std::string suffix(param, pos_format + 1);
151  for (const auto& rf_name : rf_names) {
152  if (suffix == rf_name.name) {
153  param.erase(pos_format);
154  return rf_name.rf;
155  }
156  }
157 
158  // If no suffix is found, return RESTResponseFormat::UNDEF and original string without query string
159  return rf_names[0].rf;
160 }
161 
162 static std::string AvailableDataFormatsString()
163 {
164  std::string formats;
165  for (const auto& rf_name : rf_names) {
166  if (strlen(rf_name.name) > 0) {
167  formats.append(".");
168  formats.append(rf_name.name);
169  formats.append(", ");
170  }
171  }
172 
173  if (formats.length() > 0)
174  return formats.substr(0, formats.length() - 2);
175 
176  return formats;
177 }
178 
179 static bool CheckWarmup(HTTPRequest* req)
180 {
181  std::string statusmessage;
182  if (RPCIsInWarmup(&statusmessage))
183  return RESTERR(req, HTTP_SERVICE_UNAVAILABLE, "Service temporarily unavailable: " + statusmessage);
184  return true;
185 }
186 
187 static bool rest_headers(const std::any& context,
188  HTTPRequest* req,
189  const std::string& strURIPart)
190 {
191  if (!CheckWarmup(req))
192  return false;
193  std::string param;
194  const RESTResponseFormat rf = ParseDataFormat(param, strURIPart);
195  std::vector<std::string> path = SplitString(param, '/');
196 
197  std::string raw_count;
198  std::string hashStr;
199  if (path.size() == 2) {
200  // deprecated path: /rest/headers/<count>/<hash>
201  hashStr = path[1];
202  raw_count = path[0];
203  } else if (path.size() == 1) {
204  // new path with query parameter: /rest/headers/<hash>?count=<count>
205  hashStr = path[0];
206  try {
207  raw_count = req->GetQueryParameter("count").value_or("5");
208  } catch (const std::runtime_error& e) {
209  return RESTERR(req, HTTP_BAD_REQUEST, e.what());
210  }
211  } else {
212  return RESTERR(req, HTTP_BAD_REQUEST, "Invalid URI format. Expected /rest/headers/<hash>.<ext>?count=<count>");
213  }
214 
215  const auto parsed_count{ToIntegral<size_t>(raw_count)};
216  if (!parsed_count.has_value() || *parsed_count < 1 || *parsed_count > MAX_REST_HEADERS_RESULTS) {
217  return RESTERR(req, HTTP_BAD_REQUEST, strprintf("Header count is invalid or out of acceptable range (1-%u): %s", MAX_REST_HEADERS_RESULTS, raw_count));
218  }
219 
220  uint256 hash;
221  if (!ParseHashStr(hashStr, hash))
222  return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr);
223 
224  const CBlockIndex* tip = nullptr;
225  std::vector<const CBlockIndex*> headers;
226  headers.reserve(*parsed_count);
227  {
228  ChainstateManager* maybe_chainman = GetChainman(context, req);
229  if (!maybe_chainman) return false;
230  ChainstateManager& chainman = *maybe_chainman;
231  LOCK(cs_main);
232  CChain& active_chain = chainman.ActiveChain();
233  tip = active_chain.Tip();
234  const CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(hash);
235  while (pindex != nullptr && active_chain.Contains(pindex)) {
236  headers.push_back(pindex);
237  if (headers.size() == *parsed_count) {
238  break;
239  }
240  pindex = active_chain.Next(pindex);
241  }
242  }
243 
244  switch (rf) {
246  DataStream ssHeader{};
247  for (const CBlockIndex *pindex : headers) {
248  ssHeader << pindex->GetBlockHeader();
249  }
250 
251  std::string binaryHeader = ssHeader.str();
252  req->WriteHeader("Content-Type", "application/octet-stream");
253  req->WriteReply(HTTP_OK, binaryHeader);
254  return true;
255  }
256 
258  DataStream ssHeader{};
259  for (const CBlockIndex *pindex : headers) {
260  ssHeader << pindex->GetBlockHeader();
261  }
262 
263  std::string strHex = HexStr(ssHeader) + "\n";
264  req->WriteHeader("Content-Type", "text/plain");
265  req->WriteReply(HTTP_OK, strHex);
266  return true;
267  }
269  UniValue jsonHeaders(UniValue::VARR);
270  for (const CBlockIndex *pindex : headers) {
271  jsonHeaders.push_back(blockheaderToJSON(*tip, *pindex));
272  }
273  std::string strJSON = jsonHeaders.write() + "\n";
274  req->WriteHeader("Content-Type", "application/json");
275  req->WriteReply(HTTP_OK, strJSON);
276  return true;
277  }
278  default: {
279  return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: " + AvailableDataFormatsString() + ")");
280  }
281  }
282 }
283 
284 static bool rest_block(const std::any& context,
285  HTTPRequest* req,
286  const std::string& strURIPart,
287  TxVerbosity tx_verbosity)
288 {
289  if (!CheckWarmup(req))
290  return false;
291  std::string hashStr;
292  const RESTResponseFormat rf = ParseDataFormat(hashStr, strURIPart);
293 
294  uint256 hash;
295  if (!ParseHashStr(hashStr, hash))
296  return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr);
297 
298  CBlock block;
299  const CBlockIndex* pblockindex = nullptr;
300  const CBlockIndex* tip = nullptr;
301  ChainstateManager* maybe_chainman = GetChainman(context, req);
302  if (!maybe_chainman) return false;
303  ChainstateManager& chainman = *maybe_chainman;
304  {
305  LOCK(cs_main);
306  tip = chainman.ActiveChain().Tip();
307  pblockindex = chainman.m_blockman.LookupBlockIndex(hash);
308  if (!pblockindex) {
309  return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");
310  }
311  if (chainman.m_blockman.IsBlockPruned(*pblockindex)) {
312  return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not available (pruned data)");
313  }
314  }
315 
316  if (!chainman.m_blockman.ReadBlockFromDisk(block, *pblockindex)) {
317  return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");
318  }
319 
320  switch (rf) {
322  DataStream ssBlock;
323  ssBlock << TX_WITH_WITNESS(block);
324  std::string binaryBlock = ssBlock.str();
325  req->WriteHeader("Content-Type", "application/octet-stream");
326  req->WriteReply(HTTP_OK, binaryBlock);
327  return true;
328  }
329 
331  DataStream ssBlock;
332  ssBlock << TX_WITH_WITNESS(block);
333  std::string strHex = HexStr(ssBlock) + "\n";
334  req->WriteHeader("Content-Type", "text/plain");
335  req->WriteReply(HTTP_OK, strHex);
336  return true;
337  }
338 
340  UniValue objBlock = blockToJSON(chainman.m_blockman, block, *tip, *pblockindex, tx_verbosity);
341  std::string strJSON = objBlock.write() + "\n";
342  req->WriteHeader("Content-Type", "application/json");
343  req->WriteReply(HTTP_OK, strJSON);
344  return true;
345  }
346 
347  default: {
348  return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: " + AvailableDataFormatsString() + ")");
349  }
350  }
351 }
352 
353 static bool rest_block_extended(const std::any& context, HTTPRequest* req, const std::string& strURIPart)
354 {
355  return rest_block(context, req, strURIPart, TxVerbosity::SHOW_DETAILS_AND_PREVOUT);
356 }
357 
358 static bool rest_block_notxdetails(const std::any& context, HTTPRequest* req, const std::string& strURIPart)
359 {
360  return rest_block(context, req, strURIPart, TxVerbosity::SHOW_TXID);
361 }
362 
363 static bool rest_filter_header(const std::any& context, HTTPRequest* req, const std::string& strURIPart)
364 {
365  if (!CheckWarmup(req)) return false;
366 
367  std::string param;
368  const RESTResponseFormat rf = ParseDataFormat(param, strURIPart);
369 
370  std::vector<std::string> uri_parts = SplitString(param, '/');
371  std::string raw_count;
372  std::string raw_blockhash;
373  if (uri_parts.size() == 3) {
374  // deprecated path: /rest/blockfilterheaders/<filtertype>/<count>/<blockhash>
375  raw_blockhash = uri_parts[2];
376  raw_count = uri_parts[1];
377  } else if (uri_parts.size() == 2) {
378  // new path with query parameter: /rest/blockfilterheaders/<filtertype>/<blockhash>?count=<count>
379  raw_blockhash = uri_parts[1];
380  try {
381  raw_count = req->GetQueryParameter("count").value_or("5");
382  } catch (const std::runtime_error& e) {
383  return RESTERR(req, HTTP_BAD_REQUEST, e.what());
384  }
385  } else {
386  return RESTERR(req, HTTP_BAD_REQUEST, "Invalid URI format. Expected /rest/blockfilterheaders/<filtertype>/<blockhash>.<ext>?count=<count>");
387  }
388 
389  const auto parsed_count{ToIntegral<size_t>(raw_count)};
390  if (!parsed_count.has_value() || *parsed_count < 1 || *parsed_count > MAX_REST_HEADERS_RESULTS) {
391  return RESTERR(req, HTTP_BAD_REQUEST, strprintf("Header count is invalid or out of acceptable range (1-%u): %s", MAX_REST_HEADERS_RESULTS, raw_count));
392  }
393 
394  uint256 block_hash;
395  if (!ParseHashStr(raw_blockhash, block_hash)) {
396  return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + raw_blockhash);
397  }
398 
399  BlockFilterType filtertype;
400  if (!BlockFilterTypeByName(uri_parts[0], filtertype)) {
401  return RESTERR(req, HTTP_BAD_REQUEST, "Unknown filtertype " + uri_parts[0]);
402  }
403 
404  BlockFilterIndex* index = GetBlockFilterIndex(filtertype);
405  if (!index) {
406  return RESTERR(req, HTTP_BAD_REQUEST, "Index is not enabled for filtertype " + uri_parts[0]);
407  }
408 
409  std::vector<const CBlockIndex*> headers;
410  headers.reserve(*parsed_count);
411  {
412  ChainstateManager* maybe_chainman = GetChainman(context, req);
413  if (!maybe_chainman) return false;
414  ChainstateManager& chainman = *maybe_chainman;
415  LOCK(cs_main);
416  CChain& active_chain = chainman.ActiveChain();
417  const CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(block_hash);
418  while (pindex != nullptr && active_chain.Contains(pindex)) {
419  headers.push_back(pindex);
420  if (headers.size() == *parsed_count)
421  break;
422  pindex = active_chain.Next(pindex);
423  }
424  }
425 
426  bool index_ready = index->BlockUntilSyncedToCurrentChain();
427 
428  std::vector<uint256> filter_headers;
429  filter_headers.reserve(*parsed_count);
430  for (const CBlockIndex* pindex : headers) {
431  uint256 filter_header;
432  if (!index->LookupFilterHeader(pindex, filter_header)) {
433  std::string errmsg = "Filter not found.";
434 
435  if (!index_ready) {
436  errmsg += " Block filters are still in the process of being indexed.";
437  } else {
438  errmsg += " This error is unexpected and indicates index corruption.";
439  }
440 
441  return RESTERR(req, HTTP_NOT_FOUND, errmsg);
442  }
443  filter_headers.push_back(filter_header);
444  }
445 
446  switch (rf) {
448  DataStream ssHeader{};
449  for (const uint256& header : filter_headers) {
450  ssHeader << header;
451  }
452 
453  std::string binaryHeader = ssHeader.str();
454  req->WriteHeader("Content-Type", "application/octet-stream");
455  req->WriteReply(HTTP_OK, binaryHeader);
456  return true;
457  }
459  DataStream ssHeader{};
460  for (const uint256& header : filter_headers) {
461  ssHeader << header;
462  }
463 
464  std::string strHex = HexStr(ssHeader) + "\n";
465  req->WriteHeader("Content-Type", "text/plain");
466  req->WriteReply(HTTP_OK, strHex);
467  return true;
468  }
470  UniValue jsonHeaders(UniValue::VARR);
471  for (const uint256& header : filter_headers) {
472  jsonHeaders.push_back(header.GetHex());
473  }
474 
475  std::string strJSON = jsonHeaders.write() + "\n";
476  req->WriteHeader("Content-Type", "application/json");
477  req->WriteReply(HTTP_OK, strJSON);
478  return true;
479  }
480  default: {
481  return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: " + AvailableDataFormatsString() + ")");
482  }
483  }
484 }
485 
486 static bool rest_block_filter(const std::any& context, HTTPRequest* req, const std::string& strURIPart)
487 {
488  if (!CheckWarmup(req)) return false;
489 
490  std::string param;
491  const RESTResponseFormat rf = ParseDataFormat(param, strURIPart);
492 
493  // request is sent over URI scheme /rest/blockfilter/filtertype/blockhash
494  std::vector<std::string> uri_parts = SplitString(param, '/');
495  if (uri_parts.size() != 2) {
496  return RESTERR(req, HTTP_BAD_REQUEST, "Invalid URI format. Expected /rest/blockfilter/<filtertype>/<blockhash>");
497  }
498 
499  uint256 block_hash;
500  if (!ParseHashStr(uri_parts[1], block_hash)) {
501  return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + uri_parts[1]);
502  }
503 
504  BlockFilterType filtertype;
505  if (!BlockFilterTypeByName(uri_parts[0], filtertype)) {
506  return RESTERR(req, HTTP_BAD_REQUEST, "Unknown filtertype " + uri_parts[0]);
507  }
508 
509  BlockFilterIndex* index = GetBlockFilterIndex(filtertype);
510  if (!index) {
511  return RESTERR(req, HTTP_BAD_REQUEST, "Index is not enabled for filtertype " + uri_parts[0]);
512  }
513 
514  const CBlockIndex* block_index;
515  bool block_was_connected;
516  {
517  ChainstateManager* maybe_chainman = GetChainman(context, req);
518  if (!maybe_chainman) return false;
519  ChainstateManager& chainman = *maybe_chainman;
520  LOCK(cs_main);
521  block_index = chainman.m_blockman.LookupBlockIndex(block_hash);
522  if (!block_index) {
523  return RESTERR(req, HTTP_NOT_FOUND, uri_parts[1] + " not found");
524  }
525  block_was_connected = block_index->IsValid(BLOCK_VALID_SCRIPTS);
526  }
527 
528  bool index_ready = index->BlockUntilSyncedToCurrentChain();
529 
530  BlockFilter filter;
531  if (!index->LookupFilter(block_index, filter)) {
532  std::string errmsg = "Filter not found.";
533 
534  if (!block_was_connected) {
535  errmsg += " Block was not connected to active chain.";
536  } else if (!index_ready) {
537  errmsg += " Block filters are still in the process of being indexed.";
538  } else {
539  errmsg += " This error is unexpected and indicates index corruption.";
540  }
541 
542  return RESTERR(req, HTTP_NOT_FOUND, errmsg);
543  }
544 
545  switch (rf) {
547  DataStream ssResp{};
548  ssResp << filter;
549 
550  std::string binaryResp = ssResp.str();
551  req->WriteHeader("Content-Type", "application/octet-stream");
552  req->WriteReply(HTTP_OK, binaryResp);
553  return true;
554  }
556  DataStream ssResp{};
557  ssResp << filter;
558 
559  std::string strHex = HexStr(ssResp) + "\n";
560  req->WriteHeader("Content-Type", "text/plain");
561  req->WriteReply(HTTP_OK, strHex);
562  return true;
563  }
566  ret.pushKV("filter", HexStr(filter.GetEncodedFilter()));
567  std::string strJSON = ret.write() + "\n";
568  req->WriteHeader("Content-Type", "application/json");
569  req->WriteReply(HTTP_OK, strJSON);
570  return true;
571  }
572  default: {
573  return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: " + AvailableDataFormatsString() + ")");
574  }
575  }
576 }
577 
578 // A bit of a hack - dependency on a function defined in rpc/blockchain.cpp
580 
581 static bool rest_chaininfo(const std::any& context, HTTPRequest* req, const std::string& strURIPart)
582 {
583  if (!CheckWarmup(req))
584  return false;
585  std::string param;
586  const RESTResponseFormat rf = ParseDataFormat(param, strURIPart);
587 
588  switch (rf) {
590  JSONRPCRequest jsonRequest;
591  jsonRequest.context = context;
592  jsonRequest.params = UniValue(UniValue::VARR);
593  UniValue chainInfoObject = getblockchaininfo().HandleRequest(jsonRequest);
594  std::string strJSON = chainInfoObject.write() + "\n";
595  req->WriteHeader("Content-Type", "application/json");
596  req->WriteReply(HTTP_OK, strJSON);
597  return true;
598  }
599  default: {
600  return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: json)");
601  }
602  }
603 }
604 
605 
607 
608 static bool rest_deploymentinfo(const std::any& context, HTTPRequest* req, const std::string& str_uri_part)
609 {
610  if (!CheckWarmup(req)) return false;
611 
612  std::string hash_str;
613  const RESTResponseFormat rf = ParseDataFormat(hash_str, str_uri_part);
614 
615  switch (rf) {
617  JSONRPCRequest jsonRequest;
618  jsonRequest.context = context;
619  jsonRequest.params = UniValue(UniValue::VARR);
620 
621  if (!hash_str.empty()) {
622  uint256 hash;
623  if (!ParseHashStr(hash_str, hash)) {
624  return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hash_str);
625  }
626 
627  const ChainstateManager* chainman = GetChainman(context, req);
628  if (!chainman) return false;
629  if (!WITH_LOCK(::cs_main, return chainman->m_blockman.LookupBlockIndex(ParseHashV(hash_str, "blockhash")))) {
630  return RESTERR(req, HTTP_BAD_REQUEST, "Block not found");
631  }
632 
633  jsonRequest.params.push_back(hash_str);
634  }
635 
636  req->WriteHeader("Content-Type", "application/json");
637  req->WriteReply(HTTP_OK, getdeploymentinfo().HandleRequest(jsonRequest).write() + "\n");
638  return true;
639  }
640  default: {
641  return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: json)");
642  }
643  }
644 
645 }
646 
647 static bool rest_mempool(const std::any& context, HTTPRequest* req, const std::string& str_uri_part)
648 {
649  if (!CheckWarmup(req))
650  return false;
651 
652  std::string param;
653  const RESTResponseFormat rf = ParseDataFormat(param, str_uri_part);
654  if (param != "contents" && param != "info") {
655  return RESTERR(req, HTTP_BAD_REQUEST, "Invalid URI format. Expected /rest/mempool/<info|contents>.json");
656  }
657 
658  const CTxMemPool* mempool = GetMemPool(context, req);
659  if (!mempool) return false;
660 
661  switch (rf) {
663  std::string str_json;
664  if (param == "contents") {
665  std::string raw_verbose;
666  try {
667  raw_verbose = req->GetQueryParameter("verbose").value_or("true");
668  } catch (const std::runtime_error& e) {
669  return RESTERR(req, HTTP_BAD_REQUEST, e.what());
670  }
671  if (raw_verbose != "true" && raw_verbose != "false") {
672  return RESTERR(req, HTTP_BAD_REQUEST, "The \"verbose\" query parameter must be either \"true\" or \"false\".");
673  }
674  std::string raw_mempool_sequence;
675  try {
676  raw_mempool_sequence = req->GetQueryParameter("mempool_sequence").value_or("false");
677  } catch (const std::runtime_error& e) {
678  return RESTERR(req, HTTP_BAD_REQUEST, e.what());
679  }
680  if (raw_mempool_sequence != "true" && raw_mempool_sequence != "false") {
681  return RESTERR(req, HTTP_BAD_REQUEST, "The \"mempool_sequence\" query parameter must be either \"true\" or \"false\".");
682  }
683  const bool verbose{raw_verbose == "true"};
684  const bool mempool_sequence{raw_mempool_sequence == "true"};
685  if (verbose && mempool_sequence) {
686  return RESTERR(req, HTTP_BAD_REQUEST, "Verbose results cannot contain mempool sequence values. (hint: set \"verbose=false\")");
687  }
688  str_json = MempoolToJSON(*mempool, verbose, mempool_sequence).write() + "\n";
689  } else {
690  str_json = MempoolInfoToJSON(*mempool).write() + "\n";
691  }
692 
693  req->WriteHeader("Content-Type", "application/json");
694  req->WriteReply(HTTP_OK, str_json);
695  return true;
696  }
697  default: {
698  return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: json)");
699  }
700  }
701 }
702 
703 static bool rest_tx(const std::any& context, HTTPRequest* req, const std::string& strURIPart)
704 {
705  if (!CheckWarmup(req))
706  return false;
707  std::string hashStr;
708  const RESTResponseFormat rf = ParseDataFormat(hashStr, strURIPart);
709 
710  uint256 hash;
711  if (!ParseHashStr(hashStr, hash))
712  return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr);
713 
714  if (g_txindex) {
715  g_txindex->BlockUntilSyncedToCurrentChain();
716  }
717 
718  const NodeContext* const node = GetNodeContext(context, req);
719  if (!node) return false;
720  uint256 hashBlock = uint256();
721  const CTransactionRef tx = GetTransaction(/*block_index=*/nullptr, node->mempool.get(), hash, hashBlock, node->chainman->m_blockman);
722  if (!tx) {
723  return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");
724  }
725 
726  switch (rf) {
728  DataStream ssTx;
729  ssTx << TX_WITH_WITNESS(tx);
730 
731  std::string binaryTx = ssTx.str();
732  req->WriteHeader("Content-Type", "application/octet-stream");
733  req->WriteReply(HTTP_OK, binaryTx);
734  return true;
735  }
736 
738  DataStream ssTx;
739  ssTx << TX_WITH_WITNESS(tx);
740 
741  std::string strHex = HexStr(ssTx) + "\n";
742  req->WriteHeader("Content-Type", "text/plain");
743  req->WriteReply(HTTP_OK, strHex);
744  return true;
745  }
746 
748  UniValue objTx(UniValue::VOBJ);
749  TxToUniv(*tx, /*block_hash=*/hashBlock, /*entry=*/ objTx);
750  std::string strJSON = objTx.write() + "\n";
751  req->WriteHeader("Content-Type", "application/json");
752  req->WriteReply(HTTP_OK, strJSON);
753  return true;
754  }
755 
756  default: {
757  return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: " + AvailableDataFormatsString() + ")");
758  }
759  }
760 }
761 
762 static bool rest_getutxos(const std::any& context, HTTPRequest* req, const std::string& strURIPart)
763 {
764  if (!CheckWarmup(req))
765  return false;
766  std::string param;
767  const RESTResponseFormat rf = ParseDataFormat(param, strURIPart);
768 
769  std::vector<std::string> uriParts;
770  if (param.length() > 1)
771  {
772  std::string strUriParams = param.substr(1);
773  uriParts = SplitString(strUriParams, '/');
774  }
775 
776  // throw exception in case of an empty request
777  std::string strRequestMutable = req->ReadBody();
778  if (strRequestMutable.length() == 0 && uriParts.size() == 0)
779  return RESTERR(req, HTTP_BAD_REQUEST, "Error: empty request");
780 
781  bool fInputParsed = false;
782  bool fCheckMemPool = false;
783  std::vector<COutPoint> vOutPoints;
784 
785  // parse/deserialize input
786  // input-format = output-format, rest/getutxos/bin requires binary input, gives binary output, ...
787 
788  if (uriParts.size() > 0)
789  {
790  //inputs is sent over URI scheme (/rest/getutxos/checkmempool/txid1-n/txid2-n/...)
791  if (uriParts[0] == "checkmempool") fCheckMemPool = true;
792 
793  for (size_t i = (fCheckMemPool) ? 1 : 0; i < uriParts.size(); i++)
794  {
795  int32_t nOutput;
796  std::string strTxid = uriParts[i].substr(0, uriParts[i].find('-'));
797  std::string strOutput = uriParts[i].substr(uriParts[i].find('-')+1);
798 
799  if (!ParseInt32(strOutput, &nOutput) || !IsHex(strTxid))
800  return RESTERR(req, HTTP_BAD_REQUEST, "Parse error");
801 
802  vOutPoints.emplace_back(TxidFromString(strTxid), (uint32_t)nOutput);
803  }
804 
805  if (vOutPoints.size() > 0)
806  fInputParsed = true;
807  else
808  return RESTERR(req, HTTP_BAD_REQUEST, "Error: empty request");
809  }
810 
811  switch (rf) {
813  // convert hex to bin, continue then with bin part
814  std::vector<unsigned char> strRequestV = ParseHex(strRequestMutable);
815  strRequestMutable.assign(strRequestV.begin(), strRequestV.end());
816  [[fallthrough]];
817  }
818 
820  try {
821  //deserialize only if user sent a request
822  if (strRequestMutable.size() > 0)
823  {
824  if (fInputParsed) //don't allow sending input over URI and HTTP RAW DATA
825  return RESTERR(req, HTTP_BAD_REQUEST, "Combination of URI scheme inputs and raw post data is not allowed");
826 
827  DataStream oss{};
828  oss << strRequestMutable;
829  oss >> fCheckMemPool;
830  oss >> vOutPoints;
831  }
832  } catch (const std::ios_base::failure&) {
833  // abort in case of unreadable binary data
834  return RESTERR(req, HTTP_BAD_REQUEST, "Parse error");
835  }
836  break;
837  }
838 
840  if (!fInputParsed)
841  return RESTERR(req, HTTP_BAD_REQUEST, "Error: empty request");
842  break;
843  }
844  default: {
845  return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: " + AvailableDataFormatsString() + ")");
846  }
847  }
848 
849  // limit max outpoints
850  if (vOutPoints.size() > MAX_GETUTXOS_OUTPOINTS)
851  return RESTERR(req, HTTP_BAD_REQUEST, strprintf("Error: max outpoints exceeded (max: %d, tried: %d)", MAX_GETUTXOS_OUTPOINTS, vOutPoints.size()));
852 
853  // check spentness and form a bitmap (as well as a JSON capable human-readable string representation)
854  std::vector<unsigned char> bitmap;
855  std::vector<CCoin> outs;
856  std::string bitmapStringRepresentation;
857  std::vector<bool> hits;
858  bitmap.resize((vOutPoints.size() + 7) / 8);
859  ChainstateManager* maybe_chainman = GetChainman(context, req);
860  if (!maybe_chainman) return false;
861  ChainstateManager& chainman = *maybe_chainman;
862  decltype(chainman.ActiveHeight()) active_height;
863  uint256 active_hash;
864  {
865  auto process_utxos = [&vOutPoints, &outs, &hits, &active_height, &active_hash, &chainman](const CCoinsView& view, const CTxMemPool* mempool) EXCLUSIVE_LOCKS_REQUIRED(chainman.GetMutex()) {
866  for (const COutPoint& vOutPoint : vOutPoints) {
867  Coin coin;
868  bool hit = (!mempool || !mempool->isSpent(vOutPoint)) && view.GetCoin(vOutPoint, coin);
869  hits.push_back(hit);
870  if (hit) outs.emplace_back(std::move(coin));
871  }
872  active_height = chainman.ActiveHeight();
873  active_hash = chainman.ActiveTip()->GetBlockHash();
874  };
875 
876  if (fCheckMemPool) {
877  const CTxMemPool* mempool = GetMemPool(context, req);
878  if (!mempool) return false;
879  // use db+mempool as cache backend in case user likes to query mempool
880  LOCK2(cs_main, mempool->cs);
881  CCoinsViewCache& viewChain = chainman.ActiveChainstate().CoinsTip();
882  CCoinsViewMemPool viewMempool(&viewChain, *mempool);
883  process_utxos(viewMempool, mempool);
884  } else {
885  LOCK(cs_main);
886  process_utxos(chainman.ActiveChainstate().CoinsTip(), nullptr);
887  }
888 
889  for (size_t i = 0; i < hits.size(); ++i) {
890  const bool hit = hits[i];
891  bitmapStringRepresentation.append(hit ? "1" : "0"); // form a binary string representation (human-readable for json output)
892  bitmap[i / 8] |= ((uint8_t)hit) << (i % 8);
893  }
894  }
895 
896  switch (rf) {
898  // serialize data
899  // use exact same output as mentioned in Bip64
900  DataStream ssGetUTXOResponse{};
901  ssGetUTXOResponse << active_height << active_hash << bitmap << outs;
902  std::string ssGetUTXOResponseString = ssGetUTXOResponse.str();
903 
904  req->WriteHeader("Content-Type", "application/octet-stream");
905  req->WriteReply(HTTP_OK, ssGetUTXOResponseString);
906  return true;
907  }
908 
910  DataStream ssGetUTXOResponse{};
911  ssGetUTXOResponse << active_height << active_hash << bitmap << outs;
912  std::string strHex = HexStr(ssGetUTXOResponse) + "\n";
913 
914  req->WriteHeader("Content-Type", "text/plain");
915  req->WriteReply(HTTP_OK, strHex);
916  return true;
917  }
918 
920  UniValue objGetUTXOResponse(UniValue::VOBJ);
921 
922  // pack in some essentials
923  // use more or less the same output as mentioned in Bip64
924  objGetUTXOResponse.pushKV("chainHeight", active_height);
925  objGetUTXOResponse.pushKV("chaintipHash", active_hash.GetHex());
926  objGetUTXOResponse.pushKV("bitmap", bitmapStringRepresentation);
927 
928  UniValue utxos(UniValue::VARR);
929  for (const CCoin& coin : outs) {
930  UniValue utxo(UniValue::VOBJ);
931  utxo.pushKV("height", (int32_t)coin.nHeight);
932  utxo.pushKV("value", ValueFromAmount(coin.out.nValue));
933 
934  // include the script in a json output
936  ScriptToUniv(coin.out.scriptPubKey, /*out=*/o, /*include_hex=*/true, /*include_address=*/true);
937  utxo.pushKV("scriptPubKey", o);
938  utxos.push_back(utxo);
939  }
940  objGetUTXOResponse.pushKV("utxos", utxos);
941 
942  // return json string
943  std::string strJSON = objGetUTXOResponse.write() + "\n";
944  req->WriteHeader("Content-Type", "application/json");
945  req->WriteReply(HTTP_OK, strJSON);
946  return true;
947  }
948  default: {
949  return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: " + AvailableDataFormatsString() + ")");
950  }
951  }
952 }
953 
954 static bool rest_blockhash_by_height(const std::any& context, HTTPRequest* req,
955  const std::string& str_uri_part)
956 {
957  if (!CheckWarmup(req)) return false;
958  std::string height_str;
959  const RESTResponseFormat rf = ParseDataFormat(height_str, str_uri_part);
960 
961  int32_t blockheight = -1; // Initialization done only to prevent valgrind false positive, see https://github.com/bitcoin/bitcoin/pull/18785
962  if (!ParseInt32(height_str, &blockheight) || blockheight < 0) {
963  return RESTERR(req, HTTP_BAD_REQUEST, "Invalid height: " + SanitizeString(height_str));
964  }
965 
966  CBlockIndex* pblockindex = nullptr;
967  {
968  ChainstateManager* maybe_chainman = GetChainman(context, req);
969  if (!maybe_chainman) return false;
970  ChainstateManager& chainman = *maybe_chainman;
971  LOCK(cs_main);
972  const CChain& active_chain = chainman.ActiveChain();
973  if (blockheight > active_chain.Height()) {
974  return RESTERR(req, HTTP_NOT_FOUND, "Block height out of range");
975  }
976  pblockindex = active_chain[blockheight];
977  }
978  switch (rf) {
980  DataStream ss_blockhash{};
981  ss_blockhash << pblockindex->GetBlockHash();
982  req->WriteHeader("Content-Type", "application/octet-stream");
983  req->WriteReply(HTTP_OK, ss_blockhash.str());
984  return true;
985  }
987  req->WriteHeader("Content-Type", "text/plain");
988  req->WriteReply(HTTP_OK, pblockindex->GetBlockHash().GetHex() + "\n");
989  return true;
990  }
992  req->WriteHeader("Content-Type", "application/json");
994  resp.pushKV("blockhash", pblockindex->GetBlockHash().GetHex());
995  req->WriteReply(HTTP_OK, resp.write() + "\n");
996  return true;
997  }
998  default: {
999  return RESTERR(req, HTTP_NOT_FOUND, "output format not found (available: " + AvailableDataFormatsString() + ")");
1000  }
1001  }
1002 }
1003 
1004 static const struct {
1005  const char* prefix;
1006  bool (*handler)(const std::any& context, HTTPRequest* req, const std::string& strReq);
1007 } uri_prefixes[] = {
1008  {"/rest/tx/", rest_tx},
1009  {"/rest/block/notxdetails/", rest_block_notxdetails},
1010  {"/rest/block/", rest_block_extended},
1011  {"/rest/blockfilter/", rest_block_filter},
1012  {"/rest/blockfilterheaders/", rest_filter_header},
1013  {"/rest/chaininfo", rest_chaininfo},
1014  {"/rest/mempool/", rest_mempool},
1015  {"/rest/headers/", rest_headers},
1016  {"/rest/getutxos", rest_getutxos},
1017  {"/rest/deploymentinfo/", rest_deploymentinfo},
1018  {"/rest/deploymentinfo", rest_deploymentinfo},
1019  {"/rest/blockhashbyheight/", rest_blockhash_by_height},
1020 };
1021 
1022 void StartREST(const std::any& context)
1023 {
1024  for (const auto& up : uri_prefixes) {
1025  auto handler = [context, up](HTTPRequest* req, const std::string& prefix) { return up.handler(context, req, prefix); };
1026  RegisterHTTPHandler(up.prefix, false, handler);
1027  }
1028 }
1029 
1031 {
1032 }
1033 
1034 void StopREST()
1035 {
1036  for (const auto& up : uri_prefixes) {
1037  UnregisterHTTPHandler(up.prefix, false);
1038  }
1039 }
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:423
uint32_t nHeight
Definition: rest.cpp:58
node::BlockManager m_blockman
A single BlockManager instance is shared across each constructed chainstate to avoid duplicating bloc...
Definition: validation.h:963
static ChainstateManager * GetChainman(const std::any &context, HTTPRequest *req)
Get the node context chainstatemanager.
Definition: rest.cpp:123
bool LookupFilter(const CBlockIndex *block_index, BlockFilter &filter_out) const
Get a single filter by block.
BlockFilterIndex is used to store and retrieve block filters, hashes, and headers for a range of bloc...
void push_back(UniValue val)
Definition: univalue.cpp:104
UniValue MempoolToJSON(const CTxMemPool &pool, bool verbose, bool include_mempool_sequence)
Mempool to JSON.
Definition: mempool.cpp:335
int ret
static bool CheckWarmup(HTTPRequest *req)
Definition: rest.cpp:179
std::any context
Definition: request.h:38
The same as previous option with information about prevouts if available.
std::vector< Byte > ParseHex(std::string_view hex_str)
Like TryParseHex, but returns an empty vector on invalid input.
Definition: strencodings.h:65
A UTXO entry.
Definition: coins.h:31
Definition: block.h:68
bool BlockFilterTypeByName(const std::string &name, BlockFilterType &filter_type)
Find a filter type by its human-readable name.
TxVerbosity
Verbose level for block&#39;s transaction.
Definition: core_io.h:27
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:846
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1162
static bool rest_getutxos(const std::any &context, HTTPRequest *req, const std::string &strURIPart)
Definition: rest.cpp:762
An in-memory indexed chain of blocks.
Definition: chain.h:446
RESTResponseFormat
Definition: rest.h:10
static std::string AvailableDataFormatsString()
Definition: rest.cpp:162
BlockFilterIndex * GetBlockFilterIndex(BlockFilterType filter_type)
Get a block filter index by type.
const char * prefix
Definition: rest.cpp:1005
CChain & ActiveChain() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1066
static bool rest_tx(const std::any &context, HTTPRequest *req, const std::string &strURIPart)
Definition: rest.cpp:703
RESTResponseFormat ParseDataFormat(std::string &param, const std::string &strReq)
Parse a URI to get the data format and URI without data format and query string.
Definition: rest.cpp:137
int Height() const
Return the maximal height in the chain.
Definition: chain.h:492
bool IsHex(std::string_view str)
HTTPStatusCode
HTTP status codes.
Definition: protocol.h:10
CTransactionRef GetTransaction(const CBlockIndex *const block_index, const CTxMemPool *const mempool, const uint256 &hash, uint256 &hashBlock, const BlockManager &blockman)
Return transaction with a given hash.
UniValue MempoolInfoToJSON(const CTxMemPool &pool)
Mempool information to JSON.
Definition: mempool.cpp:663
static const struct @10 uri_prefixes[]
std::optional< std::string > GetQueryParameter(const std::string &key) const
Get the query parameter value from request uri for a specified key, or std::nullopt if the key is not...
Definition: httpserver.cpp:710
bool ReadBlockFromDisk(CBlock &block, const FlatFilePos &pos) const
Functions for disk access for blocks.
static bool rest_headers(const std::any &context, HTTPRequest *req, const std::string &strURIPart)
Definition: rest.cpp:187
std::vector< std::string > SplitString(std::string_view str, char sep)
Definition: string.h:21
bool(* handler)(const std::any &context, HTTPRequest *req, const std::string &strReq)
Definition: rest.cpp:1006
void RegisterHTTPHandler(const std::string &prefix, bool exactMatch, const HTTPRequestHandler &handler)
Register handler for prefix.
Definition: httpserver.cpp:744
Txid TxidFromString(std::string_view str)
SERIALIZE_METHODS(CCoin, obj)
Definition: rest.cpp:64
uint256 GetBlockHash() const
Definition: chain.h:258
static bool rest_mempool(const std::any &context, HTTPRequest *req, const std::string &str_uri_part)
Definition: rest.cpp:647
std::string SanitizeString(std::string_view str, int rule)
Remove unsafe chars.
BlockFilterType
Definition: blockfilter.h:92
NodeContext struct containing references to chain state and connection state.
Definition: context.h:48
#define LOCK2(cs1, cs2)
Definition: sync.h:258
static bool rest_block_extended(const std::any &context, HTTPRequest *req, const std::string &strURIPart)
Definition: rest.cpp:353
static bool RESTERR(HTTPRequest *req, enum HTTPStatusCode status, std::string message)
Definition: rest.cpp:71
RESTResponseFormat rf
Definition: rest.cpp:48
static bool rest_block(const std::any &context, HTTPRequest *req, const std::string &strURIPart, TxVerbosity tx_verbosity)
Definition: rest.cpp:284
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
Scripts & signatures ok. Implies all parents are either at least VALID_SCRIPTS, or are ASSUMED_VALID...
Definition: chain.h:111
UniValue blockheaderToJSON(const CBlockIndex &tip, const CBlockIndex &blockindex)
Block header to JSON.
Definition: blockchain.cpp:134
void ScriptToUniv(const CScript &script, UniValue &out, bool include_hex=true, bool include_address=false, const SigningProvider *provider=nullptr)
Definition: core_write.cpp:150
Abstract view on the open txout dataset.
Definition: coins.h:172
void WriteReply(int nStatus, const std::string &strReply="")
Write HTTP reply.
Definition: httpserver.cpp:639
UniValue params
Definition: request.h:33
#define LOCK(cs)
Definition: sync.h:257
const char * name
Definition: rest.cpp:49
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:146
std::unique_ptr< TxIndex > g_txindex
The global transaction index, used in GetTransaction. May be null.
Definition: txindex.cpp:16
bool LookupFilterHeader(const CBlockIndex *block_index, uint256 &header_out) EXCLUSIVE_LOCKS_REQUIRED(!m_cs_headers_cache)
Get a single filter header by block.
Complete block filter struct as defined in BIP 157.
Definition: blockfilter.h:114
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
Definition: chain.h:477
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:483
void UnregisterHTTPHandler(const std::string &prefix, bool exactMatch)
Unregister handler for prefix.
Definition: httpserver.cpp:751
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
CBlockIndex * ActiveTip() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1068
An output of a transaction.
Definition: transaction.h:149
RecursiveMutex & GetMutex() const LOCK_RETURNED(
Alias for cs_main.
Definition: validation.h:956
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:28
CBlockIndex * LookupBlockIndex(const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
static const struct @9 rf_names[]
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:301
CCoin()
Definition: rest.cpp:61
CTxOut out
Definition: rest.cpp:59
Definition: init.h:25
bool ParseInt32(std::string_view str, int32_t *out)
Convert string to signed 32-bit integer with strict parse error feedback.
static bool rest_blockhash_by_height(const std::any &context, HTTPRequest *req, const std::string &str_uri_part)
Definition: rest.cpp:954
static bool rest_block_notxdetails(const std::any &context, HTTPRequest *req, const std::string &strURIPart)
Definition: rest.cpp:358
bool IsValid(enum BlockStatus nUpTo=BLOCK_VALID_TRANSACTIONS) const EXCLUSIVE_LOCKS_REQUIRED(
Check whether this block index entry is valid up to the passed validity level.
Definition: chain.h:311
static CTxMemPool * GetMemPool(const std::any &context, HTTPRequest *req)
Get the node context mempool.
Definition: rest.cpp:106
static const size_t MAX_GETUTXOS_OUTPOINTS
Definition: rest.cpp:44
std::string str() const
Definition: streams.h:168
256-bit opaque blob.
Definition: uint256.h:106
RPCHelpMan getblockchaininfo()
static bool rest_filter_header(const std::any &context, HTTPRequest *req, const std::string &strURIPart)
Definition: rest.cpp:363
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:299
void WriteHeader(const std::string &hdr, const std::string &value)
Write output header.
Definition: httpserver.cpp:627
Only TXID for each block&#39;s transaction.
RPCHelpMan getdeploymentinfo()
void StopREST()
Stop HTTP REST subsystem.
Definition: rest.cpp:1034
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:149
void pushKV(std::string key, UniValue val)
Definition: univalue.cpp:126
uint256 ParseHashV(const UniValue &v, std::string_view name)
Utilities: convert hex-encoded Values (throws error if not hex).
Definition: util.cpp:89
static NodeContext * GetNodeContext(const std::any &context, HTTPRequest *req)
Get the node context.
Definition: rest.cpp:85
static bool rest_block_filter(const std::any &context, HTTPRequest *req, const std::string &strURIPart)
Definition: rest.cpp:486
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
Definition: chain.h:463
std::string GetHex() const
Definition: uint256.cpp:11
int ActiveHeight() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1067
UniValue ValueFromAmount(const CAmount amount)
Definition: core_write.cpp:26
bool RPCIsInWarmup(std::string *outStatus)
Definition: server.cpp:350
Definition: rest.cpp:57
std::string ReadBody()
Read request body.
Definition: httpserver.cpp:607
In-flight HTTP request.
Definition: httpserver.h:60
bool ParseHashStr(const std::string &strHex, uint256 &result)
Parse a hex string into 256 bits.
Definition: core_read.cpp:235
const std::vector< unsigned char > & GetEncodedFilter() const LIFETIMEBOUND
Definition: blockfilter.h:138
void InterruptREST()
Interrupt RPC REST subsystem.
Definition: rest.cpp:1030
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:228
CCoin(Coin &&in)
Definition: rest.cpp:62
UniValue HandleRequest(const JSONRPCRequest &request) const
Definition: util.cpp:606
#define READWRITE(...)
Definition: serialize.h:156
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
Definition: cs_main.cpp:8
CCoinsView that brings transactions from a mempool into view.
Definition: txmempool.h:821
static bool rest_deploymentinfo(const std::any &context, HTTPRequest *req, const std::string &str_uri_part)
Definition: rest.cpp:608
SnapshotCompletionResult MaybeCompleteSnapshotValidation() EXCLUSIVE_LOCKS_REQUIRED(const CBlockIndex *GetSnapshotBaseBlock() const EXCLUSIVE_LOCKS_REQUIRED(Chainstate ActiveChainstate)() const
Once the background validation chainstate has reached the height which is the base of the UTXO snapsh...
Definition: validation.h:1065
UniValue blockToJSON(BlockManager &blockman, const CBlock &block, const CBlockIndex &tip, const CBlockIndex &blockindex, TxVerbosity verbosity)
Block description to JSON.
Definition: blockchain.cpp:163
#define PACKAGE_BUGREPORT
static constexpr unsigned int MAX_REST_HEADERS_RESULTS
Definition: rest.cpp:45
static bool rest_chaininfo(const std::any &context, HTTPRequest *req, const std::string &strURIPart)
Definition: rest.cpp:581
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it...
Definition: txmempool.h:388
static constexpr TransactionSerParams TX_WITH_WITNESS
Definition: transaction.h:195
void TxToUniv(const CTransaction &tx, const uint256 &block_hash, UniValue &entry, bool include_hex=true, const CTxUndo *txundo=nullptr, TxVerbosity verbosity=TxVerbosity::SHOW_DETAILS)
Definition: core_write.cpp:171
void StartREST(const std::any &context)
Start HTTP REST subsystem.
Definition: rest.cpp:1022